C++ Class Inheritance Multiple levels of inheritance

Description

C++ Class Inheritance Multiple levels of inheritance

#include <iostream>
using namespace std;
const int LEN = 80;                //maximum length of names
class Employee//from   w  w  w  .  ja v  a2s  .  c  o m
{
   private:
   char name[LEN];              //Employee name
   unsigned long number;        //Employee number
   public:
   void getdata()
   {
      cout << "\n   Enter last name: "; cin >> name;
      cout << "   Enter number: ";      cin >> number;
   }
   void putdata() const
   {
      cout << "\n   Name: " << name;
      cout << "\n   Number: " << number;
   }
};
class Manager : public Employee    //Manager class
{
   private:
   char title[LEN];             //"vice-president" etc.
   double dues;                 //golf club dues
   public:
   void getdata()
   {
      Employee::getdata();
      cout << "   Enter Name:  ";          cin >> title;
      cout << "   Enter golf club dues: "; cin >> dues;
   }
   void putdata() const
   {
      Employee::putdata();
      cout << "\n   Name:  " << title;
      cout << "\n   Golf club dues: " << dues;
   }
};
class Scientist : public Employee  //Scientist class
{
   private:
   int pubs;                    //number of publications
   public:
   void getdata()
   {
      Employee::getdata();
      cout << "   Enter number of pubs: "; cin >> pubs;
   }
   void putdata() const
   {
      Employee::putdata();
      cout << "\n   Number of publications: " << pubs;
   }
};
class Programmer : public Employee    //Programmer class
{
};
class foreman : public Programmer     //foreman class
{
    private:
        float quotas;  //percent of quotas met successfully
    public:
        void getdata()
        {
           Programmer::getdata();
           cout << "   Enter quotas: "; cin >> quotas;
        }
        void putdata() const
        {
           Programmer::putdata();
           cout << "\n   Quotas: " << quotas;
        }
};
int main()
{
    Programmer l1;
    foreman f1;
    cout << endl;
    cout << "\nEnter data for Programmer 1";
    l1.getdata();
    cout << "\nEnter data for foreman 1";
    f1.getdata();
    cout << endl;
    cout << "\nData on Programmer 1";
    l1.putdata();
    cout << "\nData on foreman 1";
    f1.putdata();
    cout << endl;
    return 0;
}



PreviousNext

Related