Write a menu driven C++ program with following option
a. Accept elements of an array
b. Display elements of an array
c. Sort the array using insertion sort method
d. Sort the array using selection sort method
e. Sort the array using bubble sort method
Write C++ functions for all options. The functions should have two parameters name of the array and number of elements in the array.

Source Code

#include<iostream>
using namespace std;
void accept(int Arr[], int s);
void display(int Arr[], int s);
void isort(int Arr[], int s);
void ssort(int Arr[], int s);
void bsort(int Arr[],int s);
int main()
{
	int Arr[100],n,choice;
	cout<<"Enter Size of Array ";
	cin>>n;
	do
	{
		cout<<"\n\nMENU";
		cout<<"\n1. Accept elements of array";
		cout<<"\n2. Display elements of array";
		cout<<"\n3. Sort the array using insertion sort method";
		cout<<"\n4. Sort the array using selection sort method";
		cout<<"\n5. Sort the array using bubble sort method";
		cout<<"\n6. Exit";
		cout<<"\n\nEnter your choice 1-6 :";
		cin>>choice;
		switch(choice)
		{
			case 1:	accept(Arr,n);
				break;
			case 2:	display(Arr,n);
				break;
			case 3:	isort(Arr,n);
				break;
			case 4:	ssort(Arr,n);
				break;
			case 5:	bsort(Arr,n);
				break;
			case 6:	break;
			default:cout<<"\nInvalid choice";
		}
	}while(choice!=6);
	return 0;
}
void accept(int Arr[], int s)
{
	for(int I=0;I<s;I++)
	{
		cout<<"Enter element "<<I+1<<":";
		cin>>Arr[I];
	}
}
void display(int Arr[], int s)
{
	cout<<"The elements of the array are:\n";
	for(int I=0;I<s;I++)
		cout<<Arr[I]<<" ";
}
void isort(int Arr[], int s)
{
	int I,J,Temp;
	for(I=1;I<s;I++)
	{
		Temp=Arr[I];
		J=I-1;
		while((Temp<Arr[J]) && (J>=0))
		{
			Arr[J+1]=Arr[J];
			J--;
		}
		Arr[J+1]=Temp;
	}
}
void ssort(int Arr[], int s)
{
	int I,J,Temp,Small;
	for(I=0;I<s-1;I++)
	{
		Small=I;
		for(J=I+1;J<s;J++) 	//finding the smallest element
		if(Arr[J]<Arr[Small])
			Small=J;
		if(Small!=I)
		{
			Temp=Arr[I]; 		//Swapping
			Arr[I]=Arr[Small];
			Arr[Small]=Temp;
		}
	}
}
void bsort(int Arr[],int s)
{
	int I,J,Temp;
	for(I=0;I<s-1;I++)
	{
		for(J=0;J<(s-1-I);J++)
			if(Arr[J]>Arr[J+1])
			{
				Temp=Arr[J]; 	//swapping
				Arr[J]=Arr[J+1];
				Arr[J+1]=Temp;
			}
	}
}

Output

Enter Size of Array 5

MENU
1. Accept elements of array
2. Display elements of array
3. Sort the array using insertion sort method
4. Sort the array using selection sort method
5. Sort the array using bubble sort method
6. Exit

Enter your choice 1-6 :1
Enter number of elements you want to insert 5
Enter element 1: 13
Enter element 2: 69
Enter element 3: 30
Enter element 4: 51
Enter element 5: 20

MENU
1. Accept elements of array
2. Display elements of array
3. Sort the array using insertion sort method
4. Sort the array using selection sort method
5. Sort the array using bubble sort method
6. Exit

Enter your choice 1-6 :2
The elements of the array are
: 13 69 30 51 20

MENU
1. Accept elements of array
2. Display elements of array
3. Sort the array using insertion sort method
4. Sort the array using selection sort method
5. Sort the array using bubble sort method
6. Exit

Enter your choice 1-6 :3

MENU
1. Accept elements of array
2. Display elements of array
3. Sort the array using insertion sort method
4. Sort the array using selection sort method
5. Sort the array using bubble sort method
6. Exit

Enter your choice 1-6 :2
The elements of the array are:
13 20 30 51 69