Advertisement
istomina_sofia

dd

Dec 28th, 2021
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.35 KB | None | 0 0
  1. public interface Shape
  2.     {
  3.          double GetSquare();
  4.          double GetPerimetr();
  5.          public void GetShapeInfo();
  6.     }
  7.  
  8.     public class Circle : Shape
  9.     {
  10.         private double r;
  11.         public double R { get => r; }
  12.  
  13.         public Circle(double r)
  14.         {
  15.             this.r = r;
  16.         }
  17.  
  18.  
  19.         public virtual double GetSquare()
  20.         {
  21.             return Math.PI * r * r;
  22.         }
  23.  
  24.         public double GetPerimetr()
  25.         {
  26.             return 2 * Math.PI * r;
  27.         }
  28.  
  29.         public virtual void GetShapeInfo()
  30.         {
  31.             Console.WriteLine($"Окружность с радиусом = {r}\n" +
  32.                 $"площадью = {GetSquare()} и длиной окружности = {GetPerimetr()}");
  33.         }
  34.     }
  35.  
  36.     public class Conus : Circle
  37.     {
  38.         double height;
  39.        
  40.          public Conus(double height, double r)
  41.             : base (r)
  42.         {
  43.             this.height = height;
  44.         }
  45.  
  46.         public double GetValue()    
  47.         {
  48.             return Math.PI * base.R * base.R * height / 3;
  49.         }
  50.  
  51.         public override double GetSquare()
  52.         {
  53.             return Math.PI * base.R * (base.R + Math.Sqrt(base.R * base.R + height * height));
  54.         }
  55.  
  56.         public override void GetShapeInfo()
  57.         {
  58.             Console.WriteLine($"Конус с радиусом основания = {base.R} и высотой = {height}\n" +
  59.                     $"площадью = {GetSquare()} и объёмом = {GetValue()}");
  60.         }
  61.        
  62.     }
  63.  
  64.     public class Sphere : Circle
  65.     {
  66.         Conus conus;
  67.         public Sphere(double r)
  68.             : base (r)
  69.         {
  70.         }
  71.         public Sphere(double r, Conus conus)
  72.             : base(r)
  73.         {
  74.             this.conus = conus;
  75.         }
  76.         public double GetValue()
  77.         {
  78.             return 4 / 3 * base.GetSquare() * base.R;
  79.         }
  80.         public override double GetSquare()
  81.         {
  82.             return 4 * base.GetSquare();
  83.         }
  84.         public override void GetShapeInfo()
  85.         {
  86.             Console.WriteLine($"Сфера с радиусом = {base.R}\n" +
  87.                         $"площадью = {GetSquare()} и объёмом = {GetValue()}");
  88.             if (conus != null)
  89.             {
  90.                 Console.WriteLine($"_______\n" +
  91.                     $"Вписаный конус:");
  92.                 conus.GetShapeInfo();
  93.                 Console.WriteLine($"_______");
  94.             }
  95.         }
  96.     }
  97.  
  98.     public class Rectangle : Shape
  99.     {
  100.         private double a;
  101.         private double b;
  102.  
  103.         public Rectangle(double a, double b)
  104.         {
  105.             this.a = a; this.b = b;
  106.         }
  107.  
  108.         public void ChangeBSide(Circle circle)
  109.         {
  110.             b *= circle.GetSquare() - circle.GetPerimetr() + 4;
  111.         }
  112.  
  113.         public double GetSquare()
  114.         {
  115.             return a * b;
  116.         }
  117.  
  118.         public double GetPerimetr()
  119.         {
  120.             return 2 * (a + b);
  121.         }
  122.  
  123.         public void GetShapeInfo()
  124.         {
  125.             Console.WriteLine($"Прямоугольник со сторонами a = {a}, b = {b}\n" +
  126.                 $"Площадью = {GetSquare()} и периметром {GetPerimetr()}");
  127.         }
  128.     }
  129.  
  130.  
  131.     class Program
  132.     {
  133.         static void ChapterOne()
  134.         {
  135.             Console.Write("Количество окружностей = ");
  136.             int n = Convert.ToInt32(Console.ReadLine());
  137.  
  138.             Console.Write("Количество конусов = ");
  139.             int m = Convert.ToInt32(Console.ReadLine());
  140.  
  141.             Circle[] circles = new Circle[n];
  142.             Conus[] conuses = new Conus[m];
  143.  
  144.             double avgSquareR = 0;
  145.             int countCircleRLessZero = 0;
  146.  
  147.             for (int i = 0; i < n; i++)
  148.             {
  149.                 Console.Write($"Введите радиус окружности {i + 1}: ");
  150.                 double r = Convert.ToDouble(Console.ReadLine());
  151.                 if (r <= 0) throw new Exception("Num less then zero");
  152.                
  153.                 circles[i] = new Circle(r);
  154.                 avgSquareR += circles[i].GetSquare();
  155.             }
  156.             avgSquareR /= n;
  157.             foreach (Circle c in circles)
  158.             {
  159.                 if (c.GetSquare() < avgSquareR) countCircleRLessZero++;
  160.             }
  161.  
  162.             double maxValue = 0;
  163.             int maxValueI = 0;
  164.  
  165.             for (int i = 0; i < m; i++)
  166.             {
  167.                 Console.WriteLine($"Введите радиус основания и высоту конуса {i + 1} ");
  168.                 Console.Write("Радиус основания = ");
  169.                 double r = Convert.ToDouble(Console.ReadLine());
  170.                 Console.Write("Высота = ");
  171.                 double h = Convert.ToDouble(Console.ReadLine());
  172.                 if (r < 0 || h < 0) throw new Exception("Num less then zero");
  173.  
  174.                 conuses[i] = new Conus(h, r);
  175.                 if (conuses[i].GetValue() > maxValue)
  176.                 {
  177.                     maxValue = conuses[i].GetValue();
  178.                     maxValueI = i;
  179.                 }
  180.             }
  181.  
  182.             Console.WriteLine($"Число коружностей с площадью меньше средней - {countCircleRLessZero}");
  183.  
  184.             Console.WriteLine($"Конус с наибольшим объёмом ({maxValue}):");
  185.             conuses[maxValueI].GetShapeInfo();
  186.             Console.WriteLine();
  187.         }
  188.  
  189.         static void ChapterTwo()
  190.         {
  191.             Circle c = new Circle(4);
  192.             c.GetShapeInfo();
  193.             Console.WriteLine();
  194.  
  195.             Conus conus = new Conus(6, 3);
  196.             conus.GetShapeInfo();
  197.             Console.WriteLine();
  198.  
  199.             Sphere sphere = new(5);
  200.             sphere.GetShapeInfo();
  201.             Console.WriteLine();
  202.  
  203.             Sphere sphere1 = new Sphere(4, conus);
  204.             sphere1.GetShapeInfo();
  205.             Console.WriteLine();
  206.  
  207.             Rectangle rectangle = new Rectangle(2, 3);
  208.             rectangle.GetShapeInfo();
  209.             rectangle.ChangeBSide(c);
  210.             rectangle.GetShapeInfo();
  211.  
  212.         }
  213.         static void Main(string[] args)
  214.         {
  215.             //ChapterOne();
  216.             ChapterTwo();
  217.            
  218.         }
  219.     }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement