kilolilo

Untitled

Mar 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class A{
  5. public:
  6. virtual void print(){
  7. cout<<"A"<<endl;
  8. }
  9. };
  10. class B:public A{
  11. public:
  12. void print(){
  13. cout<<"B"<<endl;
  14. }
  15. };
  16. class C:public A{
  17. public:
  18. void print(){
  19. cout<<"C"<<endl;
  20. }
  21. };
  22. int Cpp(){
  23. static int c=0;
  24. c++;
  25. return c;
  26. }
  27. class qwerty{
  28. public:
  29. static int count;
  30. qwerty(){
  31. cout << "Constructor is called" << endl;
  32. qwerty::count++;
  33. }
  34. static int getCount(){
  35. return qwerty::count;
  36. }
  37. };
  38.  
  39. int qwerty::count = 0;
  40.  
  41. int main()
  42. {
  43. A **ptr=new A*[10];
  44. for (int i=0;i<4;i++){
  45. ptr[i]=new A();
  46. }
  47. for (int i=4;i<8;i++){
  48. ptr[i]=new B();
  49. }
  50. for (int i=8;i<10;i++){
  51. ptr[i]=new C();
  52. }
  53. for (int i=0;i<10;i++){
  54. ptr[i]->print();
  55. }
  56. for (int i=0;i<5;i++){
  57. cout<<Cpp()<<endl;
  58. }
  59. qwerty a;
  60. qwerty b;
  61.  
  62. cout << qwerty::getCount() << endl;
  63. }
Add Comment
Please, Sign In to add comment