aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-03-07 13:07:49 -0800
committerConnor McDowell <[email protected]>2024-03-07 13:07:49 -0800
commit47cbdd02b22b832175e77f03846845d188701bba (patch)
tree12f8673347c42a199da20fc346929505f3276931
parentstarting work (diff)
downloadhomework-7-connormcdowell275-47cbdd02b22b832175e77f03846845d188701bba.tar.xz
homework-7-connormcdowell275-47cbdd02b22b832175e77f03846845d188701bba.zip
proper char outputs. however each added contact is overwriting (saved to same point in memory)
-rw-r--r--Project1/Contact_list.h4
-rw-r--r--Project1/Contacts.h28
-rw-r--r--Project1/contacts.cpp112
-rw-r--r--Project1/program.cpp10
4 files changed, 76 insertions, 78 deletions
diff --git a/Project1/Contact_list.h b/Project1/Contact_list.h
index adfdbd6..9a9dd70 100644
--- a/Project1/Contact_list.h
+++ b/Project1/Contact_list.h
@@ -27,11 +27,11 @@ public:
void set_size(size_t size);
size_t get_size();
- void DeleteContact(contact& contact);
+ void DeleteContact(contact* contact[]);
void CopyList(const contact* contacts, const size_t& size);
- void AddContact(contact& contact, size_t& t);
+ void AddContact(contact contact[], size_t& t, contact_struct save);
void Print() const;
diff --git a/Project1/Contacts.h b/Project1/Contacts.h
index fa2cad9..be81523 100644
--- a/Project1/Contacts.h
+++ b/Project1/Contacts.h
@@ -60,19 +60,21 @@ private:
};
-//struct contact_struct
-//{
-// int a = 0;
-// size_t id = contact_list::get_length;
-// size_t count = 0;
-// char Name[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) {}
-//};
+struct contact_struct
+{
+ 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) {}
+};
//struct contact
//{
diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp
index 2fec269..20da12d 100644
--- a/Project1/contacts.cpp
+++ b/Project1/contacts.cpp
@@ -190,7 +190,7 @@ void addContact(contact newContact, size_t MAX, contact_list contacts[])
}
}
-void contact_list::AddContact(contact& Contact, size_t& t)
+void contact_list::AddContact(contact contact[], size_t& t, contact_struct save)
{
//CURRENTLY TESTING
for (size_t i = 0; i < size_, i++;)
@@ -207,84 +207,77 @@ void contact_list::AddContact(contact& Contact, size_t& t)
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);
- contacts_[size_++] = Contact;
+ //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;
}
}
- for (size_t i = t; i < size_; i++)
+ for (size_t i = t; i < size_;)
{
- 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);
//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);
+ cin >> save.firstName;
+ contacts_[i].Set_firstName(save.firstName);
cout << "enter last name: " << endl;
- cin >> lastName;
- contacts_[i].Set_lastName(lastName);
+ cin >> save.lastName;
+ contacts_[i].Set_lastName(save.lastName);
cout << "enter Email: " << endl;
- cin >> Email;
- contacts_[i].Set_email(Email);
+ cin >> save.Email;
+ contacts_[i].Set_email(save.Email);
cout << "enter Street Address: " << endl;
- cin >> StreetAddress;
- contacts_[i].Set_streetAddress(StreetAddress);
+ cin >> save.StreetAddress;
+ contacts_[i].Set_streetAddress(save.StreetAddress);
cout << "enter city: " << endl;
- cin >> City;
- contacts_[i].Set_city(City);
+ cin >> save.City;
+ contacts_[i].Set_city(save.City);
cout << "enter State as two letter abbreviation: " << endl;
- cin >> State;
- contacts_[i].Set_state(State);
+ 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 >> Zip;
- contacts_[i].Set_zip(Zip);
- t++;
+ 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();
break;
}
@@ -369,6 +362,7 @@ void contact_list::Print() const
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;
}
}
@@ -424,7 +418,7 @@ size_t max_double(size_t MAX)
return MAX;
}
-void contact_list::DeleteContact(contact& contact)
+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
diff --git a/Project1/program.cpp b/Project1/program.cpp
index ab71dce..c7a776f 100644
--- a/Project1/program.cpp
+++ b/Project1/program.cpp
@@ -17,8 +17,8 @@ int main()
size_t MAX = 3;
int O = 1;
/* t = index counter*/
- contact newContact;
- //contact* newContact = new contact[MAX];
+ //contact newContact;
+ contact* newContact = new contact[MAX];
contact_list contacts(MAX);
size_t t = 0;
@@ -27,6 +27,7 @@ int main()
cout << contacts.get_size() << endl;
while (O == 1)
{
+ contact_struct save_contacts;
//cout << MAX << endl;
// c = choice input
int c = 0;
@@ -41,7 +42,7 @@ int main()
{
case 1:
//addNew(newContact, MAX, t);
- contacts.AddContact(newContact, t);
+ contacts.AddContact(newContact, t, save_contacts);
//addContact(newContact, contacts.get_size(), contacts[MAX]);
//for (auto i = 0u; i < MAX; ++i)
//{
@@ -85,6 +86,7 @@ int main()
// contacts.AddContact(newContact);
// break;
//}
+ t++;
break;
case 2:
@@ -95,7 +97,7 @@ int main()
contacts.Print(); // Print only the existing contacts
break;
case 4:
- contacts.DeleteContact(newContact);
+ contacts.DeleteContact(&newContact);
//contacts.CopyList(&newContact, MAX);
break;
case 5: