Advertisement
semkaegor4ik

XVII 3

Nov 20th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. namespace Example
  5. {
  6.     class Rectangle
  7.     {
  8.         private int a, b;
  9.         public Rectangle(int a, int b)
  10.         {
  11.             if (a < 1 || b < 1)
  12.             {
  13.                 throw new Exception("Недопустимые длины сторон");
  14.             }
  15.             else
  16.             {
  17.                 this.a = a;
  18.                 this.b = b;
  19.             }
  20.         }
  21.         public void Show()
  22.         {
  23.             Console.WriteLine("стороны прямоугольника: {0}X{1}", a, b);
  24.         }
  25.  
  26.         public int Perimetr()
  27.         {
  28.             return 2 * (a + b);
  29.         }
  30.         public int Square()
  31.         {
  32.             return a * b;
  33.         }
  34.         public bool Quadrate
  35.         {
  36.             get
  37.             {
  38.                 if (a == b)
  39.                     return true;
  40.                 else
  41.                     return false;
  42.             }
  43.         }
  44.         public Rectangle ABleng                 //сразу две стороны
  45.         {
  46.             get
  47.             {
  48.                 return new Rectangle(a,b);
  49.             }
  50.             set
  51.             {
  52.                 a = value.a;
  53.                 b = value.b;
  54.             }
  55.         }
  56.         public int Aleng                 //первая сторона
  57.         {
  58.             get
  59.             {
  60.                 return a;
  61.             }
  62.             set
  63.             {
  64.                 a = value;
  65.             }
  66.         }
  67.         public int Bleng                 //вторая сторона
  68.         {
  69.             get
  70.             {
  71.                 return b;
  72.             }
  73.             set
  74.             {
  75.                 b = value;
  76.             }
  77.         }
  78.  
  79.         public int this[int c]
  80.         {
  81.             get
  82.             {
  83.                 if (c == 1)
  84.                     return b;
  85.                 else if (c == 0)
  86.                     return a;
  87.                 else
  88.                     throw new Exception("Недопустимый индекс");
  89.             }
  90.             set
  91.             {
  92.                 if (c == 0)
  93.                     a = value;
  94.                 else if (c == 1)
  95.                     b = value;
  96.                 else
  97.                     throw new Exception("Недопустимый индекс");
  98.             }
  99.         }
  100.         public static Rectangle operator ++(Rectangle a)
  101.         {
  102.             return new Rectangle(++a.a, ++a.b);
  103.         }
  104.         public static Rectangle operator --(Rectangle a)
  105.         {
  106.             return new Rectangle(--a.a, --a.b);
  107.         }
  108.         public static Rectangle operator *(Rectangle a, int c)
  109.         {
  110.             return new Rectangle(a.a * c, a.b * c);
  111.         }
  112.     }
  113.     class Program
  114.     {
  115.         static void Main()
  116.         {
  117.             Rectangle[] ar = new Rectangle[5];
  118.             char[] delimiterChars = { ' ', '\n' };
  119.             string line;
  120.             using (StreamReader fileIn = new StreamReader("input.txt"))
  121.             {
  122.                 line = fileIn.ReadToEnd();
  123.             }
  124.             string[] info = line.Split(delimiterChars);
  125.             for(int i=0,k=0;i<info.Length;i+=2,k++)
  126.             {
  127.                 Rectangle c = new Rectangle(int.Parse(info[i]), int.Parse(info[i + 1]));
  128.                 ar[k] = c;
  129.             }
  130.             ar[0].Show();
  131.             int per = ar[1].Perimetr();
  132.             Console.WriteLine("Периметр равен {0}",per);
  133.             int squar = ar[2].Square();
  134.             Console.WriteLine("Площадь равна {0}", squar);
  135.             if(ar[3].Quadrate)
  136.                 Console.WriteLine("прямоугольник является квадратом");
  137.             int m = ar[4].Aleng;
  138.             int n = ar[4].Bleng;
  139.             Console.WriteLine("длина прямоугольника равна {0}, а ширина {1}",m,n);
  140.             ar[0][1] = 5;               //задаем новое значение ширины
  141.             int t = ar[0][1];
  142.             Console.WriteLine("ширина прямоугольника равна {0}", t);
  143.             ar[1]++;
  144.             ar[1].Show();
  145.             ar[1]--;
  146.             ar[1].Show();
  147.             Rectangle s = ar[1] * 10;
  148.             s.Show();
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement