Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <string>
  5. using namespace std;
  6.  
  7. class Shape
  8. {
  9. protected:
  10. string name_;
  11. public:
  12. Shape(string name)
  13. {
  14. name_ = name;
  15. }
  16. ~Shape() {}
  17.  
  18. string getName()
  19. {
  20. return name_;
  21. }
  22.  
  23. virtual double area() = 0;
  24. };
  25.  
  26.  
  27. class ShapeContainer
  28. {
  29. public:
  30. vector <Shape*> Lista;
  31.  
  32. ShapeContainer() {}
  33.  
  34. void add(Shape* ptr)
  35. {
  36. Lista.push_back(ptr);
  37. }
  38. void displayAll() const
  39. {
  40. for (Shape* f : Lista)
  41. {
  42. cout<< f->getName() << " " << f->area() << endl;
  43. }
  44. }
  45. };
  46.  
  47. class Rectangle : public Shape
  48. {
  49. protected:
  50. double width_;
  51. double height_;
  52. public:
  53. Rectangle(string name, double width, double height)
  54. : Shape(name)
  55. {
  56. width_ = width;
  57. height_ = height;
  58.  
  59. }
  60. ~Rectangle() {}
  61. double area()
  62. {
  63. return width_ * height_;
  64. }
  65. double permiter()
  66. {
  67. return 2 * width_ + 2 * height_;
  68. }
  69. };
  70.  
  71. class Square : public Rectangle
  72. {
  73. public:
  74. Square(string name, double width)
  75. :Rectangle(name, width, width)
  76. {}
  77. ~Square() {}
  78. double area()
  79. {
  80. return width_ * width_;
  81. }
  82. double permiter()
  83. {
  84. return 2 * width_;
  85. }
  86. };
  87.  
  88. class Circle: public Shape
  89. {
  90. protected:
  91. double radius_;
  92. public:
  93. Circle(string name, double radius)
  94. :Shape(name)
  95. {
  96. radius_ = radius;
  97.  
  98. }
  99. ~Circle() {}
  100.  
  101. double area()
  102. {
  103. return 3.14 * radius_ * radius_;
  104. }
  105. double permiter()
  106. {
  107. return 2 * 3.14 * radius_;
  108. }
  109. double getRadius()
  110. {
  111. return radius_;
  112. }
  113. };
  114.  
  115. class Elipse: public Shape
  116. {
  117. protected:
  118. double a_, b_;
  119. public:
  120. Elipse(string name, double a, double b)
  121. :Shape(name)
  122. {
  123. a_ = a;
  124. b_ = b;
  125. }
  126.  
  127. double area()
  128. {
  129. return a_ * b_ * 3.14;
  130. }
  131. double permiter()
  132. {
  133. return 3.14 *(((3/2)*(a_+b_))- sqrt(a_*b_));
  134. }
  135.  
  136. };
  137.  
  138. int main()
  139. {
  140. int opcja;
  141. bool a = 1;
  142.  
  143. while (a)
  144. {
  145. cout << endl;
  146. cout << "Wybierz opcje: " << endl;
  147. cout << "1. zadanie 1" << endl;
  148. cout << "2. zadanie 2" << endl;
  149. cout << "3. zadanie 3" << endl;
  150. cout << "4. zadanie 4" << endl;
  151. cout << "5. zakoncz " << endl;
  152.  
  153. cin >> opcja;
  154. switch (opcja)
  155. {
  156. case 1:
  157. {
  158. ShapeContainer pojemnik;
  159. Square * kwadrat("kwadrat", 5);
  160. pojemnik.add(*kwadrat);
  161. break;
  162. }
  163. case 2:
  164. {
  165. break;
  166. }
  167. case 3:
  168. {
  169. break;
  170. }
  171. case 4:
  172. {
  173. break;
  174. }
  175. case 5:
  176. {
  177. a = 0;
  178. break;
  179. }
  180.  
  181. }
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement