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().
#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;
}
Comments
Leave a comment