KeiroKamioka

How to show ABC

Feb 17th, 2021
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class a
  7. {
  8. public:
  9.     // Your code starts here
  10.  
  11.     virtual string m1() { return "A"; }
  12.  
  13.     //virtual string m1() { return a::showA();; }
  14.     //virtual string showA() { return "A";  }
  15.  
  16.     // Your code ends here
  17.     virtual string m2() { return "A"; }
  18.     virtual string m3() { return "A"; }
  19. };
  20.  
  21. class b : public a
  22. {
  23. public:
  24.     virtual string m1() { return "B"; }
  25.     // Your code starts here
  26.     virtual string m2() { return "B"; }
  27.     // Your code ends here
  28.     virtual string m3() { return "B"; }
  29. };
  30.  
  31. class c : public b
  32. {
  33. public:
  34.     virtual string m1() { return "B"; }
  35.     // Your code starts here
  36.     virtual string m2()
  37.     // Your code ends here
  38.     {
  39.         return b::m2();
  40.     }
  41.     // Your code starts here
  42.     virtual string m3() { return "C"; }
  43.     // Your code ends here
  44. };
  45.  
  46. int main()
  47. {
  48.     a* a = new c();
  49.  
  50.     cout << a->m1() << endl; // Should print "A"
  51.     cout << a->m2() << endl; // Should print "B"
  52.     cout << a->m3() << endl; // Should print "C"
  53. }
Advertisement
Add Comment
Please, Sign In to add comment