Guest User

Untitled

a guest
Dec 4th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace FirstTask
  4. {
  5.  
  6. class Triangle // Класс "Треугольник".
  7. {
  8. private double side; // Поле "Сторона треугольника".
  9.  
  10. public Triangle() // Коннструктор по-умолчанию.
  11. {
  12. side = 0;
  13. }
  14.  
  15. public Triangle(double side) // Конструктор с задачей стороны.
  16. {
  17. this.side = side;
  18. }
  19.  
  20. public double Side // Свойства класса.
  21. {
  22. get
  23. {
  24. return side;
  25. }
  26.  
  27. set
  28. {
  29. side = value;
  30. }
  31. }
  32.  
  33. public virtual double GetSquare() // Вычисление площади треугольника.
  34. {
  35. return Math.Round((((side * side) * Math.Sqrt(3)) / 4), 3);
  36. }
  37.  
  38. public virtual void Show() // Получить информацию о фигуре.
  39. {
  40. Console.WriteLine();
  41. Console.WriteLine("-----------------------------------------");
  42. Console.WriteLine("Название фигуры: Треугольник");
  43. Console.WriteLine($"Длина стороны: {Side}");
  44. Console.WriteLine($"Количество вершин: {3}");
  45. Console.WriteLine($"Количество рёбер: {3}");
  46. Console.WriteLine($"Количество граней: {1}");
  47. Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
  48. Console.WriteLine("-----------------------------------------");
  49. Console.WriteLine();
  50. }
  51.  
  52.  
  53.  
  54. }
  55.  
  56. class Tetrahedron : Triangle // Класс тетраэдра.
  57. {
  58. private int topNum = 4; // Количество вершин.
  59. public int TopNum => topNum;
  60.  
  61. private int edgNum = 6; // Количество рёбер.
  62. public int EdgNum => edgNum;
  63.  
  64. private int faceNum = 4; //Количество граней.
  65. public int FaceNum => faceNum;
  66.  
  67. public Tetrahedron() // Конструктор по-умолчанию.
  68. {
  69. Side = 0;
  70. }
  71.  
  72. public Tetrahedron(double side) // Конструктор с задачей стороны.
  73. {
  74. Side = side;
  75. }
  76.  
  77. public override double GetSquare() //Переопределение площади.
  78. {
  79. return faceNum * base.GetSquare();
  80. }
  81.  
  82. public override void Show() // Получить информацию о фигуре.
  83. {
  84. Console.WriteLine();
  85. Console.WriteLine("-----------------------------------------");
  86. Console.WriteLine("Название фигуры: Тэтраэдр");
  87. Console.WriteLine($"Длина стороны: {Side}");
  88. Console.WriteLine($"Количество вершин: {topNum}");
  89. Console.WriteLine($"Количество рёбер: {edgNum}");
  90. Console.WriteLine($"Количество граней: {faceNum}");
  91. Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
  92. Console.WriteLine("-----------------------------------------");
  93. Console.WriteLine();
  94. }
  95.  
  96. }
  97.  
  98. class Octahedron : Triangle // Класс октаэдра.
  99. {
  100. private int topNum = 6; // Количество вершин.
  101. public int TopNum => topNum;
  102.  
  103. private int edgNum = 12; // Количество рёбер.
  104. public int EdgNum => edgNum;
  105.  
  106. private int faceNum = 8; //Количество граней.
  107. public int FaceNum => faceNum;
  108.  
  109. public Octahedron() // Конструктор по-умолчанию.
  110. {
  111. Side = 0;
  112. }
  113.  
  114. public Octahedron(double side) // Конструктор с задачей стороны.
  115. {
  116. Side = side;
  117. }
  118.  
  119. public override double GetSquare() //Переопределение площади.
  120. {
  121. return faceNum * base.GetSquare();
  122. }
  123.  
  124. public override void Show() // Получить информацию о фигуре.
  125. {
  126. Console.WriteLine();
  127. Console.WriteLine("-----------------------------------------");
  128. Console.WriteLine("Название фигуры: Октаэдр");
  129. Console.WriteLine($"Длина стороны: {Side}");
  130. Console.WriteLine($"Количество вершин: {topNum}");
  131. Console.WriteLine($"Количество рёбер: {edgNum}");
  132. Console.WriteLine($"Количество граней: {faceNum}");
  133. Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
  134. Console.WriteLine("-----------------------------------------");
  135. Console.WriteLine();
  136. }
  137.  
  138. }
  139.  
  140. class Icosuhedron : Triangle // Класс икосаэдра.
  141. {
  142. private int topNum = 12; // Количество вершин.
  143. public int TopNum => topNum;
  144.  
  145. private int edgNum = 30; // Количество рёбер.
  146. public int EdgNum => edgNum;
  147.  
  148. private int faceNum = 20; //Количество граней.
  149. public int FaceNum => faceNum;
  150.  
  151. public Icosuhedron() // Конструктор по-умолчанию.
  152. {
  153. Side = 0;
  154. }
  155.  
  156. public Icosuhedron(double side) // Конструктор с задачей стороны.
  157. {
  158. Side = side;
  159. }
  160.  
  161. public override double GetSquare() //Переопределение площади.
  162. {
  163. return faceNum * base.GetSquare();
  164. }
  165.  
  166. public override void Show() // Получить информацию о фигуре.
  167. {
  168. Console.WriteLine();
  169. Console.WriteLine("-----------------------------------------");
  170. Console.WriteLine("Название фигуры: Икосаэдр");
  171. Console.WriteLine($"Длина стороны: {Side}");
  172. Console.WriteLine($"Количество вершин: {topNum}");
  173. Console.WriteLine($"Количество рёбер: {edgNum}");
  174. Console.WriteLine($"Количество граней: {faceNum}");
  175. Console.WriteLine($"Площадь фигуры: {this.GetSquare()}");
  176. Console.WriteLine("-----------------------------------------");
  177. Console.WriteLine();
  178. }
  179.  
  180. }
  181.  
  182.  
  183. class Program
  184. {
  185. static void Main(string[] args)
  186. {
  187. Triangle[] array = new Triangle[10];
  188.  
  189. Console.Write("Сколько фигур будем считать? ");
  190. int n = Convert.ToInt32(Console.ReadLine());
  191.  
  192. for (int i = 0; i < n; i++)
  193. {
  194. Console.Write("Какую фигуру будем считать сейчас? (Т/О/И) ");
  195. char fig = Convert.ToChar(Console.ReadLine());
  196.  
  197. Console.Write("Введите длину стороны: ");
  198. int side = Convert.ToInt32(Console.ReadLine());
  199.  
  200. switch (fig)
  201. {
  202. case 'Т':
  203. array[i] = new Tetrahedron(side);
  204. break;
  205. case 'О':
  206. array[i] = new Octahedron(side);
  207. break;
  208. case 'И':
  209. array[i] = new Icosuhedron(side);
  210. break;
  211. }
  212.  
  213. array[i].Show();
  214. }
  215.  
  216. Console.ReadLine();
  217. }
  218.  
  219. }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment