#ifndef MENU_HELPER_HPP #define MENU_HELPER_HPP #define _CRT_SECURE_NO_WARNINGS #include "ContactList.hpp" namespace MyStructures { void MainMenu(); Contact InputContact(); char* PromptCharInput(const char* prompt, long long maxlen); int InputInt(const char* prompt); void MainMenu() { char Options = '\0'; size_t i = 0; ContactList AddressBook(3); do { std::cout << "Welcome to the contacts menu\n" << "1)Add New Contact\n" << "2)Print All Contacts\n" << "3)Delete Contact\n" << "4)Exit\n"; std::cin >> Options; switch (Options) { case('1'): AddressBook.Append(InputContact()); break; case('2'): AddressBook.PrintList(); break; case('3'): AddressBook.DeleteContact(InputInt("Which Contact Would you like to delete?")-1); break; case('4'): std::cout << "Thank you, have a great day!" << std::endl; break; default: std::cout << "Invalid Input, Try Again!" << std::endl; } } while (Options != '4'); } Contact InputContact() { Contact newContact; newContact.SetFirstName(PromptCharInput("What is your first name?", 101)); newContact.SetLastName(PromptCharInput("What is your last name?: ", 101)); newContact.SetStreet(PromptCharInput("What is your street address?: ", 101)); newContact.SetEmail(PromptCharInput("What is your email?: ", 101)); newContact.SetState(PromptCharInput("What is your state?: ", 101)); newContact.SetCity(PromptCharInput("What is your city?: ", 101)); newContact.SetZip(InputInt("What is your zip?")); return newContact; } char* PromptCharInput(const char* prompt, long long maxlen) { std::cout.flush(); std::cout << prompt << std::endl; char* input = new char[maxlen]; cin >> input; while (!std::cin) { cout << prompt << std::endl; cin.clear(); cin.ignore(MAX_STREAM_SIZE, '\n'); cin.get(input, MAX_STREAM_SIZE, '\n'); } return input; } int InputInt(const char* prompt) { std::cout << prompt << std::endl; std::cout.flush(); int data = 0; std::cin >> data; while (!std::cin) { std::cout << prompt << std::endl; std::cin.clear(); cin.ignore(MAX_STREAM_SIZE, '\n'); std::cin >> data; } return data; } }; #endif