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 than it should display grade according to percentage.
#include <iostream>
#include <string>
using namespace std;
class Student {
public:
Student(string name, int regNumber, int marks=0);
string GetName() const {
return name;
}
int GetRegistrationNumber() const {
return registrationNumber;
}
int GetTotalMarks() const {
return totalMarks;
}
void SetTotalMarks(int marks) {
totalMarks = marks;
}
void PassExam() const;
private:
string name;
int registrationNumber;
int totalMarks;
};
Student::Student(string name, int regNumber, int marks) :
name(name), registrationNumber(regNumber), totalMarks(marks)
{}
void Student::PassExam() const
{
cout << "The student " << name;
if (totalMarks < 50) {
cout << " has not pass the Exam";
}
else {
cout << " has pass the Exam with grade ";
string grade;
if (totalMarks > 90)
grade = "A";
else if (totalMarks > 80)
grade = "B";
else if (totalMarks > 70)
grade = "C";
else if (totalMarks > 60)
grade = "D";
else
grade = "E";
cout << grade;
}
cout << endl;
}
int main()
{
Student st1("Mary Smith", 12345, 45);
Student st2("Bob Brown", 45678, 80);
st1.PassExam();
st2.PassExam();
st1.SetTotalMarks(94);
st1.PassExam();
}
Comments
Leave a comment