Advertisement
Shishu

multilevel inheritance with protector

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