Please answer this in C++: Define a structure called Contact with two c-strings: name and phone_number. Declare a sort function that takes a Contact pointer and size of Contacts and sorts the Contacts pointed to by the pointer in ascending order based on the Contact names. Declare a binary search function that takes a Contact pointer, size of Contacts and a c-string for a name and searches for the Contact name given by the c-string. The function must return the index where the contact was found or -1, if not found. In main, ask the user how many Contacts to create and dynamically allocate memory for as many Contacts as specified by the user. Read names and phone numbers of as many contacts as specified by the user and store them in the Contacts dynamically allocated. Sort the contacts by name using the sort function and display all contacts: names and phone numbers. Then, read a name from the user and using the binary search function search for it and then print in main the name and phone number of the search contact, if found or that it was not found. Delete the Contacts dynamically created when done. Hints: Remember you must use functions for copying and comparing c-strings. See strcpy and strcmp Remember you may use [] to access the contents of a pointer You must use cin.getline() function to read multiword strings Remember to use cin.ignore() to clear the keyboard buffer after a cin and before cin.getline() When accessing name or phoneNumber of a Contact pointer, use -> notation. When allocating dynamic memory, allocate an array of Contacts of the size specified by the user and store the returned pointer in a Contact pointer. To delete the array of Contacts allocated dynamically, you must use the delete [] syntax. The program will compare your program output with what it's expecting the output to be. It considers all cout statements that are used to print something on the screen as part of the output. To make sure your output matches the expected output, comment out all prompts to the user such as cout << "Enter number of people: "; or "Enter name to search for: "; When running the program you can type your input in the input line before executing the program. Make sure to enter only the inputs. The following are sample user inputs and program outputs. 5 indicates 5 names and phone numbers will be entered. After the list gets sorted, a name is entered to search for phone number. In this example, Rob Harman is the searched name. 5 Rob Herman 818-555-1234 Jane Stone 818-555-1235 Jill Mathew 818-555-1236 Steve Mann 818-555-1237 Mary Cramer 818-555-1238 Rob Herman Output: Jane Stone 818-555-1235 Jill Mathew 818-555-1236 Mary Cramer 818-555-1238 Rob Herman 818-555-1234 Steve Mann 818-555-1237 : 818-555-1234 [search result]
Please answer this in C++:
Define a structure called Contact with two c-strings: name and phone_number.
Declare a sort function that takes a Contact pointer and size of Contacts and sorts the Contacts pointed to by the pointer in ascending order based on the Contact names.
Declare a binary search function that takes a Contact pointer, size of Contacts and a c-string for a name and searches for the Contact name given by the c-string. The function must return the index where the contact was found or -1, if not found.
In main, ask the user how many Contacts to create and dynamically allocate memory for as many Contacts as specified by the user. Read names and phone numbers of as many contacts as specified by the user and store them in the Contacts dynamically allocated.
Sort the contacts by name using the sort function and display all contacts: names and phone numbers. Then, read a name from the user and using the binary search function search for it and then print in main the name and phone number of the search contact, if found or that it was not found.
Delete the Contacts dynamically created when done.
Hints: Remember you must use functions for copying and comparing c-strings. See strcpy and strcmp Remember you may use [] to access the contents of a pointer You must use cin.getline() function to read multiword strings Remember to use cin.ignore() to clear the keyboard buffer after a cin and before cin.getline() When accessing name or phoneNumber of a Contact pointer, use -> notation. When allocating dynamic memory, allocate an array of Contacts of the size specified by the user and store the returned pointer in a Contact pointer. To delete the array of Contacts allocated dynamically, you must use the delete [] syntax.
The program will compare your program output with what it's expecting the output to be. It considers all cout statements that are used to print something on the screen as part of the output. To make sure your output matches the expected output, comment out all prompts to the user such as cout << "Enter number of people: "; or "Enter name to search for: ";
When running the program you can type your input in the input line before executing the program. Make sure to enter only the inputs. The following are sample user inputs and program outputs. 5 indicates 5 names and phone numbers will be entered. After the list gets sorted, a name is entered to search for phone number. In this example, Rob Harman is the searched name.
5
Rob Herman
818-555-1234
Jane Stone
818-555-1235
Jill Mathew
818-555-1236
Steve Mann
818-555-1237
Mary Cramer
818-555-1238
Rob Herman
Output:
Jane Stone 818-555-1235
Jill Mathew 818-555-1236
Mary Cramer 818-555-1238
Rob Herman 818-555-1234
Steve Mann 818-555-1237 : 818-555-1234 [search result]
Define a structure called Contact with two c-strings: name and mobile_number....
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images