Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface Shape
- {
- double GetSquare();
- double GetPerimetr();
- public void GetShapeInfo();
- }
- public class Circle : Shape
- {
- private double r;
- public double R { get => r; }
- public Circle(double r)
- {
- this.r = r;
- }
- public virtual double GetSquare()
- {
- return Math.PI * r * r;
- }
- public double GetPerimetr()
- {
- return 2 * Math.PI * r;
- }
- public virtual void GetShapeInfo()
- {
- Console.WriteLine($"Окружность с радиусом = {r}\n" +
- $"площадью = {GetSquare()} и длиной окружности = {GetPerimetr()}");
- }
- }
- public class Conus : Circle
- {
- double height;
- public Conus(double height, double r)
- : base (r)
- {
- this.height = height;
- }
- public double GetValue()
- {
- return Math.PI * base.R * base.R * height / 3;
- }
- public override double GetSquare()
- {
- return Math.PI * base.R * (base.R + Math.Sqrt(base.R * base.R + height * height));
- }
- public override void GetShapeInfo()
- {
- Console.WriteLine($"Конус с радиусом основания = {base.R} и высотой = {height}\n" +
- $"площадью = {GetSquare()} и объёмом = {GetValue()}");
- }
- }
- public class Sphere : Circle
- {
- Conus conus;
- public Sphere(double r)
- : base (r)
- {
- }
- public Sphere(double r, Conus conus)
- : base(r)
- {
- this.conus = conus;
- }
- public double GetValue()
- {
- return 4 / 3 * base.GetSquare() * base.R;
- }
- public override double GetSquare()
- {
- return 4 * base.GetSquare();
- }
- public override void GetShapeInfo()
- {
- Console.WriteLine($"Сфера с радиусом = {base.R}\n" +
- $"площадью = {GetSquare()} и объёмом = {GetValue()}");
- if (conus != null)
- {
- Console.WriteLine($"_______\n" +
- $"Вписаный конус:");
- conus.GetShapeInfo();
- Console.WriteLine($"_______");
- }
- }
- }
- public class Rectangle : Shape
- {
- private double a;
- private double b;
- public Rectangle(double a, double b)
- {
- this.a = a; this.b = b;
- }
- public void ChangeBSide(Circle circle)
- {
- b *= circle.GetSquare() - circle.GetPerimetr() + 4;
- }
- public double GetSquare()
- {
- return a * b;
- }
- public double GetPerimetr()
- {
- return 2 * (a + b);
- }
- public void GetShapeInfo()
- {
- Console.WriteLine($"Прямоугольник со сторонами a = {a}, b = {b}\n" +
- $"Площадью = {GetSquare()} и периметром {GetPerimetr()}");
- }
- }
- class Program
- {
- static void ChapterOne()
- {
- Console.Write("Количество окружностей = ");
- int n = Convert.ToInt32(Console.ReadLine());
- Console.Write("Количество конусов = ");
- int m = Convert.ToInt32(Console.ReadLine());
- Circle[] circles = new Circle[n];
- Conus[] conuses = new Conus[m];
- double avgSquareR = 0;
- int countCircleRLessZero = 0;
- for (int i = 0; i < n; i++)
- {
- Console.Write($"Введите радиус окружности {i + 1}: ");
- double r = Convert.ToDouble(Console.ReadLine());
- if (r <= 0) throw new Exception("Num less then zero");
- circles[i] = new Circle(r);
- avgSquareR += circles[i].GetSquare();
- }
- avgSquareR /= n;
- foreach (Circle c in circles)
- {
- if (c.GetSquare() < avgSquareR) countCircleRLessZero++;
- }
- double maxValue = 0;
- int maxValueI = 0;
- for (int i = 0; i < m; i++)
- {
- Console.WriteLine($"Введите радиус основания и высоту конуса {i + 1} ");
- Console.Write("Радиус основания = ");
- double r = Convert.ToDouble(Console.ReadLine());
- Console.Write("Высота = ");
- double h = Convert.ToDouble(Console.ReadLine());
- if (r < 0 || h < 0) throw new Exception("Num less then zero");
- conuses[i] = new Conus(h, r);
- if (conuses[i].GetValue() > maxValue)
- {
- maxValue = conuses[i].GetValue();
- maxValueI = i;
- }
- }
- Console.WriteLine($"Число коружностей с площадью меньше средней - {countCircleRLessZero}");
- Console.WriteLine($"Конус с наибольшим объёмом ({maxValue}):");
- conuses[maxValueI].GetShapeInfo();
- Console.WriteLine();
- }
- static void ChapterTwo()
- {
- Circle c = new Circle(4);
- c.GetShapeInfo();
- Console.WriteLine();
- Conus conus = new Conus(6, 3);
- conus.GetShapeInfo();
- Console.WriteLine();
- Sphere sphere = new(5);
- sphere.GetShapeInfo();
- Console.WriteLine();
- Sphere sphere1 = new Sphere(4, conus);
- sphere1.GetShapeInfo();
- Console.WriteLine();
- Rectangle rectangle = new Rectangle(2, 3);
- rectangle.GetShapeInfo();
- rectangle.ChangeBSide(c);
- rectangle.GetShapeInfo();
- }
- static void Main(string[] args)
- {
- //ChapterOne();
- ChapterTwo();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement