Answer to Question #245613 in C++ for kinza

Question #245613
Write a program to perform list operations using a menu

based program. Try to take 2 arrays of type int and char.

Int should store roll no's and char should store grades.



List Menu



1. Insert



2. Delete



3. Update

4. Search
1
Expert's answer
2021-10-03T04:01:32-0400


#include <iostream>


using namespace std;
void Delete(int arr[],char arr2[],int size){
    int num;
    cout<<"\nEnter roll number to Delete: ";
    cin>>num;
    for(int i=0;i<size;i++){
        if (arr[i]==num){
            arr[i]==0;
            cout<<"\nDeletion successful";
            break;
        }
    }
}
void Update(int arr[],char arr2[],int size){
    int num;
    cout<<"\nEnter roll number to update: ";
    cin>>num;
    char new_grade;
    cout<<"\nEnter new grade for student with roll number "<<num<<" : ";
    cin>>new_grade;
    for(int i=0;i<size;i++){
        if (arr[i]==num){
            arr2[i]==new_grade;
            cout<<"\nUpdate successful";
            break;
        }
    }
    
}
void Search(int arr[],char arr2[],int size,int n){
    for(int i=0;i<size;i++){
        if(n==arr[i]){
            cout<<"\nRoll number "<<arr[i]<<" is present and has a grade of "<<arr2[i];
            break;
        }
        else{
            cout<<"\nThe roll number is not present";
        }
    }
    
}
int main()
{
    int n;
    cout<<"\nEnter number of student:";
    cin>>n;
    int roll_no[n];
    char grades[n];
    int i=0;
    while(1){
        cout<<"\nChoose an operation to perform:\n1. Insert\n2. Delete\n3. Update\n4. Search\n5. Exit\n";
        int c;
        cin>>c;
        if (c==1){
            cout<<"\nEnter roll number: ";
            cin>>roll_no[i];
            cout<<"\nEnter grade: ";
            cin>>grades[i];
        }
        else if (c==2){
            Delete(roll_no,grades,n);
        }
        else if (c==3){
            Update(roll_no,grades,n);
        }
        else if (c==4){
            int num;
            cout<<"\nEnter roll number to search: ";
            cin>>num;
            Search(roll_no,grades,n,num);
        }
        else if (c==5){
            break;
        }
        
        i++;
    }


    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