aboutsummaryrefslogtreecommitdiff
path: root/Homework6ReeceWarner/contacts.cpp
diff options
context:
space:
mode:
authorrPatrickWarner <[email protected]>2024-02-13 19:16:52 -0800
committerrPatrickWarner <[email protected]>2024-02-13 19:16:52 -0800
commitac302b109eefa96a332d1273754c3967f12db5d6 (patch)
tree7bc38a6b73ce67b1335f313cc76c79459a4bb4b5 /Homework6ReeceWarner/contacts.cpp
parentadd deadline (diff)
downloadhomework-6-reecepwarner-ac302b109eefa96a332d1273754c3967f12db5d6.tar.xz
homework-6-reecepwarner-ac302b109eefa96a332d1273754c3967f12db5d6.zip
init
Diffstat (limited to 'Homework6ReeceWarner/contacts.cpp')
-rw-r--r--Homework6ReeceWarner/contacts.cpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/Homework6ReeceWarner/contacts.cpp b/Homework6ReeceWarner/contacts.cpp
new file mode 100644
index 0000000..81992fe
--- /dev/null
+++ b/Homework6ReeceWarner/contacts.cpp
@@ -0,0 +1,203 @@
+#include "contacts.h"
+#include <iostream>
+#include <string>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+contact contacts[MAX] = {};
+contact emptycontact[MAX] = {}; //this is what I am comparing strings with in the print function
+int numberofcontacts = 0;
+
+contact InputNewContact()
+{
+ cout << "Avoid Using Spaces While Entering Your Street Name" << endl;
+ contact newcontact = {};
+ cout << "First Name: ";
+ cin >> newcontact.FirstName;
+
+ cout << "Last Name: ";
+ cin >> newcontact.LastName;
+
+ cout << "Email: ";
+ cin >> newcontact.Email;
+
+ cout << "Street Number: ";
+ cin >> newcontact.StreetNumber;
+
+ cout << "Street Name: ";
+ cin >> newcontact.StreetName;
+
+ cout << "City: ";
+ cin >> newcontact.city;
+
+ cout << "State: ";
+ cin >> newcontact.State;
+
+ cout << "Zip: ";
+ cin >> newcontact.Zip;
+
+ cout << "\n" << endl;
+
+ return newcontact;
+
+}
+
+
+void printcontacts()
+{
+ for (int x = 0; x < numberofcontacts; x++)
+ {
+ contact empty = emptycontact[x];
+
+ contact existingcontacts = contacts[x];
+ int result;
+ result = strcmp(existingcontacts.FirstName, empty.FirstName); //Compares the cString with an empty one, when it is equal, it prints nothing!!!
+ if (result == 0)
+ {
+ cout << " ";
+ }
+ else
+ {
+ _strupr_s(existingcontacts.FirstName); //permanently changing the string to uppercase
+ _strupr_s(existingcontacts.LastName);
+ cout << "Name " << x << ": " << existingcontacts.FirstName << " " << existingcontacts.LastName << endl;
+ }
+ result = strcmp(existingcontacts.Email, empty.Email);
+ if (result == 0)
+ {
+ cout << " ";
+ }
+ else
+ {
+ _strupr_s(existingcontacts.Email);
+
+ cout << "Email " << x << ": " << existingcontacts.Email << endl;
+ }
+ result = strcmp(existingcontacts.StreetNumber, empty.StreetNumber);
+ if (result == 0)
+ {
+ cout << " ";
+ }
+ else
+ {
+ _strupr_s(existingcontacts.StreetName);
+ cout << "Street Address " << x << ": " << existingcontacts.StreetNumber << " " << existingcontacts.StreetName << endl;
+ }
+ result = strcmp(existingcontacts.city, empty.city);
+ if (result == 0)
+ {
+ cout << " ";
+ }
+ else
+ {
+ _strupr_s(existingcontacts.city);
+ cout << "City " << x << ": " << existingcontacts.city << endl;
+ }
+ result = strcmp(existingcontacts.State, empty.State);
+ if (result == 0)
+ {
+ cout << " ";
+ }
+ else
+ {
+ _strupr_s(existingcontacts.State);
+ cout << "State(xx) " << x << ": " << existingcontacts.State << endl;
+ }
+ if (existingcontacts.Zip == 0)
+ {
+ cout << " " << endl;
+ }
+ else
+ {
+ cout << "Zip Code " << x << ": " << existingcontacts.Zip << endl;
+ cout << "//////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////" << endl; //little divider
+ }
+
+ }
+
+}
+
+
+contact UpdateContact()
+{
+ printcontacts();
+
+ cout << "\n\nWhich contact would you like to update?" << endl;
+
+ int i = 0;
+ cin >> i;
+ while (i >= numberofcontacts) //This while loop prevents the user from overwriting onto an undefined array. I tested it without it and I could write onto any integer that I input
+ {
+ cout << "Invalid Input, Try again" << endl;
+ cin >> i;
+ }
+
+ contacts[i] = InputNewContact();
+ contact updatedcontacts = contacts[i];
+ cout << "\n" << endl;
+
+ return updatedcontacts;
+
+}
+
+
+contact DeleteContactInformation()
+{
+ printcontacts();
+
+ cout << "\n\nWhich contact would you like to delete?" << endl;
+
+ int i = 0; //I didn't add the while loop from the update contact here because there were no negative consequences from inputing an integer larger than the numberofcontacts counter
+ cin >> i;
+ contact deletedcontact = contacts[i];
+ contacts[i] = {NULL};
+
+ for (i; i < numberofcontacts; i++) //shifts deleted contact to the top
+ {
+ contacts[i] = contacts[i + 1];
+ }
+
+ return deletedcontact;
+
+}
+
+
+void menu() {
+ char options = '\0';
+
+ do
+ {
+ cout << "Welcome to the contacts menu\n"
+ << "1)Add New Contact\n"
+ << "2)Update Contact\n"
+ << "3)Print All Contacts\n"
+ << "4)Delete Contact\n"
+ << "5)Exit\n";
+ cin >> options;
+ switch (options)
+ {
+ case('1'):
+ contacts[numberofcontacts++] = InputNewContact();
+ break;
+ case('2'):
+ UpdateContact();
+ break;
+ case('3'):
+ printcontacts();
+ break;
+ case('4'):
+ DeleteContactInformation();
+
+ break;
+ case('5'):
+ cout << "Have a wondeful day!" << endl;
+ break;
+ default:
+ cout << "Invalid Input, Try Again!" << endl;
+ }
+
+ } while (options != '5');
+
+};