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: You may need to include cstring for manipulating cstrings 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 Use cin.getline() function to read multiword strings Remember to use cin.ignore() to clear the keyboard buffer before using cin.getline() When accessing name or phone_number 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 following is sample interaction between the user and the program: Enter number of contacts to create: 5 Enter name: Rob Herman Enter phone number: 818-555-1234 Enter name: Jane Stone Enter phone number: 818-555-1235 Enter name: Jill Mathew Enter phone number: 818-555-1236 Enter name: Steve Mann Enter phone number: 818-555-1237 Enter name: Mary Cramer Enter phone number: 818-555-1238 Sorted list: 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 Enter a name to search for: Rob Herman Rob Herman 818-555-1234 Press any key to continue.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter13: Structures
Section13.5: Dynamic Data Structure Allocation
Problem 2E
icon
Related questions
Question

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: You may need to include cstring for manipulating cstrings 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 Use cin.getline() function to read multiword strings Remember to use cin.ignore() to clear the keyboard buffer before using cin.getline() When accessing name or phone_number 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 following is sample interaction between the user and the program:

Enter number of contacts to create: 5

Enter name: Rob Herman

Enter phone number: 818-555-1234

Enter name: Jane Stone

Enter phone number: 818-555-1235

Enter name: Jill Mathew

Enter phone number: 818-555-1236

Enter name: Steve Mann

Enter phone number: 818-555-1237

Enter name: Mary Cramer

Enter phone number: 818-555-1238

Sorted list:

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

Enter a name to search for: Rob Herman

Rob Herman 818-555-1234

Press any key to continue.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr