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 Students{
protected:
int rollno;
string name;
public:
Students(int r, string n): rollno(r), name(n){}
};
class Examination:public Students{
protected:
int oop, english, maths;
public:
Examination(int r, string n, int p, int e, int m): oop(p), english(e), maths(m), Students(r, n){}
};
class Results: public Examination{
int total;
public:
Results(int r, string n, int p, int e, int m): Examination(r, n, p, e, m){
total = oop + english + maths;
}
void pass(){
string s = "Pass";
if(total <= 150) s = "Fail";
cout<<s<<endl<<endl;
}
void display(){
cout<<"Roll number: "<<rollno<<endl;
cout<<"Name: "<<name<<endl;
cout<<"OOP: "<<oop<<endl;
cout<<"English: "<<english<<endl;
cout<<"Maths: "<<maths<<endl;
cout<<"Total: "<<total<<endl;
pass();
}
};
int main(){
Results Ramesh(23, "Ramesh", 78, 88, 65);
Results Bravo(22, "Bravo", 43, 54, 30);
Ramesh.display();
Bravo.display();
return 0;
}
Comments
Leave a comment