Advertisement
Tusohian

Inheritance [Multiple & Multi Level]

Aug 4th, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class people
  5. {
  6.     int age ;
  7.  
  8. public:
  9.  
  10.     people(int x)
  11.     {
  12.         age=x;
  13.     }
  14.  
  15.     display()
  16.     {
  17.         cout<<"Age is: "<<age<<endl;
  18.     }
  19.  
  20. };
  21.  
  22. class student : public people
  23. {
  24.     float cgpa;
  25.  
  26. public:
  27.  
  28.     student(int x, float b):people(x)
  29.     {
  30.         cgpa=b;
  31.     }
  32.  
  33.     display()
  34.     {
  35.         people::display();
  36.         cout<<"CGPA is: "<<cgpa<<endl;
  37.     }
  38.  
  39. };
  40.  
  41.  
  42. class employee : public people
  43. {
  44.  
  45. protected:
  46.  
  47.     int salary;
  48.  
  49. public:
  50.  
  51.     employee (int x, int s):people(x)
  52.     {
  53.         salary=s;
  54.     }
  55.  
  56.     display()
  57.     {
  58.         people::display();
  59.         cout<<"Salary is: "<<salary<<endl;
  60.     }
  61.  
  62. };
  63.  
  64.  
  65. class embastudent :  public student,  public employee
  66. {
  67. public:
  68.  
  69.     embastudent(int x, float b, int s) : student(x,b), employee(x,s){}
  70.  
  71.     display()
  72.     {
  73.         student::display();
  74.         /*employee::display();*/
  75.         cout<<"Salary is: "<<salary<<endl;
  76.      }
  77.  
  78. };
  79.  
  80. int main()
  81. {
  82.     embastudent es1(25, 4.0, 20000);
  83.     es1.display();
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement