fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. private:
  7. int a,b;
  8. public:
  9. A(int a, int b)
  10. {
  11. this->a=a;
  12. this->b=b;
  13. }
  14. void setVar(int a,int b)
  15. {
  16. this->a=a;
  17. this->b=b;
  18. }
  19. int getA()
  20. {
  21. return a;
  22. }
  23. int getB()
  24. {
  25. return b;
  26. }
  27. };
  28. class B
  29. {
  30. private:
  31. string s1;
  32. protected:
  33. double d;
  34. public:
  35. B(string s1,double d)
  36. {
  37. this->s1=s1;
  38. this->d=d;
  39. }
  40. void setVar2(string s1,double d)
  41. {
  42. this->s1=s1;
  43. this->d=d;
  44. }
  45. string getS1()
  46. {
  47. return s1;
  48. }
  49. double getD()
  50. {
  51. return d;
  52. }
  53. };
  54.  
  55. class C: private A, protected B
  56. {
  57. public:
  58. string s2;
  59. C(int a, int b,string s1, double d,string s2): A(a,b),B(s1,d)
  60. {
  61. this->s2=s2;
  62. }
  63. void setDelVar(int a,int b,string s1,double d)
  64. {
  65. setVar(a,b);
  66. setVar2(s1,d);
  67. }
  68. int getDelA()
  69. {
  70. return getA();
  71. }
  72. int getDelB()
  73. {
  74. return getB();
  75. }
  76. string getDelS1()
  77. {
  78. return getS1();
  79. }
  80. double getDelD()
  81. {
  82. return getD();
  83. }
  84. string getS2()
  85. {
  86. return s2;
  87. }
  88.  
  89. };
  90.  
  91. class D: public C
  92. {
  93. public:
  94. D(int a,int b,string s1,double d, string s2): C(a,b,s1,d,s2)
  95. {}
  96. };
  97.  
  98. void display(D d)
  99. {
  100. cout<<d.getDelA()<<" "<<d.getDelB()<<" "<<d.getDelS1()<<" "<<d.getDelD()<<" "<<d.getS2()<<endl;
  101. }
  102.  
  103. int main()
  104. {
  105.  
  106. D d(5,6,"s",7.8,"ss");
  107. display(d);
  108. }
  109.  
  110.  
  111.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
5 6 s 7.8 ss