#include "Contact_list.h" #include #include #include #include #include using std::cin; using std::cout; using std::endl; // constructors and destructors for contact // constructors and destructors for contact_list contact_list::~contact_list() { delete[] contacts_; contacts_ = nullptr; } contact* contact_list::allocateContactList(const size_t& size) { contact* contacts_ = nullptr; length_ = size; contacts_ = new contact[size]{}; return contacts_; } contact_list::contact_list(const size_t& size) { length_ = size; contacts_ = allocateContactList(size); } //standard functions for contact and contact_list classes //copy (contact_list) void contact_list::CopyList(contact* contacts,size_t size) { length_ = size; //contacts_ = allocateContactList(size); contact* newContacts = new contact[size]; for (auto i = 0u; i < size; ++i) { newContacts[i] = contacts_[i]; } cout << "Class copied!" << endl; cout << "printing!" << endl; for (auto i = 0u; i < size; i++) { cout << "Contact number: " << i << endl; newContacts[i].print(); } } //copy operator (contact) contact& contact::operator=(contact& rhs) { if (this != &rhs) { _firstName = rhs._firstName; _lastName = rhs._lastName; _streetAddress = rhs._streetAddress; _city = rhs._city; _state = rhs._state; _zip = rhs._zip; _email = rhs._email; } return *this; } //move (contact) contact::contact(contact&& move) noexcept { *this = move; //also *this = std::move(move); } contact& contact::operator=(contact&& rhs) noexcept { if (this != &rhs) { _firstName = rhs._firstName; _lastName = rhs._lastName; _streetAddress = rhs._streetAddress; _city = rhs._city; _state = rhs._state; _zip = rhs._zip; _email = rhs._email; } return *this; } //getters n setters void contact::Set_firstName(string firstName) { _firstName = firstName; } string contact::Get_firstName() { return _firstName; } void contact::Set_lastName(string lastName) { _lastName = lastName; } string contact::Get_lastName() { return _lastName; } void contact::Set_streetAddress(string streetAddress) { _streetAddress = streetAddress; } string contact::Get_streetAddress() { return _streetAddress; } void contact::Set_city(string city) { _city = city; } string contact::Get_city() { return _city; } void contact::Set_state(string state) { _state = state; } string contact::Get_state() { return _state; } void contact::Set_zip(int zip) { _zip = zip; } int contact::Get_zip() { return _zip; } void contact::Set_email(string email) { _email = email; } string contact::Get_email() { return _email; } void contact_list::set_length(size_t MAX) { length_ = MAX; } size_t contact_list::get_length() { return length_; } void contact_list::set_size(size_t size) { size_ = size; } size_t contact_list::get_size() { return size_; } void contact::Set_a(size_t a) { _a = a; } size_t contact::Get_a() { return _a; } void contact::Set_id(size_t id) { _id = id; } size_t contact::Get_id() { return _id; } void contact::print() { //cout << "Contact number: " << _id << endl; cout << "Full name: " << _firstName << " " << _lastName << endl; cout << "Street Address: " << _streetAddress << endl; cout << "City: " << _city << endl; cout << "State: " << _state << endl; cout << "Zip code: " << _zip << endl; cout << "Email: " << _email << endl; } //functions //void addContact(contact newContact, size_t MAX, contact_list contacts[]) //{ //for(auto i = 0u; i < MAX; ++i) //{ // char firstName[30]; // char lastName[30]; // char Email[105]; // char StreetAddress[45]; // char City[35]; // char State[4]; // int Zip = 0; // newContact.Set_a(0); // newContact.Set_id(i + 1); // //newContact[i].count = t; // cin.ignore(1000, '\n'); // cout << "Please enter each piece of information when you are prompted to" << endl; // cout << "enter first name: " << endl; // cin >> firstName; // newContact.Set_firstName(firstName); // cout << "enter last name: " << endl; // cin >> lastName; // newContact.Set_lastName(lastName); // cout << "enter Email: " << endl; // cin >> Email; // newContact.Set_email(Email); // cout << "enter Street Address: " << endl; // cin >> StreetAddress; // newContact.Set_streetAddress(StreetAddress); // cout << "enter city: " << endl; // cin >> City; // newContact.Set_city(City); // cout << "enter State as two letter abbreviation: " << endl; // cin >> State; // newContact.Set_state(State); // cout << "Please enter the next value as a series of numbers" << endl; // cout << "enter Zip: " << endl; // cin >> Zip; // newContact.Set_zip(Zip); // size_t id = i + 1; // newContact.Set_id(id); // break; //} //} void contact_list::AddContact(contact contact[], size_t& t, contact_struct save) { //CURRENTLY TESTING contact_struct _save; for (size_t i = 0; i < size_, i++;) { size_t a = contacts_[i].Get_a(); for (a = 1; ++i;) { contacts_[i].Set_a(0); size_t temp = contacts_[i].Get_id(); for (auto j = temp; j < size_; j++) { if (contacts_[i].Get_id() != 0) { i = i + 1; } contacts_[i].Set_a(0); contacts_[i].Set_id(i); //newContact[i].count = t; cin.ignore(1000, '\n'); cout << "Please enter each piece of information when you are prompted to" << endl; cout << "enter first name: " << endl; cin >> save.firstName; contacts_[i].Set_firstName(save.firstName); cout << "enter last name: " << endl; cin >> save.lastName; contacts_[i].Set_lastName(save.lastName); cout << "enter Email: " << endl; cin >> save.Email; contacts_[i].Set_email(save.Email); cout << "enter Street Address: " << endl; cin >> save.StreetAddress; contacts_[i].Set_streetAddress(save.StreetAddress); cout << "enter city: " << endl; cin >> save.City; contacts_[i].Set_city(save.City); cout << "enter State as two letter abbreviation: " << endl; cin >> save.State; contacts_[i].Set_state(save.State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> save.Zip; contacts_[i].Set_zip(save.Zip); } break; } } for (size_t i = t; i < size_;) { contacts_[i].Set_a(0); contacts_[i].Set_id(i + 1); //newContact[i].count = t; cin.ignore(1000, '\n'); cout << "Please enter each piece of information when you are prompted to" << endl; cout << "enter first name: " << endl; cin >> save.firstName; contacts_[i].Set_firstName(save.firstName); cout << "enter last name: " << endl; cin >> save.lastName; contacts_[i].Set_lastName(save.lastName); cout << "enter Email: " << endl; cin >> save.Email; contacts_[i].Set_email(save.Email); cout << "enter Street Address: " << endl; cin >> save.StreetAddress; contacts_[i].Set_streetAddress(save.StreetAddress); cout << "enter city: " << endl; cin >> save.City; contacts_[i].Set_city(save.City); cout << "enter State as two letter abbreviation: " << endl; cin >> save.State; contacts_[i].Set_state(save.State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> save.Zip; contacts_[i].Set_zip(save.Zip); break; } //cout << newContact[i]->Name << "\n" << newContact[i]->Email << "\n" << newContact[i]->StreetAddress << "\n" << newContact[i]->City << "\n" << newContact[i]->State << "\n" << newContact[i]->Zip << endl; } // not required update function below. //void contact_list::Update(const contact& contact) //{ // //uses input based on list number from print (though when delete is made will be using that id/name print) to update the values of. // //CURRENTLY TESTING // char firstName[30]; // char lastName[30]; // char Email[105]; // char StreetAddress[45]; // char City[35]; // char State[4]; // int Zip = 0; // cout << "select a contact to update based on their position in the list (check print all contacts for list position)" << endl; // int c = 0; // cin >> c; // int t = c - 1; // for (size_t i = t; i < size_;) // { // cin.ignore(1000, '\n'); // cout << "Please enter each piece of information when you are prompted to" << endl; // newContact[i].Set_id(c); // cout << "enter first name: " << endl; // cin >> firstName; // newContact[i].Set_firstName(firstName); // cout << "enter last name: " << endl; // cin >> lastName; // newContact[i].Set_lastName(lastName); // cout << "enter Email: " << endl; // cin >> Email; // newContact[i].Set_email(Email); // cout << "enter Street Address: " << endl; // cin >> StreetAddress; // newContact[i].Set_streetAddress(StreetAddress); // cout << "enter city: " << endl; // cin >> City; // newContact[i].Set_city(City); // cout << "enter State as two letter abbreviation: " << endl; // cin >> State; // newContact[i].Set_state(State); // cout << "Please enter the next value as a series of numbers" << endl; // cout << "enter Zip: " << endl; // cin >> Zip; // newContact[i].Set_zip(Zip); // break; // } //} void contact_list::Print() const { //prints all info but count and bool for every existing (non trash value filled) contact struct //CURRENTLY not working for (auto i = 0u; i < size_; ++i) { size_t check = contacts_[i].Get_a(); if (check == 1) { i = i + 1; } if (contacts_[i].Get_id() == 0) { break; } if (contacts_[i].Get_id() < 0) { break; } if (contacts_[i].Get_id() > size_) { break; } cout << "Contact number: " << contacts_[i].Get_id() << endl; cout << "Full name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl; cout << "Email: " << contacts_[i].Get_email() << endl; cout << "Street Address: " << contacts_[i].Get_streetAddress() << endl; cout << "City: " << contacts_[i].Get_city() << endl; cout << "State: " << contacts_[i].Get_state() << endl; cout << "Zip code: " << contacts_[i].Get_zip() << endl; //contacts_[i].print; //if (contacts_[i].Get_id() == 0) { // break; //} } } // depreciated contact double function below. //contact contact_double(contact*& newContact, size_t& MAX, size_t t) //{ // /*hell on earth is in this condenced comment*/ // //supposedly doubles length. doesn't work. // //current ideas: add if loop to whole main with the id counter t and if length of newContact = max double the length. // //current problems: using const size_t max prevents editing size for the whole function, and it resets as soon as the while loop loops or leaves the scope of the if statement. // //contact* doubleContact = new contact[MAX * 2]; // //for (auto a = 0u; a < MAX; ++a) // //{ // // doubleContact[a].a = newContact[a].a; // // doubleContact[a].id = newContact[a].id; // // doubleContact[a].count = newContact[a].count; // // doubleContact[a].Name[25] = newContact[a].Name[25]; // // doubleContact[a].Email[100] = newContact[a].Email[100]; // // doubleContact[a].StreetAddress[35] = newContact[a].StreetAddress[35]; // // doubleContact[a].City[30] = newContact[a].City[30]; // // doubleContact[a].State[3] = newContact[a].State[3]; // // doubleContact[a].Zip = newContact[a].Zip; // // cout << "List number: " << doubleContact[a].id << endl; // // cout << "name: " << doubleContact[a].Name << endl; // // cout << "Email: " << doubleContact[a].Email << endl; // // cout << "Address: " << doubleContact[a].StreetAddress << endl; // // cout << "city: " << doubleContact[a].City << endl; // // cout << "state: " << doubleContact[a].State << endl; // // cout << "Zip: " << doubleContact[a].Zip << endl; // //} // //newContact = doubleContact; // //delete[] doubleContact; // ////delete[] newContact; // //MAX = MAX * 2; // ////printAll(&doubleContact[MAX], MAX); // ////printAll(&newContact[MAX], MAX); // //return newContact[MAX]; // // //contact* doubleContact = new contact[MAX * 2]; // //for (auto a = 0u; a < MAX; ++a) // //{ // // doubleContact[a] = newContact[a]; // //} // //delete[] newContact; // //newContact = doubleContact; // //MAX = MAX * 2; // //return newContact[MAX - 1]; // return; //} void contact_list::DeleteContact(contact* contact[]) { //Work in progress, add BOOL (true) to struct, when this is selected print id list with respective names //then take input of id list number and set bool to false //add to new part to addNew: if bool != 0 then copy and paste update code w/addNew couts cout << "The list of contacts and their names will now print" << endl; for (auto i = 0u; i < size_; i++) { /* if (contacts_[i].Get_id() == 0) { break; }*/ if (contacts_[i].Get_id() < 0) { break; } if (contacts_[i].Get_id() > size_) { break; } if (contacts_[i].Get_a() == 1) { break; } cout << "Id number: " << contacts_[i].Get_id() << " is under the name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl; } for (auto i = 0u; i < size_; i++) { size_t delete_choice = 0; cout << "\n"; cin.ignore(1000, '\n'); cout << "Enter the id number of the contact you'd like to delete" << endl; cin >> delete_choice; if (delete_choice != contacts_[i].Get_id()) { i = i + 1; } if (delete_choice == contacts_[i].Get_id()) { contacts_[i].Set_a(1); contacts_[i + 1].Set_id(i); cout << "the contact for: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << " (id number: " << contacts_[i].Get_id() << "Has been deleted. (bool check = " << contacts_[i].Get_a() << endl; break; } } }