aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYana Blashchishina <[email protected]>2024-02-12 07:16:02 -0800
committerYana Blashchishina <[email protected]>2024-02-12 07:16:02 -0800
commitfbf383f000634607b75e7a87187f788bd1f8cc0c (patch)
tree026d00418373a4e727298d59781e3c81d0bc468a
parentfresh start, idk what im doing (diff)
downloadhomework-5-yanablash-main.tar.xz
homework-5-yanablash-main.zip
completedHEADmain
-rw-r--r--Homework5/Homework5/Contacts.cpp73
-rw-r--r--Homework5/Homework5/Contacts.h13
-rw-r--r--Homework5/Homework5/program.cpp37
3 files changed, 120 insertions, 3 deletions
diff --git a/Homework5/Homework5/Contacts.cpp b/Homework5/Homework5/Contacts.cpp
index 7c54964..85777ab 100644
--- a/Homework5/Homework5/Contacts.cpp
+++ b/Homework5/Homework5/Contacts.cpp
@@ -2,3 +2,76 @@
#include "Contacts.h"
+using std::cout;
+using std::cin;
+using std::endl;
+
+void addContact (Contact contacts[], int& numContacts) {
+ if (numContacts < 100) {
+ Contact& newContact = contacts[numContacts];
+
+ cout << "Enter Name: ";
+ cin >> newContact.Name;
+
+ cout << "Enter Email: ";
+ cin >> newContact.Email;
+
+ cout << "Enter Street Address: ";
+ cin >> newContact.StreetAddress;
+
+ cout << "Enter City: ";
+ cin >> newContact.City;
+
+ cout << "Enter State: ";
+ cin >> newContact.State;
+
+ cout << "Enter Zip Code: ";
+ cin >> newContact.Zip;
+ }
+}
+
+
+
+void updateContact(Contact contacts[], int& numContacts) {
+ int num;
+ cin >> num;
+ Contact& contactToUpdate = contacts[num];
+
+ cout << "Enter new Name: ";
+ cin >> contactToUpdate.Name;
+
+ cout << "Enter new Email: ";
+ cin >> contactToUpdate.Email;
+
+ cout << "Enter new Street Address: ";
+ cin >> contactToUpdate.StreetAddress;
+
+ cout << "Enter New City: ";
+ cin >> contactToUpdate.City;
+
+ cout << "Enter New State: ";
+ cin >> contactToUpdate.State;
+
+ cout << "Enter new Zip Code: ";
+ cin >> contactToUpdate.Zip;
+
+ cout << "Contact Updated";
+}
+
+void printContact(const Contact contacts[], int numContacts) {
+ if (numContacts == 0) {
+ cout << "No contacts available";
+ }
+ else {
+ cout << "Contacts: ";
+ for (int i = 0; i < numContacts; ++i) {
+ const Contact& contact = contacts[i];
+ cout << "Name: " << contact.Name << " x ";
+ cout << "Email: " << contact.Email << " x ";
+ cout << "Street Address: " << contact.StreetAddress << " x ";
+ cout << "City: " << contact.City << " x ";
+ cout << " State: " << contact.State << " x ";
+ cout << " Zip Code: " << contact.Zip << " x ";
+ }
+ }
+} \ No newline at end of file
diff --git a/Homework5/Homework5/Contacts.h b/Homework5/Homework5/Contacts.h
index 4236b61..31d24a3 100644
--- a/Homework5/Homework5/Contacts.h
+++ b/Homework5/Homework5/Contacts.h
@@ -1,7 +1,16 @@
#ifndef CONTACTS_H
#define CONTACTS_H
+struct Contact {
+ char Name[25] = {};
+ char Email[100] = {};
+ char StreetAddress[35] = {};
+ char City[30] = {};
+ char State[2] = {};
+ int Zip = 0;
+};
-
-
+ void addContact(Contact contacts[], int& numContacts);
+ void updateContact(Contact contacts[], int& numContacts);
+ void printContact(const Contact contacts[], int numContacts);
#endif \ No newline at end of file
diff --git a/Homework5/Homework5/program.cpp b/Homework5/Homework5/program.cpp
index af695b5..20573b3 100644
--- a/Homework5/Homework5/program.cpp
+++ b/Homework5/Homework5/program.cpp
@@ -13,7 +13,42 @@ using std::cin;
using std::endl;
int main() {
-
+ Contact contacts[10];
+ int numContacts = 0;
+
+ while (true) {
+ cout << " Menu Options: ";
+ cout << "1. Add New Contact ";
+ cout << "2. Update Contact ";
+ cout << "3. Print All Contacts ";
+ cout << "4. Exit ";
+
+
+ int option;
+ cout << "Enter your option: ";
+ cin >> option;
+
+
+ switch (option) {
+ case 1:
+ addContact(contacts, numContacts);
+ break;
+
+ case 2:
+ updateContact(contacts, numContacts);
+ break;
+
+ case 3:
+ printContact(contacts, numContacts);
+ break;
+
+ case 4:
+ cout << "Exiting";
+ return 0;
+ default:
+ cout << "Try Again";
+ }
+ }