aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNataliia Brown <[email protected]>2024-02-16 01:28:12 -0800
committerNataliia Brown <[email protected]>2024-02-16 01:28:12 -0800
commit7d41b75cd0c182d1044af74411a0e0b174a56eea (patch)
tree60c375de0e596f897d930315023ec727cfba035b
parentstill working on update (diff)
downloadhomework-5-natabrown-7d41b75cd0c182d1044af74411a0e0b174a56eea.tar.xz
homework-5-natabrown-7d41b75cd0c182d1044af74411a0e0b174a56eea.zip
compiles and correct
-rw-r--r--Homework 5/Homework 5/Contacts.cpp38
-rw-r--r--Homework 5/Homework 5/Contacts.h4
-rw-r--r--Homework 5/Homework 5/program.cpp100
3 files changed, 81 insertions, 61 deletions
diff --git a/Homework 5/Homework 5/Contacts.cpp b/Homework 5/Homework 5/Contacts.cpp
index 69c2118..bd4c5f2 100644
--- a/Homework 5/Homework 5/Contacts.cpp
+++ b/Homework 5/Homework 5/Contacts.cpp
@@ -4,17 +4,20 @@
// Assignment: Homework 5
#include "Contacts.h"
-
#include <iostream>
-#include <vector>
+#include <array>
using namespace std;
-Contact InputPersonalInfo()
+
+
+
+
+Contact InputContact()
{
Contact user = {};
- cout << "Adding New Contact:" << endl;
+ cout << "\nAdding New Contact:" << endl;
cout << "Name: ";
cin >> user.Name;
@@ -34,8 +37,33 @@ Contact InputPersonalInfo()
cout << "Zip: ";
cin >> user.Zip;
- system("cls");
+
return user;
+
+}
+
+
+void PrintContacts(Contact(&contacts)[10]) {
+ int i = 1;
+ for (auto &x : contacts) {
+
+ cout << "\nContact #: " << i << endl;
+
+ cout << "Name: " << x.Name << endl;
+
+ cout << "Email: " << x.Email << endl;
+
+ cout << "Street Adress: "<< x.StreetAdress << endl;
+
+ cout << "City: " << x.City << endl;
+
+ cout << "State: " << x.State << endl;
+
+ cout << "Zip: " << x.Zip << endl;
+
+ i = i+1;
+ }
+
}
diff --git a/Homework 5/Homework 5/Contacts.h b/Homework 5/Homework 5/Contacts.h
index 4bba12c..944d692 100644
--- a/Homework 5/Homework 5/Contacts.h
+++ b/Homework 5/Homework 5/Contacts.h
@@ -13,10 +13,12 @@ struct Contact
int Zip = 0;
};
-Contact InputPersonalInfo();
+Contact InputContact();
void Menu();
+void PrintContacts(Contact(&contacts)[10]);
+
diff --git a/Homework 5/Homework 5/program.cpp b/Homework 5/Homework 5/program.cpp
index c545401..cda038b 100644
--- a/Homework 5/Homework 5/program.cpp
+++ b/Homework 5/Homework 5/program.cpp
@@ -6,104 +6,94 @@
#include "Contacts.h"
#include <iostream>
-#include<list>
-#include <vector>
+#include <cstdlib>
using namespace std;
+const int MAX = 10;
void Menu() {
- cout << "Please choose option from 1 to 4:" << endl << "1. Add New Contact" << endl << "2. Update Contact" << endl
+ cout << "\nPlease choose option from 1 to 4:" << endl << "1. Add New Contact" << endl << "2. Update Contact" << endl
<< "3. Print All Contacts" << endl << "4. Exit" << endl;
}
-
+Contact contacts[MAX] = {};
int main() {
-
+ int numberOfContacts = 0;
+
Menu();
-
int i;
cin >> i;
-
- vector<Contact>vecContacts;
+ system("cls");
while (i != 4) {
-
if (i == 1)
- {
+ {
+ contacts[numberOfContacts] = InputContact();
+ numberOfContacts++;
system("cls");
- cout << "1: " << endl;
-
- vecContacts.push_back(InputPersonalInfo());
}
-
else if (i == 2)
{
- //system("cls");
+ cout << "\nCurrent contacts: " << endl;
+ int x = 1;
+ for (int y = 0; y < numberOfContacts; y++) {
- cout << "Enter email to update contact: " << endl;
+ cout << "\nContact #: " << x << endl;
- char new_email;
- cin >> new_email;
+ cout << "Name: " << contacts[y].Name << endl;
- for (int count = 0; count < vecContacts.size(); count++)
- {
- if (vecContacts[count].Email == new_email) {
+ cout << "Email: " << contacts[y].Email << endl;
- Contact new_user = {};
- cout << "Updating Contact:" << endl;
+ cout << "Street Adress: " << contacts[y].StreetAdress << endl;
- cout << "New Email: ";
- cin >> new_user.Email;
+ cout << "City: " << contacts[y].City << endl;
- cout << "New Name: ";
- cin >> new_user.Name;
+ cout << "State: " << contacts[y].State << endl;
- cout << "New Street Adress: ";
- cin >> new_user.StreetAdress;
+ cout << "Zip: " << contacts[y].Zip << endl;
- cout << "New City: ";
- cin >> new_user.City;
+ x = x + 1;
+ }
+ cout << "\n\nEnter the contact # to update it." << endl;
+ int k;
+ cin >> k;
+ contacts[k-1] = InputContact();
+ }
+ else if (i == 3)
+ {
+ int t = 1;
+ for (int i = 0; i < numberOfContacts; i++) {
+ cout << "\nContact #: " << t << endl;
- cout << "New State: ";
- cin >> new_user.State;
+ cout << "Name: " << contacts[i].Name << endl;
- cout << "New Zip: ";
- cin >> new_user.Zip;
+ cout << "Email: " << contacts[i].Email << endl;
- vecContacts.push_back(new_user);
- }
- else {
+ cout << "Street Adress: " << contacts[i].StreetAdress << endl;
- cout << "No such contact." << endl;
+ cout << "City: " << contacts[i].City << endl;
- }
- }
- }
- else if (i == 3)
- {
- //system("cls");
- cout << "3: " << endl;
- for (int count = 0; count < vecContacts.size(); count++)
- {
- cout << "\nName: " << vecContacts[count].Name << "\nEmail: " << vecContacts[count].Email << "\nStreet Adress: " << vecContacts[count].StreetAdress << "\nCity: " << vecContacts[count].City << "\nState: " << vecContacts[count].State << "\nZip: " << vecContacts[count].Zip << endl;
- }
- cout << endl;
+ cout << "State: " << contacts[i].State << endl;
+
+ cout << "Zip: " << contacts[i].Zip << endl;
+ t = t + 1;
+ }
}
- //system("cls");
+
int j;
Menu();
cin >> j;
i = j;
-
-
-
+ system("cls");
}
return 0;
}
+
+