Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. using namespace std;
  5.  
  6. class Square
  7. {
  8. protected:
  9. int length;
  10. public:
  11. Square(int a)
  12. {
  13. length = a;
  14. }
  15. void draw()
  16. {
  17. for(int i = 0; i < length; i++)
  18. {
  19. drawline();
  20. }
  21. cout << endl;
  22. }
  23.  
  24. void drawline()
  25. {
  26. for(int i = 0; i < length; i++)
  27. {
  28. cout << "*";
  29. }
  30. cout << endl;
  31. }
  32. };
  33.  
  34. class Triangle : public Square
  35. {
  36. int line;
  37. public:
  38. Triangle(int a) : Square(a)
  39. {
  40. line = a;
  41. }
  42. void draw()
  43. {
  44. for(int i = 0; i < line; i++)
  45. {
  46. drawline();
  47. length -= 1;
  48. }
  49. cout << endl;
  50. }
  51. };
  52.  
  53. class Rectangle : public Square
  54. {
  55. int width;
  56. public:
  57. Rectangle(int a, int b) : Square(a)
  58. {
  59. width = b;
  60. }
  61. void draw()
  62. {
  63. for(int i = 0; i < width; i++)
  64. {
  65. drawline();
  66. }
  67. cout << endl;
  68. }
  69. };
  70.  
  71. int main()
  72. {
  73. Square A(5);
  74. Triangle B(4);
  75. Rectangle C(4,7);
  76.  
  77. A.draw();
  78. B.draw();
  79. C.draw();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement