aboutsummaryrefslogtreecommitdiff
path: root/homework5
diff options
context:
space:
mode:
authorrPatrickWarner <[email protected]>2024-02-12 17:38:48 -0800
committerrPatrickWarner <[email protected]>2024-02-12 17:38:48 -0800
commite28ef933d39e32232b7a8719b070fde83ae2f252 (patch)
tree1f5def391e0dcbde24050fe519c2de4e2ed52b50 /homework5
parentinit (diff)
downloadhomework-5-reecepwarner-main.tar.xz
homework-5-reecepwarner-main.zip
finalchanges/completedHEADmain
Diffstat (limited to 'homework5')
-rw-r--r--homework5/homework5/contacts.cpp204
-rw-r--r--homework5/homework5/contacts.h23
-rw-r--r--homework5/homework5/program.cpp18
3 files changed, 226 insertions, 19 deletions
diff --git a/homework5/homework5/contacts.cpp b/homework5/homework5/contacts.cpp
index 131d7d0..81992fe 100644
--- a/homework5/homework5/contacts.cpp
+++ b/homework5/homework5/contacts.cpp
@@ -1 +1,203 @@
-#include "contacts.h" \ No newline at end of file
+#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');
+
+};
diff --git a/homework5/homework5/contacts.h b/homework5/homework5/contacts.h
index 182b858..9fec259 100644
--- a/homework5/homework5/contacts.h
+++ b/homework5/homework5/contacts.h
@@ -1,17 +1,30 @@
-#ifndef contacts
+#ifndef contactsheader
+
+#define contactsheader
+
+#define MAX 100
-#define contacts
struct contact
{
- char Name[25] = {};
+ char FirstName[50] = {};
+ char LastName[50] = {};
char Email[100] = {};
- char StreetAddress[35] = {};
+ char StreetNumber[50] = {};
+ char StreetName[100] = {};
char city[30] = {};
- char State[2] = {};
+ char State[4] = {};
int Zip = 0;
+
};
+void menu();
+contact InputNewContact();
+contact UpdateContact();
+void printcontacts();
+
+
+
#endif
diff --git a/homework5/homework5/program.cpp b/homework5/homework5/program.cpp
index b960f1d..a888184 100644
--- a/homework5/homework5/program.cpp
+++ b/homework5/homework5/program.cpp
@@ -1,27 +1,19 @@
//Name:Reece Warner
//Date:Feb 5th 2024
//Homework 5
-
-
#include "contacts.h"
#include <iostream>
+
using std::cout;
using std::cin;
using std::endl;
+
int main()
{
-
-
-
-
-
-
-
-
-
-
+ menu();
return 0;
-} \ No newline at end of file
+}
+