Answer to Question #241689 in C++ for Jack

Question #241689

Create the classes as per the hierarchy given below. The data members are mentioned along with class name. Include parameterized constructor in all the classes. Input data at run-time for a student, calculate the total marks and percentage and display them.


Student: Name, Roll Number

|

V

Marks: marks in 5 subjects

|

V

Result: total marks, percentage


1
Expert's answer
2021-09-24T18:57:13-0400
#include <iostream>


using namespace std;
class Student{
    private:
        string Name;
        int Roll_Number
    public:
        void getData1(){
            cout<<"\nEnter name: ";
            cin>>Name;
            cout<<"\nEnter Roll Number: ";
            cin>>Roll_Number;
        }
        void disp1(){
            cout<<"\nName: "<<Name;
            cout<<"\nRoll Number: "<<Roll_Number;
        }
};


class Marks: public Student{
    private:
        int marks[5];
    public:
        void getData(){
            cout<<"\nEnter marks in 5 subjects: ";
            for(int i=0;i<5;i++){
                cin>>marks[i];
            }
            int sum=0;
            for(int i=0;i<5;i++){
                sum+=i;
            }
            double perc=(sum/500)*100;
            cout<<"\nTotal Marks: "<<sum;
            cout<<"\nPercentage: "<<perc;
        }
};


class Result: public Marks{
    private:
        int total_marks;
        int percentage;
    
};


int main()
{
    Result r;
    r.disp1();
    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

Jack
03.10.21, 10:28

Thanks a lot AssignmentExpert

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS