#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_index(int id) { _id = id; } int contact::Get_index() { return _id; } 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; } //functions void contact_list::AddContact(const contact& contact) { contacts_[size_++] = contact; //CURRENTLY TESTING for (size_t i = 0; i < size_, i++;) { int a = contact.Get_a(); for (a = 1; ++i;) { contact.Set_a(0); int temp = contact[i].Get_id(); for (auto j = temp; j < size_; j++) { if (contact.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; contact.Set_id(i); //newContact[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; contact.Set_firstName(firstName); cout << "enter last name: " << endl; cin >> lastName; contact.Set_lastName(lastName); cout << "enter Email: " << endl; cin >> Email; contact.Set_email(Email); cout << "enter Street Address: " << endl; cin >> StreetAddress; contact.Set_streetAddress(StreetAddress); cout << "enter city: " << endl; cin >> City; contact.Set_city(City); cout << "enter State as two letter abbreviation: " << endl; cin >> State; contact.Set_state(State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> Zip; contact.Set_zip(Zip); break; } } for (size_t i = t; i < MAX; i++) { char firstName[30]; char lastName[30]; char Email[105]; char StreetAddress[45]; char City[35]; char State[4]; int Zip = 0; contact.Set_a(0); contact.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; contact.Set_firstName(firstName); cout << "enter last name: " << endl; cin >> lastName; contact.Set_lastName(lastName); cout << "enter Email: " << endl; cin >> Email; contact.Set_email(Email); cout << "enter Street Address: " << endl; cin >> StreetAddress; contact.Set_streetAddress(StreetAddress); cout << "enter city: " << endl; cin >> City; contact.Set_city(City); cout << "enter State as two letter abbreviation: " << endl; cin >> State; contact.Set_state(State); cout << "Please enter the next value as a series of numbers" << endl; cout << "enter Zip: " << endl; cin >> Zip; contact.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(contact newContact, size_t MAX) { //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 < MAX;) { 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(contact newContact[], size_t& MAX) const { //prints all info but count and bool for every existing (non trash value filled) contact struct //CURRENTLY WORKING for (size_t i = 0; i <= MAX; ++i) { /*for (int t = -1; t < newContact[i].id;) { break; }*/ size_t existing = newContact[i].Get_a(); size_t verify = newContact[i].Get_id(); if (existing == 1) { i = i + 1; } if (verify == 0) { break; } if (verify < 0) { break; } if (verify > MAX) { break; } cout << "List number: " << newContact[i].Get_id() << endl; cout << "First name: " << newContact[i].Get_firstName() << endl; cout << "Last name: " << newContact[i].Get_lastName(); cout << "Email: " << newContact[i].Get_email() << endl; cout << "Address: " << newContact[i].Get_streetAddress() << endl; cout << "city: " << newContact[i].Get_city() << endl; cout << "state: " << newContact[i].Get_state() << endl; cout << "Zip: " << newContact[i].Get_zip() << endl; } } 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 newContact[], size_t MAX) { //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 < MAX; i++) { if (newContact[i].Get_id() == 0) { break; } if (newContact[i].Get_id() < 0) { break; } if (newContact[i].Get_id() > MAX) { break; } //if (newContact[i].a == 1) //{ // break; //} cout << "Id number: " << newContact[i].Get_id() << " is under the name: " << newContact[i].Get_firstName() << " " << newContact[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 < MAX; 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 != newContact[i].Get_id()) { i = i + 1; } if (delete_choice == newContact[i].Get_id()) { newContact[i].Set_a(1); cout << "Contact number: " << newContact[i].Get_id() << " deleted" << endl; newContact[i + 1].Set_id(i - 1); break; } } //cout << "The list of contacts and their names will now print" << endl; // for (auto i = 0u; i <= MAX; i++) // { // if (newContact[i].id == 0) { // break; // } // if (newContact[i].id < 0) { // break; // } // if (newContact[i].id > MAX) { // break; // } // //if (newContact[i].a == 1) // //{ // // break; // //} // cout << "Id number: " << newContact[i].id << " is under the name: " << newContact[i].Name << 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; // break; // } } void contact_list::CopyList(const contact* contacts, const size_t& size) { }