#include "contacts.h" contact emptycontact[MAX] = {}; //this is what I am comparing strings with in the print function int numberofcontacts = 0; contact* contacts = new contact[MAX]; contact InputNewContact(const size_t size) { contact* contacts = new contact[size]; cout.flush(); cin.ignore(); cout.flush(); Prompts("What is your name?"); cout.flush(); cin.get(contacts->Name, 50, '\n'); cin.ignore(); Prompts("What is your Email?"); cin.get(contacts->Email, 100, '\n'); Prompts("What is your Street"); cin.ignore(); cin.get(contacts->Street, 100, '\n'); Prompts("What is your city?"); cin.ignore(); cin.get(contacts->city, 30, '\n'); Prompts("What is your state?"); cin.ignore(); cin.get(contacts->State, 04, '\n'); Prompts("What is your Zip?"); cin.ignore(); cin.get(contacts->Zip, 50, '\n'); return *contacts; } void printcontacts() { for (int x = 0; x < numberofcontacts; x++) { contact empty = emptycontact[x]; contact existingcontacts = contacts[x]; int result; result = strcmp(existingcontacts.Name, empty.Name); //Compares the cString with an empty one, when it is equal, it prints nothing!!! if (result == 0) { Prompts(""); cout << endl; } else { OutputContacts(_strupr(existingcontacts.Name), "Name", x); OutputContacts(_strupr(existingcontacts.Email), "Email", x); OutputContacts(_strupr(existingcontacts.Street), "Street Address", x); OutputContacts(_strupr(existingcontacts.city), "City", x); OutputContacts(_strupr(existingcontacts.State), "State", x); cout << "Zip Code " << x << ": " << existingcontacts.Zip << endl; cout << "//////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////" << endl; //little divider } } } contact UpdateContact() { printcontacts(); int i = ReadInt("Which contact would you like to update?"); contacts[i] = InputNewContact(MAX); contact updatedcontacts = contacts[i]; cout << "\n" << endl; return updatedcontacts; } contact* DeleteContactInformation() { printcontacts(); contact* deletedcontact = &contacts[ReadInt("Which contact would you like to delete?")]; *deletedcontact = { '\0' }; 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'): if (numberofcontacts==3) { contacts[numberofcontacts++] = InputNewContact(DoubleArraySize(MAX)); } else { contacts[numberofcontacts++] = InputNewContact(MAX); } break; case('2'): UpdateContact(); break; case('3'): printcontacts(); break; case('4'): DeleteContactInformation(); break; case('5'): cout << "Have a wondeful day!" << endl; DeleteEverything(); break; default: cout << "Invalid Input, Try Again!" << endl; } } while (options != '5'); }; void Prompts(const char* phrase) { cout.flush(); cout << phrase << " "; cout.flush(); } void OutputContacts(char* arrays, const char* prompt, int x) { cout << prompt << " " << x << ": "; cout << arrays << endl; } const size_t DoubleArraySize(const size_t& size) { contact* newArray = nullptr; newArray = new contact[size * 2]; for (auto i = 0u; i < size; i++) { newArray[i] = contacts[i]; } delete[] contacts; contacts = newArray; const size_t newsize = size * 2; return newsize; } int ReadInt(const char* Prompt) { int Value; cout << endl << Prompt << ": "; cin >> Value; while (!cin) { cin.clear(); cin.ignore(MAX_STREAM_SIZE, '\n'); cout << "That is not a number, please try again!" << endl; cout.flush(); cin >> Value; } return Value; } void DeleteEverything() { delete[] contacts; }