Write a C++ program to announce student’s result. Demonstrate this scenario through three classes: Students, Results and Examination. The Student class has data members {1st is roll number and 2nd is name}. Create the class Examination by inheriting the Student class. The Exam class input three subjects Marks out of 100 (OOP, English,Maths). Derive the child class Result from the Exam class and it has its own fields such as total Marks. Based on the total marks students must be declared pass or Fail if the total marks achieved by students equal or greater than 150/300 then only he be declared as Pass. Write an interactive program to model this relationship. (
#include <iostream>
using namespace std;
//class student
class Student{
//data members
public:
string name;
string rollNo;
//methods
void getStudentdetails(){
cout<<"\nThe student's details";
cout<<"\nEnter student's name: ";
cin>>name;
cout<<"\nEnter student's rollno: ";
cin>>rollNo;
}
};
//class examination
class Examination: public Student{
//data members
public:
int oop;
int english;
int math;
//methods
void getMarks(){
cout<<"The student's marks";
cout<<"\nEnter OOP marks: ";
cin>>oop;
cout<<"Enter English marks: ";
cin>>english;
cout<<"Enter Math marks: ";
cin>>math;
if (oop>100||english>100||math>100){
cout<<"\nInvalid marks";
}
}
};
// class result
class Result: public Examination{
private:
int total;
public:
int getTotal(){
return (oop+english+math);
}
};
int main()
{
Result res;
// get the details of the Student
res.getStudentdetails();
//input marks for the three subjects
res.getMarks();
//display the total marks
cout<<"Total marks is "<<res.getTotal();
//pass or fail
if (res.getTotal()>=(150/300)){
cout<<"\nPass";
}
else{
cout<<"\nFail";
}
return 0;
}
Comments
Leave a comment