Answer to Question #185887 in C++ for Laiba

Question #185887

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.


1
Expert's answer
2021-04-27T18:33:35-0400
#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;
}

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