Create a class student. Take data members: Student name, Registration Number and Total Marks. Create a function that will perform task student is pass or not in exam. If the student is Pass then it should display grade according to percentage
#include <iostream>
#include <string>
using namespace std;
class Student{
private:
string name;
string registrationNumber;
int totalMarks;
public:
Student(string name,string registrationNumber,int totalMarks){
this->name=name;
this->registrationNumber=registrationNumber;
this->totalMarks=totalMarks;
}
void checkExam(){
cout<<"The student name: "<<name<<"\n";
cout<<"The registration number: "<<registrationNumber<<"\n";
cout<<"The total marks: "<<totalMarks<<"\n";
string grade="F";
if(totalMarks>=60 && totalMarks<=100){
if(totalMarks>90){
grade="A";
}else if(totalMarks>=80 && totalMarks<90){
grade="B";
}else if(totalMarks>=70 && totalMarks<80){
grade="C";
}else if(totalMarks>=60 && totalMarks<70){
grade="D";
}
cout<<"The grade: "<<grade<<"\n";
cout<<"The student passed the exam.\n";
}else{
cout<<"The student didn't pass the exam.\n";
}
cout<<"\n";
}
};
int main()
{
Student studentPeter("Peter","S1215643",85);
studentPeter.checkExam();
Student studentMary("Mary","S2154651",50);
studentMary.checkExam();
Student studentMike("Mike","S78998465",75);
studentMike.checkExam();
system("pause");
return 0;
}
Comments
Leave a comment