Inheritance-Multiple Inheritance example

 #include <iostream>

using namespace std;

class Student_name{

    protected:

    string name;

    public:

    void set_name(string n)

    {

        name=n;

    }

};

class Student_roll_number{

    protected:

    int roll_number;

    public:

    void set_roll_number(int r)

    {

        roll_number=r;

    }

};

class Student_average:public Student_name,public Student_roll_number{

    protected:

    float mean;

    public:

    void average(int,int,int);

    void print(void);

    

};

void Student_average::average(int math,int phy,int chem)

{

    float a=float(math+phy+chem)/3;

    mean=a;

}

void Student_average:: print()

{

    cout<<"The name is "<<name<<endl;

    cout<<"The roll number is "<<roll_number<<endl;

    cout<<"The average is "<<mean<<endl;

    cout<<"The percentage is "<<mean<<"%"<<endl;

}

int main() {

Student_average a1;

a1.set_name("Peeyush");

a1.set_roll_number(69);

a1.average(90,96,94);

a1.print();

return 0;

}


Comments

Popular posts from this blog

Hackerrank-Accessing Inherited Functions problem-Inheritance

Inheritance- Code with Harry-Lecture 41 solution (Multiple inheritance)