Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Home_task_5._1
  8. {
  9.     class Rectangle
  10.     {
  11.         private double sideA;
  12.         private double sideB;
  13.  
  14.  
  15.         public void SetsideA(double sideA)
  16.         {
  17.             if (sideA > 0)
  18.                 this.sideA = sideA;
  19.             else
  20.                 throw new Exception();
  21.         }
  22.  
  23.         public double GetsideA()
  24.         {
  25.             return sideA;
  26.         }
  27.  
  28.  
  29.         public void SetsideB(double sideB)
  30.         {
  31.             if (sideB > 0)
  32.                 this.sideB = sideB;
  33.             else
  34.                 throw new Exception();
  35.         }
  36.  
  37.         public double GetsideB()
  38.         {
  39.             return sideB;
  40.         }
  41.  
  42.  
  43.         public Rectangle(double sideA, double sideB)
  44.         {
  45.             this.sideA = sideA;
  46.             this.sideB = sideB;
  47.         }
  48.  
  49.         public Rectangle(double sideA)
  50.         {
  51.             this.sideA = sideA;
  52.             this.sideB = 5;
  53.         }
  54.  
  55.         public Rectangle()
  56.         {
  57.             this.sideA = 3;
  58.             this.sideB = 4;
  59.         }
  60.  
  61.         public void Inputs()
  62.         {
  63.             Console.WriteLine("sideA = {0} sideB = {1}", sideA, sideB);
  64.         }
  65.  
  66.         public double Area()
  67.         {
  68.             double area = this.sideA * this.sideB;
  69.             return area;
  70.         }
  71.  
  72.         public double Perimeter()
  73.         {
  74.             double perimeter = 2 * (this.sideA + this.sideB);
  75.             return perimeter;
  76.         }
  77.  
  78.         public bool IsSquare()
  79.         {
  80.             return sideA == sideB;
  81.         }
  82.     }
  83.  
  84.  
  85.     class Program
  86.     {
  87.         static void Main(string[] args)
  88.         {
  89.             //Rectangle p1 = new Rectangle();
  90.             //p1.SetsideA(double.Parse(Console.ReadLine()));
  91.             //p1.SetsideB(double.Parse(Console.ReadLine()));
  92.             //p1.Inputs();
  93.             //Console.WriteLine(p1.Area());
  94.             //Console.WriteLine(p1.Perimeter());
  95.             //Console.WriteLine(p1.IsSquare());
  96. //
  97. //
  98.             //var succ1 = double.TryParse(Console.ReadLine(), out var side1);
  99.             //Rectangle p2 = new Rectangle(side1);
  100.             //p2.Inputs();
  101.             //Console.WriteLine(p2.Area());
  102.             //Console.WriteLine(p2.Perimeter());
  103.             //Console.WriteLine(p2.IsSquare());
  104. //
  105. //
  106.             //Rectangle p3 = new Rectangle();
  107.             //p3.Inputs();
  108.             //Console.WriteLine(p3.Area());
  109.             //Console.WriteLine(p3.Perimeter());
  110.             //Console.WriteLine(p3.IsSquare());
  111.  
  112.             var arr = new Rectangle[3];
  113.             for (int i = 0; i < 3; i++)
  114.             {
  115.                 Rectangle p;
  116.                 if (double.TryParse(Console.ReadLine(), out var side1))
  117.                 {
  118.                     p = double.TryParse(Console.ReadLine(), out var side2)
  119.                         ? new Rectangle(side1, side2)
  120.                         : new Rectangle(side1);
  121.                 }
  122.                 else
  123.                 {
  124.                     p = new Rectangle();
  125.                 }
  126.  
  127.                 arr[i] = p;
  128.  
  129.                 p.Inputs();
  130.                 Console.WriteLine($"area {p.Area()} perim {p.Perimeter()} square {p.IsSquare()}");
  131.             }
  132.  
  133.             Console.WriteLine();
  134.  
  135.             var maxArea = arr[0].Area();
  136.             var maxAInd = 0;
  137.             var minPerim = arr[0].Perimeter();
  138.             var minPInd = 0;
  139.             var anySquares = false;
  140.             for (int i = 0; i < 3; i++)
  141.             {
  142.                 if (arr[i].Area() > maxArea)
  143.                 {
  144.                     maxArea = arr[i].Area();
  145.                     maxAInd = i;
  146.                 }
  147.                 if (arr[i].Perimeter() < minPerim)
  148.                 {
  149.                     minPerim = arr[i].Perimeter();
  150.                     minPInd = i;
  151.                 }
  152.                 if (arr[i].IsSquare())
  153.                 {
  154.                     Console.WriteLine($"rectangle {i + 1} is square");
  155.                     anySquares = true;
  156.                 }
  157.             }
  158.  
  159.             if (!anySquares)
  160.                 Console.WriteLine($"there are no rectangles that are squares");
  161.  
  162.             Console.WriteLine($"max area rect is: index {maxAInd + 1} area {maxArea}");
  163.             Console.WriteLine($"min perim rect is: index {minPInd + 1} area {minPerim}");
  164.         }
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement