Answer to Question #262533 in C++ for Vava

Question #262533

Write a C++ FUNCTION named getData()that prompts the user to enter results for a



number of students passed to it using the following data structure: (5 MARKS)



struct result



{



string name;



int matNum;



double mark;



};

1
Expert's answer
2021-11-07T17:18:27-0500
#include <iostream>


using namespace std;


struct result
{
    string name;
    int matNum;
    double mark;


};


void getData(struct result r[],int n){
    
    for(int i=0;i<n;i++){
        cout<<"\nEnter details for student "<<(i+1)<<":\n";
        cout<<"\nName: ";
        cin>>r[i].name;
        cout<<"\nMatnum: ";
        cin>>r[i].matNum;
        cout<<"\nMark: ";
        cin>>r[i].mark;
    }
}


int main()
{
    int n;
    cout<<"\nEnter number of students: ";
    cin>>n;
    struct result r[n];
    getData(r,n);


    cout<<"\nDetails for all students are as follows:\n";
    for(int i=0;i<n;i++){
        cout<<"\nDetails for student "<<(i+1)<<": \n";
        cout<<"\nName: "<<r[i].name;
        cout<<"\nMatnum: "<<r[i].matNum;
        cout<<"\nMark: "<<r[i].mark;
    }
    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