Write a Menu driven Program which include these operations like Creating an array, insertion, deletion and fetching all the elements from an array?
#include <iostream>
using namespace std;
void insert(int arr[],int n){
int index; int number;
cout<<"\nEnter index: ";
cin>>index;
cout<<"\nEnter number to insert: ";
cin>>number;
arr[index]=number;
}
void delete1(int arr[],int n){
int index; int number;
cout<<"\nEnter index of the number to delete: ";
cin>>index;
arr[index]=0;
}
void fetch(int arr[],int n){
for(int i=0;i<n;i++){
cout<<arr[i]<<endl;
}
cout<<endl;
}
int main()
{
//Create an array
int n;
cout<<"\nEnter number of elements in the array: ";
cin>>n;
int arr[n];
int c;
cout<<"\nEnter "<<n<<" elements of the array:\n";
for(int i=0;i<n;i++){
cin>>arr[i];
}
cout<<"\nChoose an operation:\n1. Insertion\n2. Deletion\n3. Fetching all the elements\n ";
cin>>c;
if (c==1)
insert(arr,n);
else if(c==2)
delete1(arr,n);
else if(c==3)
fetch(arr,n);
return 0;
}
Comments
Leave a comment