Question: #include using namespace std; void fill _ array ( int arr [ ] , int size ) { cout < < Enter < <

#include using namespace std; void fill_array(int arr[], int size){ cout << "Enter "<< size <<" elements:
"; for (int i =0; i < size; ++i){ cin >> arr[i]; }} void print_array(int arr[], int size){ for (int i =0; i < size; ++i){ cout << arr[i]<<""; if ((i +1)%5==0){ cout << endl; }} if (size %5!=0){ cout << endl; // New line at the end if not printed yet }} int linear_search(int arr[], int size, int key){ for (int i =0; i < size; ++i){ if (arr[i]== key){ return i; // Return index of the first occurrence }} return -1; // If not found } void select_sort(int arr[], int size){ for (int i =0; i < size -1; ++i){ int minIndex = i; for (int j = i +1; j < size; ++j){ if (arr[j]< arr[minIndex]){ minIndex = j; }} if (minIndex != i){ swap(arr[i], arr[minIndex]); // Swap the found minimum element with the first element }}} void insert_sort(int arr[], int size){ for (int i =1; i < size; ++i){ int key = arr[i]; int j = i -1; while (j >=0 && arr[j]> key){ arr[j +1]= arr[j]; j = j -1; } arr[j +1]= key; }} void bubble_sort(int arr[], int size){ for (int i =0; i < size -1; ++i){ for (int j =0; j < size - i -1; ++j){ if (arr[j]> arr[j +1]){ swap(arr[j], arr[j +1]); // Swap if the element found is greater }}}} void menu(){ cout << "Menu:
"; cout <<"1. Linear Search
"; cout <<"2. Selection Sort
"; cout <<"3. Insertion Sort
"; cout <<"4. Bubble Sort
"; cout <<"5. Exit
"; } 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 Programming Questions!