fork download
  1. g System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Figure
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. Cons c = new Cons();
  12.  
  13.  
  14.  
  15.  
  16. }
  17. }
  18. class Cons
  19. {
  20.  
  21. public Cons()
  22. {
  23. double x, y, radius, wight, height, x1, y1, radiusOutSide;
  24. var figure = new List<Figure>();
  25. string newLine = Environment.NewLine;
  26. bool exit = false;
  27. string Name = "";
  28.  
  29. Console.Write("Как мне к вам обращаться? ");
  30. Name= TestName.Name();//свой метод проверки имени на пустоту
  31. while (!exit)
  32. {
  33. Console.WriteLine($"{Name} выберите действие ");
  34. Console.WriteLine("1.Добавить фигуру" + newLine + "2.Вывести фигуры"
  35. + newLine + "3.Очистить холст"
  36. + newLine + "4.Выход"
  37. + newLine + "5.Сменить пользователя");
  38.  
  39. string TypeFigure = Console.ReadLine();
  40. switch (TypeFigure)
  41. {
  42. case "1":
  43. Console.WriteLine("Доступные фигуры к созданию:" + newLine + "Круг || Окружность || Прямоугольник || Квадрат || Линия || Кольцо ");
  44. Console.Write("Выберите тип фигуры: ");
  45. string inputShape = Console.ReadLine();
  46. switch (inputShape)
  47. {
  48. case "Круг":
  49. case "круг":
  50. Console.WriteLine($"{Name} введите параметры фигуры Круг :");
  51. Console.Write("Введите координаты по оси X :");
  52. while (!double.TryParse(Console.ReadLine(), out x)) ;
  53. Console.Write("Введите координаты по оси Y :");
  54. while (!double.TryParse(Console.ReadLine(), out y)) ;
  55. Console.Write("Введите радиус:");
  56. while (!double.TryParse(Console.ReadLine(), out radius)) ;
  57. figure.Add(new Circle(x, y, radius));
  58. Console.WriteLine("Удачно!");
  59. break;
  60. case "Окружность":
  61. case "окружность":
  62. Console.WriteLine($"{Name} введите параметры фигуры окружность :");
  63. Console.Write("Введите координаты по оси X :");
  64. while (!double.TryParse(Console.ReadLine(), out x)) ;
  65. Console.Write("Введите координаты по оси Y :");
  66. while (!double.TryParse(Console.ReadLine(), out y)) ;
  67. Console.Write("Введите радиус:");
  68. while (!double.TryParse(Console.ReadLine(), out radius)) ;
  69. figure.Add(new СircleWithoutArea(x, y, radius));
  70. Console.WriteLine("Удачно!");
  71. break;
  72. case "квадрат":
  73. case "Квадрат":
  74. Console.WriteLine($"{Name} введите параметры фигуры Квадрат :");
  75. Console.Write("Введите координаты по оси X :");
  76. while (!double.TryParse(Console.ReadLine(), out x)) ;
  77. Console.Write("Введите координаты по оси Y :");
  78. while (!double.TryParse(Console.ReadLine(), out y)) ;
  79. Console.Write("Введите длину стороны:");
  80. while (!double.TryParse(Console.ReadLine(), out wight)) ;
  81. figure.Add(new Square(x, y, wight));
  82. Console.WriteLine("Удачно!");
  83. break;
  84. case "прямоугольник":
  85. case "Прямоугольник":
  86. Console.WriteLine($"{Name} введите параметры фигуры прямоугольникa :");
  87. Console.Write("Введите координаты по оси X :");
  88. while (!double.TryParse(Console.ReadLine(), out x)) ;
  89. Console.Write("Введите координаты по оси Y :");
  90. while (!double.TryParse(Console.ReadLine(), out y)) ;
  91. Console.Write("Введите ширину:");
  92. while (!double.TryParse(Console.ReadLine(), out wight)) ;
  93. Console.Write("Введите высоту:");
  94. while (!double.TryParse(Console.ReadLine(), out height)) ;
  95. figure.Add(new Rectangle(x, y, wight, height));
  96. Console.WriteLine("Удачно!");
  97. break;
  98. case "Линия":
  99. case "линия":
  100. Console.WriteLine($"{Name} введите параметры Линии :");
  101. Console.Write("Введите координаты по оси X первой точки:");
  102. while (!double.TryParse(Console.ReadLine(), out x)) ;
  103. Console.Write("Введите координаты по оси Y первой точки:");
  104. while (!double.TryParse(Console.ReadLine(), out y)) ;
  105. Console.Write("Введите координаты по оси X второй точки:");
  106. while (!double.TryParse(Console.ReadLine(), out x1)) ;
  107. Console.Write("Введите координаты по оси Y второй точки:");
  108. while (!double.TryParse(Console.ReadLine(), out y1)) ;
  109. figure.Add(new Line(x, y, x1, y1));
  110. Console.WriteLine("Удачно!");
  111. break;
  112. case "Кольцо":
  113. case "кольцо":
  114. Console.WriteLine($"{Name} введите параметры Кольца :");
  115. Console.Write("Введите координаты по оси X первой точки:");
  116. while (!double.TryParse(Console.ReadLine(), out x)) ;
  117. Console.Write("Введите координаты по оси Y первой точки:");
  118. while (!double.TryParse(Console.ReadLine(), out y)) ;
  119. Console.Write("Введите введите внешний радиус");
  120. while (!double.TryParse(Console.ReadLine(), out radius)) ;
  121. Console.Write("Введите введите внутренний радиус:");
  122. while (!double.TryParse(Console.ReadLine(), out radiusOutSide)) ;
  123. if (radius >= radiusOutSide)
  124. {
  125. double obj = radius;
  126. radius = radiusOutSide;
  127. radius = obj;
  128.  
  129. }
  130. figure.Add(new Ring(x, y, radius, radiusOutSide));
  131. Console.WriteLine("Удачно!");
  132. break;
  133. default:
  134. Console.WriteLine("Ввод невалиден.");
  135. break;
  136. }
  137.  
  138. break;
  139. case "2":
  140.  
  141. if (figure.Count > 0)
  142. {
  143. Console.WriteLine("Линии :");
  144. foreach (Figure item in figure)
  145. {
  146.  
  147. Line line = item as Line;
  148. if (line != null)
  149. {
  150. string value = $" Линия: Длина линии: {line.sidesLength}.";
  151. Console.WriteLine(value);
  152. }
  153. Ring ring = item as Ring;
  154. if (ring != null)
  155. {
  156. string value = $" Кольцо: Длина внешней окружности: {ring.outSideRadius} Длина внутренней окружности: {ring.radius} Площадь: {ring.area}.";
  157. Console.WriteLine(value);
  158. }
  159. Square square = item as Square;
  160. if (square != null)
  161. {
  162. Console.WriteLine($" Квадрат: Длина сторон: {square.sidesLength} Площадь: {square.area}");
  163. }
  164. Rectangle rectangle = item as Rectangle;
  165. if (rectangle != null)
  166. {
  167. string value = $" Прямоугольник: Длина линии: {rectangle.sidesLength} Площадь: {rectangle.area}.";
  168. Console.WriteLine(value);
  169. }
  170. Circle circle = item as Circle;
  171. if (circle != null| circle.sidelenght >0)
  172. {
  173. Console.WriteLine($" Круг: Радиус: {circle.radius} Площадь: {circle.area} Cумма сторон {circle.sidelenght} ");
  174. }
  175. СircleWithoutArea circleWithoutArea = item as СircleWithoutArea;
  176. if (circleWithoutArea != null)
  177. {
  178. Console.WriteLine($" Окружность: Радиус: {circleWithoutArea.radius} Cумма сторон {circleWithoutArea.siderLenght} ");
  179. }
  180.  
  181. };
  182. }
  183.  
  184. break;
  185. case "3":
  186. figure.Clear();
  187. Console.WriteLine($"{Name}, вы удалили все фигуры.");
  188. break;
  189. case "4":
  190. exit = true;
  191. break;
  192. case "5":
  193. Name = TestName.Name();
  194. break;
  195. }
  196. }
  197.  
  198.  
  199.  
  200. }
  201. }
  202. public static class TestName
  203. {
  204. public static string Name()
  205. {
  206. bool nullName = true;
  207. string Name = "";
  208. while (nullName)
  209. {
  210. Name = Console.ReadLine();
  211. if (!String.IsNullOrEmpty(Name))
  212. {
  213. nullName = false;
  214. }
  215. }
  216. return Name;
  217.  
  218. }
  219. }
  220.  
  221.  
  222.  
  223. public abstract class Figure
  224. {
  225. protected double x, y;
  226.  
  227. public Figure(double x, double y)
  228. {
  229. this.x = x;
  230. this.y = y;
  231. }
  232.  
  233. public abstract double SidesLength();
  234.  
  235. }
  236.  
  237.  
  238. public class Line : Figure
  239. {
  240. public double x1;
  241. public double y1;
  242. public double sidesLength { get; set; }
  243.  
  244. public Line(double x, double y, double x1, double y1)
  245. : base(x, y)
  246. {
  247. this.x1 = x1;
  248. this.y1 = y1;
  249. sidesLength = SidesLength();
  250. }
  251.  
  252. public override double SidesLength()
  253. {
  254. return Math.Sqrt(Math.Pow((x1 - x), 2) + Math.Pow((y1 - y), 2));
  255. }
  256.  
  257. }
  258.  
  259.  
  260.  
  261. public class Square : Figure
  262. {
  263. public double height;
  264. public double width;
  265. public double area;
  266. public double sidesLength;
  267.  
  268. public Square(double x, double y, double widht)
  269. : base(x, y)
  270. {
  271. this.height = width;
  272. this.width = widht;
  273. area = Area();
  274. sidesLength = SidesLength();
  275.  
  276. }
  277.  
  278.  
  279. public override double SidesLength()
  280. {
  281. return width * 4;
  282. }
  283. public virtual double Area()
  284. {
  285. return width * width;
  286. }
  287.  
  288. }
  289.  
  290.  
  291.  
  292. public class Rectangle : Square
  293. {
  294. public Rectangle(double x, double y, double widht, double height)
  295. : base(x, y, widht)
  296. {
  297. this.height = height;
  298. this.width = widht;
  299. area = Area();
  300. sidesLength = SidesLength();
  301. }
  302.  
  303. public override double SidesLength()
  304. {
  305. return (width + height) * 2;
  306. }
  307.  
  308. }
  309.  
  310.  
  311.  
  312. public class СircleWithoutArea : Figure
  313. {
  314. public const double pi = Math.PI;
  315. public double radius;
  316. public double siderLenght;
  317. public СircleWithoutArea(double x, double y, double radius)
  318. : base(x, y)
  319. {
  320. this.radius = radius;
  321. siderLenght = SidesLength();
  322. }
  323.  
  324. public override double SidesLength()
  325. {
  326. return pi * radius * 2;
  327. }
  328.  
  329. }
  330.  
  331.  
  332.  
  333. public class Circle : СircleWithoutArea
  334. {
  335. public double sidelenght;
  336. public double area;
  337. public Circle(double x, double y, double radius)
  338. : base(x, y, radius)
  339. {
  340. this.radius = radius;
  341. sidelenght = SidesLength();
  342. area = Area();
  343. }
  344.  
  345. public virtual double Area()
  346. {
  347. return pi * radius * radius;
  348. }
  349. public override double SidesLength()
  350. {
  351. return pi * radius * 2;
  352. }
  353. }
  354.  
  355.  
  356.  
  357. public class Ring : СircleWithoutArea
  358. {
  359. public double area;
  360. public double outSideRadius;
  361.  
  362. public Ring(double x, double y, double radius, double outSideRadius)
  363. : base(x, y, radius)
  364. {
  365. this.outSideRadius = outSideRadius;
  366. area = Area();
  367. }
  368.  
  369. public virtual double Area()
  370. {
  371. return pi * (outSideRadius * outSideRadius - radius * radius);
  372. }
  373. public override double SidesLength()
  374. {
  375. return pi * outSideRadius * 2;
  376. }
  377. public double InsideSidesLength()
  378. {
  379. return pi * radius * 2;
  380. }
  381. }
  382.  
  383. }
  384.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,0): error CS1525: Unexpected symbol `g'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty