Answer to Question #236964 in C++ for xyz

Question #236964

 Create class PI with data members roll and name. Create another class AI with data members sub1 and sub2. Derive a class Student from PI and AI classes. Student class has one data member total to calculate the sum of sub1 and sub2.


1
Expert's answer
2021-09-14T18:21:08-0400
#include <iostream>


using namespace std;


class PI{
    protected:
        int roll;
        string name;
};


class AI{
    protected:
        int sub1;
        int sub2;
};


class Student: public PI, public AI{
    private:
        int total;
        
    public:
    void displayTotal(){
        cout<<"\nEnter sub 1: ";
        cin>>sub1;
        cout<<"\nEnter sub 2: ";
        cin>>sub2;
        total=sub1+sub2;
        cout<<"\nTotal = "<<total;
        
    }
};


int main()
{
    Student s;
    s.displayTotal();


    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