Question
Task: search by ONLY last name and save and sort by alphabetic order of last name(order of saving is in the instruction). DO NOT USE
Task: search by ONLY last name and save and sort by alphabetic order of last name(order of saving is in the instruction). DO NOT USE CLASS AND VECTOR.
PLEASE SUBMIT A COMPLETE CODE!
Please write the code according to the instruction. Program needs to have input validation for numbers and characters input. Please make sure program saves sorted in the order of last name. You can implement on my code from assignment 1 if you want. It might save some time. But if you add things in my code, please make sure that you run the code in a compiler before you submit the solution to me. Code is given below after the description pictures.
#include #include #include #include #include using namespace std; enum PhoneType { CELL, HOME, WORK }; struct Contact { string firstName; string lastName; long long phoneNumber{}; PhoneType phoneType; }; void displayContacts(Contact[], int, bool); void addContact(Contact[], int); void loadDatabase(Contact[], int); void saveToDatabase(Contact[], int); string phoneNumberToString(long); int indexOfLastContact(Contact[], int); static const string DATABASE_TXT_FILE = "database.txt"; static const char DELIMITER = '~'; int main() { const int MAX_CONTACTS = 50; Contact contacts[MAX_CONTACTS]; loadDatabase(contacts, MAX_CONTACTS); int mainMenuChoice = 0; while (mainMenuChoice != 3) { cout > mainMenuChoice; switch (mainMenuChoice) { case 1: displayContacts(contacts, MAX_CONTACTS, false); break; case 2: addContact(contacts, MAX_CONTACTS); break; case 3: saveToDatabase(contacts, MAX_CONTACTS); break; } } return 0; } void displayContacts(Contact contacts[], int arraySize, bool isNumbered) { int indexOfLast = indexOfLastContact(contacts, arraySize); for (int i = 0; i > contact.firstName; cout > contact.lastName; bool isValidPhoneNumber = false; while (!isValidPhoneNumber) { long phoneNumber; cout > phoneNumber; if (cin.fail()) { cin.clear(); cin.ignore(numeric_limits::max(), ' '); continue; } if (phoneNumber > 9999999999 || phoneNumber 3) { cout > phoneTypeInt; if (cin.fail()) { cin.clear(); cin.ignore(numeric_limits::max(), ' '); } switch (phoneTypeInt) { case 1: contact.phoneType = CELL; break; case 2: contact.phoneType = HOME; break; case 3: contact.phoneType = WORK; break; } } contacts[indexOfLast + 1] = contact; cout Description: For this assignment you will add features to your Assignment 1 phone contacts app. In addition to the features you implemented in Assignment 1, your program will also display the contacts in alphabetical order by last name, allow the user to search for a specific contact by last name, and also delete a specific contact. Your program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact 3. Search for a contact given the contact's first or last name 4. Delete a contact 5. Exit program. To represent a contact in your program, create a struct named Contact with the following fields firstName string lastName string phoneNumber - long phoneType -enum PhoneType The PhoneType can be only one of the following: "CELL", "HOME", "WORK" When the program first loads, it reads all the saved contacts (if any) from a file named database.txt into a contacts array of size 50. You may NOT use vectors for this assignment. const int MAX CONTACTS 50; Contact contacts[MAX_CONTACTS]; Once the contacts are read from the database.txt file and loaded into the contacts array, the contacts array should be sorted by last name using either bubble sort or insertion sort. While the program is running, the user can choose any of the 5 available options. During the program execution, if the user chooses to add or delete contacts, the contacts array should be updated and re-sorted. Any searching of the contacts array should be performed using binary search. The database.txt file will be updated automatically only when the program is about to exit. In other words, when the user selects option 5, the program first writes the contents of the Array into the database.txt file, and then exits. The format of the contents of the database.txt file should be in human readable plain text, one record per line (note the separator between different entries) For example: Shawn Seals 5124567890 e Ted Sheckler~2104567890 2 Chip Chipperson 9404567890~1 For display, contacts should be printed to the console in the following format Chip Chipperson, Home (940)456-7890 Shawn Seals, Cell (512)456-7890 Ted Sheckler, Work (210)456-7890
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started