Answer to Question #182753 in C++ for Garima

Question #182753

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


1
Expert's answer
2021-04-18T11:22:53-0400


#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;
}

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