#include "Contact_list.h" #include #include #include using std::cin; using std::cout; using std::endl; // constructors 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); } //getters n setters void contact::Set_firstName(const char* firstName) { _firstName = firstName; } const char* contact::Get_firstName() { return _firstName; } void contact::Set_lastName(const char* lastName) { _lastName = lastName; } const char* contact::Get_lastName() { return _lastName; } void contact::Set_streetAddress(const char* streetAddress) { _streetAddress = streetAddress; } const char* contact::Get_streetAddress() { return _streetAddress; } void contact::Set_city(const char* city) { _city = city; } const char* contact::Get_city() { return _city; } void contact::Set_state(const char* state) { _state = state; } const char* contact::Get_state() { return _state; } void contact::Set_zip(int zip) { _zip = zip; } int contact::Get_zip() { return _zip; } void contact::Set_email(const char* email) { _email = email; } const char* 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 contact_list::AddContact(const contact& contact) { contacts_[size_++] = contact; //CURRENTLY TESTING 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; } } char firstName[30]; char lastName[30]; char Email[105]; char StreetAddress[45]; char City[35]; char State[4]; int Zip = 0; contacts_[i].Set_id(i); //contacts_[i].Set_a(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; contacts_[i].Set_firstName(firstName); cout << "enter last name: " << endl; cin >> lastName; contacts_[i].Set_lastName(lastName); cout << "enter Email: " << endl; cin >> Email; contacts_[i].Set_email(Email); cout << "enter Street Address: " << endl; cin >> StreetAddress; contacts_[i].Set_streetAddress(StreetAddress); cout << "enter city: " << endl; cin >> City; contacts_[i].Set_city(City); cout << "enter State as two letter abbreviation: " << endl; cin >> State; contacts_[i].Set_state(State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> Zip; contacts_[i].Set_zip(Zip); break; } } for (auto i = 0u; i < size_; i++) { size_t t = contacts_[i].Get_id(); for (size_t i = t; i < size_; i++) { char firstName[30]; char lastName[30]; char Email[105]; char StreetAddress[45]; char City[35]; char State[4]; int Zip = 0; 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 >> firstName; contacts_[i].Set_firstName(firstName); cout << "enter last name: " << endl; cin >> lastName; contacts_[i].Set_lastName(lastName); cout << "enter Email: " << endl; cin >> Email; contacts_[i].Set_email(Email); cout << "enter Street Address: " << endl; cin >> StreetAddress; contacts_[i].Set_streetAddress(StreetAddress); cout << "enter city: " << endl; cin >> City; contacts_[i].Set_city(City); cout << "enter State as two letter abbreviation: " << endl; cin >> State; contacts_[i].Set_state(State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> Zip; contacts_[i].Set_zip(Zip); t++; 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; } //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 WORKING for (auto i = 0u; i < size_; ++i) { contacts_[i].print(); } } 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]; } size_t max_double(size_t MAX) { MAX = MAX * 2; return MAX; } 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 (newContact[i].a == 1) //{ // break; //} cout << "Id number: " << contacts_[i].Get_id() << " is under the name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl; //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 == newContact[i].id) //{ // newContact[i].a = 1; // cout << "Contact number: " << newContact[i].id << " deleted" << endl; // newContact[i + 1].id = newContact[i + 1].id - 1; // break; //} } 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 - 1); break; } } } void contact_list::CopyList(const contact* contacts, const size_t& size) { length_ = size; contacts_ = allocateContactList(size); for(auto i = 0u; i < size; ++i) { contacts_[i] = contacts[i]; } }