Question: USING C++ USING THE PROGRAM BELOW!! Add a menu option to prompt the user for a grade/score to search for in the array. Use a
USING C++ USING THE PROGRAM BELOW!!
Add a menu option to prompt the user for a grade/score to search for in the array.
- Use a binary search to perform the search. Make sure to include the following steps along the way:
i) A sort routine must be called before the binary search. You may use either the selection sort or the bubble sort. However, the sort must be implemented in its own function and not in main.
ii) Next include a function called by main to implement the binary search.
The ordered array produced by the sort should be passed to the search routine which returns the location in the sorted array of the sought value, or -1 if the value is not in the array.
//main library #include
//displaying marks void printMarks(int marks[21], int n){ cout << "The scores entered were: "; for(int i=0; i //displaying less than 70 count int ltseventy(int marks[21], int n){ int count = 0; for(int i=0; i //displaying greater than or equal to 90 count int gtenienty(int marks[21], int n){ int count = 0; for(int i=0; i //print average int avg(int marks[21], int n){ float sum; for(int i=0; i //driver function int main() { //marks store int marks[21]; //count and user choice int n = 0, choice; //prompt cout << "Enter up to 20 test scores between 0 and 100. If fewer than 20 then enter -1 to quit. "; cin >> marks[n]; //read loop while(marks[n] != -1 && n<20){ n++; cout << "Enter another score, or enter -1 to quit: "; cin >> marks[n]; } cout << "All of your scores have been entered."; //working loop while(1){ cout << " What would you like to do? Enter the number from the menu below. 1 - Print a list of all scores entered 2 - Get a report of how many scores less than 70 were entered 3 - Get a report of how many scores greater than or equal to 90 were entered 4 - Get a report of the average passing score 5 - End "; cin >> choice; //display scores if(choice == 1){ printMarks(marks, n); } //less than 70 count else if(choice == 2){ int count = ltseventy(marks, n); cout << " There was "<< count << " score(s) entered that was less than 70.." ; } //more than or eq 90 count else if(choice == 3){ int count = gtenienty(marks, n); cout << " There was "<< count << " score(s) entered that was greater than or equal to 90.."; } //pass average else if(choice == 4){ int avrg = avg(marks, n); cout << " Total average pass mark: " << avrg; } //exit else if(choice == 5) break; //invalid else cout << " Invalid Input"; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
