-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program (7).cs
75 lines (67 loc) · 2.56 KB
/
Program (7).cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
namespace Homework8
{
class Program
{
static void Main(string[] args)
{
List<Shape> shapes = new List<Shape>();
//Console.WriteLine("Let's create figures");
//shapes.Add(new Square("Square_A", 2));
//shapes.Add(new Square("Square_B", 8));
//shapes.Add(new Square("Square_C", 6));
//shapes.Add(new Square("Square_D", 4));
//shapes.Add(new Circle("Circle_A", 9));
//shapes.Add(new Circle("Circle_B", 7));
//shapes.Add(new Circle("Circle_C", 5));
//shapes.Add(new Circle("Circle_D", 3));
start:
try
{
for (int i = 0; i < 2; i++)
{
Console.Write("Enter Circle name: ");
string name = Console.ReadLine();
Console.WriteLine("Enter radius: ");
double radius = double.Parse(Console.ReadLine());
shapes.Add(new Circle(name, radius));
Console.Write("Enter Square name: ");
string squareName = Console.ReadLine();
Console.WriteLine("Enter side: ");
double side = double.Parse(Console.ReadLine());
shapes.Add(new Square(squareName, side));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
goto start;
}
foreach (var item in shapes)
{
Console.WriteLine($"Figure {item.Name} has perimetr: {item.Perimeter():F2}");
Console.WriteLine($"Figure {item.Name} has area: {item.Area():F2}");
}
double max=shapes[0].Perimeter();
int index = 0;
for (int i = 0; i < shapes.Count; i++)
{
if (shapes[i].Perimeter() > max)
{
max = shapes[i].Perimeter();
index = i;
}
}
Console.WriteLine("=========================================");
Console.WriteLine($"Shape with biggest perimetr is {shapes[index].Name}");
Console.WriteLine("=========================================");
Console.WriteLine("============Sorted by area==================");
shapes.Sort();
foreach (var item in shapes)
{
Console.WriteLine($"Figure {item.Name} has area: {item.Area():F2}");
}
}
}
}