Advertisement
kqlul123

Untitled

Dec 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. #include "iostream"
  2. #include "iomanip"
  3. #include <string>
  4. #define _USE_MATH_DEFINES
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. //Фигура
  11. class Figure
  12. {
  13. protected:
  14. string Color;
  15. public:
  16. Figure(string color = "Red");
  17. virtual void Input() = 0;
  18. virtual void Output() = 0;
  19. virtual float Square() = 0;
  20. };
  21. Figure::Figure(string qq)
  22. {
  23. Color = qq;
  24. }
  25.  
  26.  
  27. //Круг
  28. class Circle : public Figure
  29. {
  30. public:
  31. int Radius;
  32. Circle(string color = "Blue", float radius = 20);
  33. void Input() override;
  34. void Output() override;
  35. float Square() override;
  36. };
  37. Circle::Circle(string color, float radius) : Figure(color)
  38. {
  39. Radius = radius;
  40. }
  41. void Circle::Input()
  42. {
  43. cout << "Введите цвет\n";
  44. cin >> Color;
  45. cout << "Введите радиус\n";
  46. cin >> Radius;
  47. cout << endl;
  48. }
  49. void Circle::Output()
  50. {
  51. cout << "Цвет: " << Color << endl;
  52. cout << "Радиус: " << Radius << endl;
  53. cout << "Площадь: " << Square() << endl;
  54. }
  55. float Circle::Square()
  56. {
  57. return M_PI * (Radius*Radius);
  58. }
  59.  
  60. //Прямоугольник
  61. class Pr : public Figure
  62. {
  63. public:
  64. float Width;
  65. float Length;
  66. Pr(string color = "Green", float width = 40, float length = 35);
  67. void Input() override;
  68. void Output() override;
  69. float Square() override;
  70. };
  71. Pr::Pr(string color, float width, float length) : Figure(color)
  72. {
  73. Width = width;
  74. Length = length;
  75. }
  76. void Pr::Input()
  77. {
  78. cout << "Введите цвет\n";
  79. cin >> Color;
  80. cout << "Введите длину\n";
  81. cin >> Length;
  82. cout << "Введите ширину\n";
  83. cin >> Width;
  84. }
  85. void Pr::Output()
  86. {
  87. cout << "Цвет: " << Color << endl;
  88. cout << "Длина: " << Length << endl;
  89. cout << "Ширина: " << Width << endl;
  90. cout << "Площадь: " << Square() << endl;
  91. }
  92. float Pr::Square()
  93. {
  94. return Width * Length;
  95. }
  96.  
  97. //Параллелипипед
  98. class Parall : public Pr {
  99. private:
  100. string Type;
  101. float Height;
  102. public:
  103. Parall(string color = "Green", float width = 20, float length = 35, string type = "Прямоугольный", float height = 35);
  104. void Input() override;
  105. void Output() override;
  106. float Square() override;
  107. };
  108. Parall::Parall(string color, float width, float length, string type, float height) : Pr(color, width, length) {
  109. Type = type;
  110. }
  111. void Parall::Input()
  112. {
  113. Pr::Input();
  114. cout << "Введите тип параллелепипеда [Прямоугольный 1| Куб 2]\n";
  115. int option = 0;
  116. cin >> option;
  117. switch (option)
  118. {
  119. case 1:
  120. Type = "Прямоугольный";
  121. cout << "Введите высоту параллелипеда" << endl;
  122. cin >> Height;
  123. break;
  124. case 2:
  125. Type = "Куб";
  126. break;
  127. default:
  128. Type = "Произвольный";
  129. break;
  130. }
  131. cout << endl;
  132. }
  133. void Parall::Output() {
  134. Pr::Output();
  135. cout << "Тип параллелипипеда: " << Type << endl << endl;
  136. cout << "Площадь: " << Square() << endl;
  137. }
  138. float Parall::Square() {
  139. if (Type == "Прямоугольный")
  140. return 2 * (Width*Length + Width * Height + Length * Height);
  141. else if (Type == "Куб")
  142. return 6 * (Width*Width);
  143. }
  144.  
  145.  
  146. //Цилиндр
  147. class Barrel : public Circle {
  148. private:
  149. string Type;
  150. public:
  151. float CHeight;
  152. Barrel(string name = "Black", float radius = 30, float height = 10, string type = "Круговой");
  153. void Input() override;
  154. void Output() override;
  155. float Square() override;
  156. };
  157. Barrel::Barrel(string color, float radius, float height, string type) : Circle(color, radius) {
  158. Type = type;
  159. CHeight = height;
  160. }
  161. void Barrel::Input() {
  162. Circle::Input();
  163. cout << "Введите высоту цилиндра\n";
  164. cin >> CHeight;
  165. cout << "Введите тип цилиндра [Круговой 1| Прямой 2| Наклонный 3]\n";
  166. int option = 0;
  167. cin >> option;
  168. switch (option)
  169. {
  170. case 1:
  171. Type = "Круговой";
  172. break;
  173. case 2:
  174. Type = "Прямой";
  175. break;
  176. case 3:
  177. Type = "Наклонный";
  178. break;
  179. default:
  180. Type = "Особый";
  181. break;
  182. }
  183. cout << endl;
  184. }
  185. void Barrel::Output() {
  186. Circle::Output();
  187. cout << "Высота: " << CHeight;
  188. cout << "Площадь: " << Square() << endl;
  189. }
  190. float Barrel::Square() {
  191. return 2*M_PI*Radius*(CHeight + Radius);
  192. }
  193.  
  194.  
  195. //Вывести доступные опции
  196. void ShowOptions() {
  197. cout << endl;
  198. cout << "[1] Circle - круг " << endl;
  199. cout << "[2] Pr - прямоугольник" << endl;
  200. cout << "[3] Barrel - цилиндр" << endl;
  201. cout << "[4] Parall - параллелипипед" << endl;
  202. cout << "0 - выход из программы" << endl << endl;
  203.  
  204. }
  205.  
  206. int main()
  207. {
  208. setlocale(LC_ALL, "Russian");
  209. Figure *figure = nullptr;
  210.  
  211. int option = 1;
  212. do {
  213. cout << "Введите тип фигуры:";
  214. ShowOptions();
  215. cin >> option;
  216. switch (option)
  217. {
  218. case 1:
  219. figure = new Circle();
  220. break;
  221. case 2:
  222. figure = new Pr();
  223. break;
  224. case 3:
  225. figure = new Barrel();
  226. break;
  227. case 4:
  228. figure = new Parall();
  229. break;
  230. case 0:
  231. cout << "Завершение программы" << endl;
  232. break;
  233. default:
  234. option = -1;
  235. cout << "Такой тип фигуры не найден" << endl;
  236. break;
  237. }
  238. if (option != -1 && option != 0) {
  239. figure->Input();
  240. figure->Output();
  241. delete figure;
  242. }
  243. } while (option != 0);
  244.  
  245. system("pause");
  246. return 0;
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement