Question: In C++ code, implement the following 7 functions for the main function listed below: 1. void fill_array(int arr[], int size); // pre-condition: The arr has

In C++ code, implement the following 7 functions for the main function listed below:

1. void fill_array(int arr[], int size); // pre-condition: The arr has actual size that is greater than or equal to size // post-condition: arr[0], ..., arr[size-1] is filled from keyboard

2.void print_array(int arr[], int size); // pre-condition: The arr has actual size that is greater than or equal to size // post-condition: arr[0], ..., arr[size-1] is printed to screen with 5 elements per line

3.int linear_search(int arr[], int size, int key); // pre-condition: arr has given size // post-condition: The index of first occurrence of key in arr is returned. If the key cannot be found in arr, -1 is returned

4.void select_sort(int arr[], int size); // pre-condition: arr has given size // post-condition: the elements in arr are rearranged from least to largest

5.void insert_sort(int arr[], int size); Of course, a menu function is needed. The main function will look like following: // pre-condition: arr has given size // post-condition: the elements in arr are rearranged from least to largest

6.void bubble_sort(int arr[], int size); // pre-condition: arr has given size // post-condition: the elements in arr are rearranged from least to largest

7. A menu function

Main Function:

int main() { int choice; int a[9]; do{ menu(); cout << "Enter your choice: "; cin >> choice; switch(choice) { case 1: { fill_array(a, 9); cout << "Enter the key you want to search: "; int key; cin >> key; int index = linear_search(a, 9, key); if(index == -1) cout << "The key " << key << " is not in array "; else cout << "The key " << key << " is #" << (index + 1) << " element in array "; break; } case 2: { fill_array(a, 9); select_sort(a, 9); cout << "After sort, the array is: "; print_array(a, 9); break; } case 3: { fill_array(a, 9); insert_sort(a, 9); cout << "After sort, the array is: "; print_array(a, 9); break; } case 4: { fill_array(a, 9); bubble_sort(a, 9); cout << "After sort, the array is: "; print_array(a, 9); break; } case 5: { cout << "Thank you for using the array functions "; break; } default: { cout << "Wrong choice. Please choose from menu: "; break; } } }while(choice != 5); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!