Advertisement
Shishu

multilevel inheritance without protector

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