#include "contacts.h" #include #include 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'); };