Answer to Question #234299 in C++ for harsha

Question #234299

Write a Menu driven Program which include these operations like Creating an array, insertion, deletion and fetching all the elements from an array?


1
Expert's answer
2021-09-07T16:30:58-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS