diff options
| -rw-r--r-- | Project1/Contact_list.h | 2 | ||||
| -rw-r--r-- | Project1/Contacts.h | 61 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 225 | ||||
| -rw-r--r-- | Project1/program.cpp | 11 |
4 files changed, 144 insertions, 155 deletions
diff --git a/Project1/Contact_list.h b/Project1/Contact_list.h index 9a9dd70..c4c0973 100644 --- a/Project1/Contact_list.h +++ b/Project1/Contact_list.h @@ -31,7 +31,7 @@ public: void CopyList(const contact* contacts, const size_t& size); - void AddContact(contact contact[], size_t& t, contact_struct save); + void AddContact(contact contact[], size_t& t, contact_struct save, contact_list contacts); void Print() const; diff --git a/Project1/Contacts.h b/Project1/Contacts.h index be81523..48a89c3 100644 --- a/Project1/Contacts.h +++ b/Project1/Contacts.h @@ -1,7 +1,8 @@ #ifndef CONTACTS_HEADER_H #define CONTACTS_HEADER_H - +#include <iostream> +using namespace std; // functions @@ -16,26 +17,26 @@ public: contact(contact&& move); contact& operator=(contact&& rhs);*/ - const char* Get_firstName(); - void Set_firstName(char* firstName); + string Get_firstName(); + void Set_firstName(string firstName); - const char* Get_lastName(); - void Set_lastName(char* lastName); + string Get_lastName(); + void Set_lastName(string lastName); - const char* Get_streetAddress(); - void Set_streetAddress(char* streetAddress); + string Get_streetAddress(); + void Set_streetAddress(string streetAddress); - const char* Get_city(); - void Set_city(char* city); + string Get_city(); + void Set_city(string city); - const char* Get_state(); - void Set_state(char* state); + string Get_state(); + void Set_state(string state); int Get_zip(); void Set_zip(int zip); - const char* Get_email(); - void Set_email(char* email); + string Get_email(); + void Set_email(string email); size_t Get_a(); void Set_a(size_t a); @@ -49,31 +50,31 @@ private: size_t _a = 0; // _a functions as delete bool. if a = 1, the slot is overwritten int _id; - char* _firstName{ }; - char* _lastName{ }; - char* _streetAddress{ }; - char* _city{ }; - char* _state{ }; + string _firstName; + string _lastName; + string _streetAddress; + string _city; + string _state; int _zip; - char* _email{ }; + string _email; }; struct contact_struct { - int a = 0; + int a = 0; //size_t id = contact_list::get_length; - int id = 0; - size_t count = 0; - char firstName[30]; - char lastName[30]; - char Email[105]; - char StreetAddress[45]; - char City[35]; - char State[4]; - int Zip = 0; - //contact() : a(true), id(0), count(0), Zip(0) {} + int id = 0; + size_t count = 0; + string firstName; + string lastName; + string Email; + string StreetAddress; + string City; + string State; + int Zip = 0; + //contact() : a(true), id(0), count(0), Zip(0) {} }; //struct contact 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++) { diff --git a/Project1/program.cpp b/Project1/program.cpp index c7a776f..4d4d6f6 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -5,6 +5,8 @@ #include "Contact_list.h" #include <iostream> +#include <string.h> +#include <stdio.h> using std::cin; using std::cout; @@ -24,7 +26,7 @@ int main() size_t t = 0; contacts.set_size(MAX); - cout << contacts.get_size() << endl; + //cout << contacts.get_size() << endl; while (O == 1) { contact_struct save_contacts; @@ -32,7 +34,7 @@ int main() // c = choice input int c = 0; cout << "1. Enter a contact\n"; - cout << "2. Update a contact\n"; + cout << "2. Copy all contacts\n"; cout << "3. print all contacts\n"; cout << "4. Delete a contact\n"; cout << "5. Quit\n"; @@ -42,7 +44,7 @@ int main() { case 1: //addNew(newContact, MAX, t); - contacts.AddContact(newContact, t, save_contacts); + contacts.AddContact(newContact, t, save_contacts, contacts); //addContact(newContact, contacts.get_size(), contacts[MAX]); //for (auto i = 0u; i < MAX; ++i) //{ @@ -91,7 +93,8 @@ int main() break; case 2: //contacts.Update(newContact); - cout << "this program is currently a work in progress" << endl; + //cout << "this program is currently a work in progress" << endl; + contacts.CopyList(newContact, contacts.get_size()); break; case 3: contacts.Print(); // Print only the existing contacts |