Answer to Question #230071 in C++ for Arup

Question #230071

WAP to find name and mark of a student who scored heist in a class by considering minimum five student by using class and object (array of object) by considering suitable data member and fun().


1
Expert's answer
2021-08-28T01:35:34-0400


#include <iostream>


using namespace std;


class Student{
    private:
        int marks;
        string name;
    
    public:
        void setMarks(int m){
            marks=m;
        }
        int getMarks(){
            return marks;
        }
        void setName(string n){
            name=n;
        }
        string getName(){
            return name;
        }
    
};
int main()
{
    Student s[5];
    string names[5];
    int marks[5];
    for(int i=0;i<5;i++){
        cout<<"\nEnter details for student "<<i+1<<"\n";
        cout<<"\nEnter name: ";
        cin>>names[i];
        s[i].setName(names[i]);
        cout<<"\nEnter marks: ";
        cin>>marks[i];
        s[i].setMarks(marks[i]);
    }
    int max=marks[0];
    string max_name=names[0];
    for(int i=0;i<5;i++){
        if(marks[i]>max){
            max=marks[i];
            max_name=names[i];
        }
    }
    cout<<"\nThe student with the highest marks has the following details:\n";
    cout<<"\nName: "<<max_name;
    cout<<"\nMarks: "<<max;
    
    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