Need help with Programming C++ and menu choices (menu-driven program)

Nov 30th, 2015
Price: $50 USD

Question description

In this assignment you will create a program that allows the user to choose between the following menu choices (menu-driven program):

1. Linear Search

2. Binary Search

3. Bubble Sort

4. Selection Sort

5. Quit

Keep running the program till the user chooses to Quit.

Your program should have the following parts:

Searching Algorithms (Linear and Binary Search) You are the owner of a book store. You have the following information available in your stock (information is stored in the form of parallel arrays):

string bookTitle[] = {“Starting out with C++”, “Java Programming”, “Software Structures”, “Design and Analysis of Algorithms”, “Computer Graphics”, “Artificial Intelligence: A Modern Approach”, “Probability and Statistics”, “Cognitive Science”, “Modern Information Retrieval”, “Speech and Language Processing”};

int bookID[] = {1101, 1211, 1333, 1456, 1567, 1642, 1699, 1755, 1800, 1999};

double bookPrice[] = {112.32, 73.25, 54.00, 67.32, 135.00, 173.22, 120.00, 42.25, 32.11, 123.75};

First display() the above information to the user in a tabular format. Your program should then accept the.

book ID and the number of books the user wishes to purchase. Based on the book ID provided by the user, display the following information (if the ID is found):

 - Book ID

- Book Title

 - Number of books bought

 - Total cost of the purchase If the book ID is not found, display a message saying so. The book ID needs to be searched based on linearSearch() or binarySearch() (based on user choice from the menu).

 Sorting Algorithms (Bubble and Selection Sort)

Your program should generate 1000 random numbers in the range of 1 to 500 and store them in an array. Use bubbleSort() or selectionSort() (based on the menu choice) to sort the array of numbers. Display both the unsorted and the sorted array.

A sample output has been provided to you at the end of this document.

Instructions: Please make sure your code has following functions:

• display(): To display the contents of parallel array in a tabular format

• linearSearch(): To apply the linear search algorithm to search for the book ID

• binarySearch(): To apply the binary search algorithm to search for the book ID

• bubbleSort(): To apply the bubble sort algorithm to sort the elements of an unsorted array

• selectionSort(): To apply the selection sort algorithm to sort the elements of an unsorted array

You can use additional functions (optional) for other operations. Make sure your program runs till the user decides to quit the program. Your program should validate (input validation) the menu choice entered by the user. A bonus programming part has been provided below for extra points.

Bonus Part (Optional): 25 points

 We want to test the efficiency of our searching and sorting algorithms. To test the efficiency I want you to calculate and display the execution (elapsed) time (in seconds) required for each of the Searching and Sorting techniques. Execution time is calculated from the start of a function call to the end of the function. Look up online resources on how to calculate elapsed time and using the system time library.

Can you tell which searching technique is better/faster (linear search vs. binary search) and which sorting technique is better/faster (bubble sort vs. selection sort)?

Sample Output:


1. Linear Search

2. Binary Search

3. Bubble Sort

4. Selection Sort

5. Quit

Please enter your choice: 1

 **** LINEAR SEARCH *****






 ID Title Cost Starting out with C++ $112.32 Java Programming $73.25 ... ... ... ...

 Please enter the book ID you wish to purchase: 1101 How many copies you wish to purchase: 2

Book ID: 1101 Book Title: Starting out with C++ Number of books bought: 2 Total Cost: $ 224.64

The output will look the same for Binary Search too.


1. Linear Search

2. Binary Search

3. Bubble Sort

4. Selection Sort

5. Quit

Please enter your choice: 3

**** BUBBLE SORT ****

Unsorted array:

23 45 321 1 87 122 500 222 45 455 321 387 .............

Sorted array:

1 23 45 45 87 122 222 321 321 387 455 500 .............

The output will look the same for Selection Sort too.

Tutor Answer

(Top Tutor) Daniel C.
School: UIUC

Studypool has helped 1,244,100 students

Review from our student for this Answer

Nov 30th, 2015
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1822 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors