Object Oriented Programming - Old Questions

2. Differentiate between single inheritance and multiple inheritance? Imagine a college hires some lectures. Some lectures are paid in period basic, while others are paid in month basic. Create a class called lecture that stores ID and name of lectures. From this class derive two classes: part time, which adds payperhr(type float): and full time, which adds paypermonth(type float). Each of these three classes should have a readdata() function to get its data from user at the key board and printdata() function to display the data.

Write a main() program to test the Full time and Part time classes by creating instance of them asking the user to fill their data with readdata () and display the data with printdata().

10 marks | Asked in 2074

Program:

#include <iostream>

using namespace std;

class Lecture

{

    public:

    int id;

    string name;

    void readdata()

    {

        cout<<"Enter the Id of lecture:";

        cin>>id;

        cout<<"Enter the name of leture:";

        cin>>name;

    }

    void printdata()

    {

        cout<<"Id of lecture : "<<id<<endl;

        cout<<"Name of lecture: "<<name<<endl;

    }

    

};

class PartTime:public Lecture

{

    public:

    float payperhr;

    void readdatapt()

    {

        cout<<"Enter the salary paid per hour: ";

        cin>>payperhr;

        

    }

    void printdatapt()

    {

        cout<<"Salary paid per hour:"<<payperhr<<endl;

    }

};

class FullTime:public Lecture

{

    public:

    float paypermonth;

    void readdataft()

    {

        cout<<"Enter the salary paid per month: ";

        cin>>paypermonth;

        

    }

    void printdataft()

    {

        cout<<"Salary paid per month:"<<paypermonth<<endl;

    }

};


int main()

{

    PartTime p1;

    FullTime f1;

    

    cout<<"***Part Time***"<<endl;

    p1.readdata();

    p1.readdatapt();

    cout<<"***Displaying Data***"<<endl;

    p1.printdata();

    p1.printdatapt();

    

    cout<<"***Full Time***"<<endl;

    f1.readdata();

    f1.readdataft();

    cout<<"***Displaying Data***"<<endl;

    f1.printdata();

    f1.printdataft();

    

    return 0;

}