aboutsummaryrefslogtreecommitdiff
path: root/Homework 6
diff options
context:
space:
mode:
Diffstat (limited to 'Homework 6')
-rw-r--r--Homework 6/Homework 6/Contacts.cpp23
-rw-r--r--Homework 6/Homework 6/Contacts.h2
-rw-r--r--Homework 6/Homework 6/program.cpp54
3 files changed, 32 insertions, 47 deletions
diff --git a/Homework 6/Homework 6/Contacts.cpp b/Homework 6/Homework 6/Contacts.cpp
index 86f2fbb..fdcfdca 100644
--- a/Homework 6/Homework 6/Contacts.cpp
+++ b/Homework 6/Homework 6/Contacts.cpp
@@ -43,25 +43,22 @@ Contact InputContact()
}
-void PrintContacts(Contact(&contacts)[10]) {
- int i = 1;
- for (auto &x : contacts) {
-
- cout << "\nContact #: " << i << endl;
+void PrintContacts(Contact(&contacts)[10], int numberOfContacts) {
+
+ for (int i = 0; i < numberOfContacts; i++) {
+ cout << "\nContact #: " << i + 1 << endl;
- cout << "Name: " << x.Name << endl;
+ cout << "Name: " << contacts[i].Name << endl;
- cout << "Email: " << x.Email << endl;
+ cout << "Email: " << contacts[i].Email << endl;
- cout << "Street Adress: "<< x.StreetAdress << endl;
+ cout << "Street Adress: " << contacts[i].StreetAdress << endl;
- cout << "City: " << x.City << endl;
+ cout << "City: " << contacts[i].City << endl;
- cout << "State: " << x.State << endl;
+ cout << "State: " << contacts[i].State << endl;
- cout << "Zip: " << x.Zip << endl;
-
- i = i+1;
+ cout << "Zip: " << contacts[i].Zip << endl;
}
}
diff --git a/Homework 6/Homework 6/Contacts.h b/Homework 6/Homework 6/Contacts.h
index 811d349..6a8ac55 100644
--- a/Homework 6/Homework 6/Contacts.h
+++ b/Homework 6/Homework 6/Contacts.h
@@ -17,7 +17,7 @@ Contact InputContact();
void Menu();
-void PrintContacts(Contact(&contacts)[10]);
+void PrintContacts(Contact(&contacts)[10], int numberOfContacts);
diff --git a/Homework 6/Homework 6/program.cpp b/Homework 6/Homework 6/program.cpp
index 8a01d6d..dcd2a87 100644
--- a/Homework 6/Homework 6/program.cpp
+++ b/Homework 6/Homework 6/program.cpp
@@ -17,9 +17,10 @@ void Menu() {
<< "3. Print All Contacts" << endl << "4. Exit" << endl;
}
-Contact contacts[MAX] = {};
+
int main() {
+ Contact contacts[MAX] = {};
int numberOfContacts = 0;
Menu();
@@ -28,16 +29,17 @@ int main() {
system("cls");
while (i != 4) {
- if (i == 1)
- {
+ int t = 1;
+ int x = 1;
+ switch (i) {
+ case 1:
contacts[numberOfContacts] = InputContact();
numberOfContacts++;
system("cls");
- }
- else if (i == 2)
- {
+ break;
+ case 2:
cout << "\nCurrent contacts: " << endl;
- int x = 1;
+
for (int y = 0; y < numberOfContacts; y++) {
cout << "\nContact #: " << x << endl;
@@ -59,36 +61,22 @@ int main() {
cout << "\n\nEnter the contact # to update it." << endl;
int k;
cin >> k;
- contacts[k-1] = InputContact();
+ contacts[k - 1] = InputContact();
+ break;
+
+ case 3:
+
+ PrintContacts(contacts, numberOfContacts);
+ break;
+ default:
+ cout << "this was a bad input" << endl;
+ break;
}
- else if (i == 3)
- {
- int t = 1;
- for (int i = 0; i < numberOfContacts; i++) {
- cout << "\nContact #: " << t << endl;
-
- cout << "Name: " << contacts[i].Name << endl;
-
- cout << "Email: " << contacts[i].Email << endl;
-
- cout << "Street Adress: " << contacts[i].StreetAdress << endl;
-
- cout << "City: " << contacts[i].City << endl;
-
- cout << "State: " << contacts[i].State << endl;
- cout << "Zip: " << contacts[i].Zip << endl;
-
- t = t + 1;
- }
- }
-
- int j;
Menu();
-
- cin >> j;
- i = j;
+ cin >> i;
system("cls");
+
}
return 0;
}