Write a C++ program using concept of hierarchical inheritance.


SUBMITTED BY: Nrupeshsinh

DATE: June 26, 2016, 4:17 a.m.

FORMAT: C++

SIZE: 471 Bytes

HITS: 517

  1. # include<iostream.h>
  2. # include<conio.h>
  3. class A
  4. {
  5. public:
  6. int a,b;
  7. void show()
  8. {
  9. cout<<"Enter value :";
  10. cin>>a;
  11. cout<<"Enter value :";
  12. cin>>b;
  13. }
  14. };
  15. class B :public A
  16. {
  17. public:
  18. void show1()
  19. {
  20. cout<<"SUM="<<a+b<<endl;
  21. }
  22. };
  23. class C : public A
  24. {
  25. public:
  26. void show2()
  27. {
  28. cout<<"SUB="<<a-b<<endl;
  29. }
  30. };
  31. void main()
  32. {
  33. clrscr();
  34. B obj;
  35. C obj1;
  36. obj.show();
  37. obj.show1();
  38. obj1.show2();
  39. getch();
  40. }

comments powered by Disqus