Multi-level inheritance in OOP

  1. * /program to illutrate multilevel inheritance./ *   
  2. #include < iostream > using namespace std;  
  3. class student  
  4. {  
  5.     protectedint roll;  
  6.     publicvoid getdata(int);  
  7.     void putdata(void);  
  8. };  
  9. void student::getdata(int a)  
  10. {  
  11.     roll = a;  
  12. }  
  13. void student::putdata()  
  14. {  
  15.     cout << "\nrollno:" << roll;  
  16. }  
  17. class test: public student  
  18. {  
  19.     protectedfloat sub1;  
  20.     float sub2;  
  21.     publicvoid get(floatfloat);  
  22.     void put(void);  
  23. };  
  24. void test::get(float x, float y)  
  25. {  
  26.     sub1 = x;  
  27.     sub2 = y;  
  28. }  
  29. void test::put()  
  30. {  
  31.     cout << "\n'c' marks:" << sub1;  
  32.     cout << "\n'c++' marks:" << sub2;  
  33. }  
  34. class result: public test  
  35. {  
  36.     float total;  
  37.     publicvoid display(void);  
  38. };  
  39. void result::display(void)  
  40. {  
  41.     total = sub1 + sub2;  
  42.     putdata();  
  43.     put();  
  44.     cout << "\ntotal=" << total;  
  45. }  
  46. int main()  
  47. {  
  48.     result stu;  
  49.     stu.getdata(150);  
  50.     stu.get(78.0, 65.8);  
  51.     stu.display();  
  52.     return 0;  
  53. }