C++ Multiple Inheritance Example

 

/*WAP according to the specification given below:

a)Create a class Teacher with data member 't_id and subjects' and member function for reading and displaying data members.

b)Create another class Staff with data members 's_id and position', and member function for reading and displaying data members.

c)Derive a class Coordinator from Teacher and Staff and the class must have it's own data member 'department and member function for reading and displaying data memebers)

d)Create a two object of Coordinator class and read and display their details.

*/

#include <iostream>

using namespace std;

class Teacher{

private:

    int t_id;

    string subject;

public:

    void readingTeacherData(){

        cout<<"Enter the teacher\'s id :";

        cin>>t_id;

        cout<<"Enter the subject :";

        cin>>subject;

    }

    void displayTeacherData(){

    cout<<"The teacher with "<<t_id<<" id is the teacher of "<<subject<<" subject."<<endl;

    }

};

class Staff{

private:

    int s_id;

    string position;

public:

    void readingStaffData(){

        cout<<"Enter the staff\'s id :";

        cin>>s_id;

        cout<<"Enter the position :";

        cin>>position;

    }

    void displayStaffData(){

    cout<<"The staff with "<<s_id<<" id is the staff for "<<position<<" position."<<endl;

    }

};

class Coordinator:public Teacher,public Staff{

private:

    string department;

public:

    void getCoordinatorData() {

    cout<<"Enter the Coordinator\'s department :";

    cin>>department;

    }

    void displayCoordinatorData(){

    cout<<"The department of the Coordinator is "<<department<<endl;

    }

};

int main()

{

    Coordinator coordinator;

    coordinator.readingTeacherData();

    coordinator.readingStaffData();

    coordinator.getCoordinatorData();


    coordinator.displayTeacherData();

    coordinator.displayStaffData();

    coordinator.displayCoordinatorData();


    Coordinator coordinator1;

    coordinator1.readingTeacherData();

    coordinator1.readingStaffData();

    coordinator1.getCoordinatorData();


    coordinator1.displayTeacherData();

    coordinator1.displayStaffData();

    coordinator1.displayCoordinatorData();


    return 0;

}


Comments

Popular posts from this blog

Privacy Policy for Constitution of Nepal

Privacy Policy for Noida Metro Fare

Privacy Policy for NepBrain