diff options
| author | Connor McDowell <[email protected]> | 2024-03-08 12:36:58 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-03-08 12:36:58 -0800 |
| commit | 0da86e742fa41643aff752c1f434cb191036463a (patch) | |
| tree | cdbdcc91d900921829fd7a9dcdb48121b21c2c1f /Project1/contacts.cpp | |
| parent | proper char outputs. however each added contact is overwriting (saved to same... (diff) | |
| download | homework-7-connormcdowell275-0da86e742fa41643aff752c1f434cb191036463a.tar.xz homework-7-connormcdowell275-0da86e742fa41643aff752c1f434cb191036463a.zip | |
refactored with strings instead of char arrays
Diffstat (limited to 'Project1/contacts.cpp')
| -rw-r--r-- | Project1/contacts.cpp | 225 |
1 files changed, 105 insertions, 120 deletions
diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 20da12d..b255def 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -1,13 +1,15 @@ #include "Contact_list.h" +#include <string.h> #include <iostream> #include <list> #include <vector> +#include <stdio.h> using std::cin; using std::cout; using std::endl; -// constructors +// constructors and destructors contact_list::~contact_list() { @@ -35,47 +37,47 @@ contact_list::contact_list(const size_t& size) //getters n setters -void contact::Set_firstName(char* firstName) +void contact::Set_firstName(string firstName) { _firstName = firstName; } -const char* contact::Get_firstName() +string contact::Get_firstName() { return _firstName; } -void contact::Set_lastName(char* lastName) +void contact::Set_lastName(string lastName) { _lastName = lastName; } -const char* contact::Get_lastName() +string contact::Get_lastName() { return _lastName; } -void contact::Set_streetAddress(char* streetAddress) +void contact::Set_streetAddress(string streetAddress) { _streetAddress = streetAddress; } -const char* contact::Get_streetAddress() +string contact::Get_streetAddress() { return _streetAddress; } -void contact::Set_city(char* city) +void contact::Set_city(string city) { _city = city; } -const char* contact::Get_city() +string contact::Get_city() { return _city; } -void contact::Set_state(char* state) +void contact::Set_state(string state) { _state = state; } -const char* contact::Get_state() +string contact::Get_state() { return _state; } @@ -89,11 +91,11 @@ int contact::Get_zip() return _zip; } -void contact::Set_email(char* email) +void contact::Set_email(string email) { _email = email; } -const char* contact::Get_email() +string contact::Get_email() { return _email; } @@ -146,53 +148,54 @@ void contact::print() } //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 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) +void contact_list::AddContact(contact contact[], size_t& t, contact_struct save, contact_list contacts) { //CURRENTLY TESTING + contact_struct _save; for (size_t i = 0; i < size_, i++;) { size_t a = contacts_[i].Get_a(); @@ -206,42 +209,34 @@ void contact_list::AddContact(contact contact[], size_t& t, contact_struct save) { 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); } - //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); - // contacts_[size_++] = Contact; - break; } } @@ -273,17 +268,11 @@ void contact_list::AddContact(contact contact[], size_t& t, contact_struct save) 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); -/* size_t id = i; - contacts_[i].Set_id(id);*/ - //contacts_[size_++] = Contact; - contacts_[i].Get_firstName(); + 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; - - } //void contact_list::Update(const contact& contact) @@ -346,7 +335,7 @@ void contact_list::Print() const { i = i + 1; } - /* if (contacts_[i].Get_id() == 0) { + if (contacts_[i].Get_id() == 0) { break; }*/ if (contacts_[i].Get_id() < 0) { @@ -363,7 +352,9 @@ void contact_list::Print() const 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; + //} } } @@ -412,12 +403,6 @@ contact contact_double(contact*& newContact, size_t& MAX, size_t t) 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 @@ -440,18 +425,18 @@ void contact_list::DeleteContact(contact* contact[]) // 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; - //} + 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()) + { + contacts_[i].Set_a(1); + cout << "Contact number: " << contacts_[i].Get_id() << " deleted" << endl; + contacts_[i + 1].Set_id(contacts_[i + 1].Get_id() - 1); + break; + } } for (auto i = 0u; i < size_; i++) { |