Ochkasty_Dino

Practicum17-3

Dec 15th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.35 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 ConsoleApp7
  8. {
  9.     class Rectangle
  10.     {
  11.         int a;
  12.         int b;
  13.  
  14.         public Rectangle(int a, int b)
  15.         {
  16.             this.a = a;
  17.             this.b = b;
  18.         }
  19.  
  20.         public void Show()
  21.         {
  22.             Console.WriteLine("a={0}, b={1}", a, b);
  23.         }
  24.  
  25.         public int Perim(int a, int b)
  26.         {
  27.  
  28.             return (2 * (a + b));
  29.         }
  30.  
  31.         public int Plosh(int a, int b)
  32.         {
  33.             return (a * b);
  34.         }
  35.  
  36.         public int A
  37.         {
  38.             get
  39.             {
  40.                 return a;
  41.             }
  42.             set
  43.             {
  44.                 a = value;
  45.             }
  46.         }
  47.         public int B
  48.         {
  49.             get
  50.             {
  51.                 return b;
  52.             }
  53.             set
  54.             {
  55.                 b = value;
  56.             }
  57.         }
  58.         public string kvad
  59.         {
  60.             get
  61.             {
  62.                 if (a == b)
  63.                     return "Является квадратом";
  64.                 else return "Не является квадратом";
  65.             }
  66.         }
  67.  
  68.         public int this[int i]
  69.         {
  70.             get
  71.             {
  72.                 if ((i == 0))
  73.                 {
  74.                     return a;
  75.                 }
  76.                 else if ((i == 1))
  77.                 {
  78.                     return b;
  79.                 }
  80.                 else
  81.                 {
  82.                     Console.Write("Недопустимый индекс: {0}; возвращен ", i);
  83.  
  84.                     return 0;
  85.                 }
  86.             }
  87.  
  88.             set
  89.             {
  90.                 if (i == 0)
  91.                     a = value;
  92.                 if (i == 1)
  93.                     b = value;
  94.                 if (i < 0 && i > 1)
  95.                 {
  96.                     Console.WriteLine("Недопустимый индекс");
  97.                 }
  98.             }
  99.         }
  100.  
  101.         public static Rectangle operator ++(Rectangle c)
  102.         {
  103.             Rectangle temp = new Rectangle(c.a+1, c.b+1);
  104.             return temp;
  105.         }
  106.         public static Rectangle operator --(Rectangle c)
  107.         {
  108.             Rectangle temp = new Rectangle(c.a - 1, c.b - 1);
  109.             return temp;
  110.         }
  111.         public static Rectangle operator *(Rectangle c, int x)
  112.         {
  113.             Rectangle temp = new Rectangle(c.a * x, c.b * x);
  114.             return temp;
  115.         }
  116.  
  117.  
  118.     }
  119.     class Program
  120.     {
  121.         static void Main(string[] args)
  122.         {
  123.             Console.Write("Введите, пожалуйста, a=");
  124.             int a = int.Parse(Console.ReadLine());
  125.             Console.Write("Введите, пожалуйста, b=");
  126.             int b = int.Parse(Console.ReadLine());
  127.             // конструктор экземпляра
  128.             Rectangle oneRectangle = new Rectangle(a, b);
  129.             Console.WriteLine("______________________________________");
  130.             //вывод сторон треугольника
  131.             oneRectangle.Show();
  132.             Console.WriteLine("______________________________________");
  133.             //вывод периметра
  134.             Console.WriteLine("Периметр: {0}",oneRectangle.Perim(a, b));
  135.             Console.WriteLine("______________________________________");
  136.             //вывод площади
  137.             Console.WriteLine("Площадь: {0}", oneRectangle.Plosh(a, b));
  138.             Console.WriteLine("______________________________________");
  139.  
  140.             //свойство для записи и чтения сторон
  141.             oneRectangle.A = a;
  142.             oneRectangle.Show();
  143.             Console.WriteLine("______________________________________");
  144.             //свойство для чтения квадрат или нет
  145.             Console.WriteLine(oneRectangle.kvad);
  146.             Console.WriteLine("______________________________________");
  147.             //индексы
  148.             Console.WriteLine("Введите пожалуйста индексы:");
  149.             Console.WriteLine();
  150.             int i1 = int.Parse(Console.ReadLine());
  151.             int i2 = int.Parse(Console.ReadLine());
  152.             int i3 = int.Parse(Console.ReadLine());
  153.             Console.WriteLine();
  154.             Console.WriteLine("{0}", oneRectangle[i1]);
  155.             Console.WriteLine("{0}", oneRectangle[i2]);
  156.             Console.WriteLine("{0}", oneRectangle[i3]); Console.WriteLine();
  157.  
  158.             Console.WriteLine("______________________________________");
  159.             //инкремент
  160.             Console.Write("Инкремент: ");
  161.             oneRectangle++;
  162.             oneRectangle.Show();
  163.             Console.WriteLine("______________________________________");
  164.             //декремент
  165.             Console.Write("Декремент: ");
  166.             oneRectangle--;
  167.             oneRectangle.Show();
  168.             Console.WriteLine("______________________________________");
  169.  
  170.             //умножение на скаляр
  171.             Console.Write("Умножение на скаляр (на 2): ");
  172.             oneRectangle = oneRectangle * 2;
  173.             oneRectangle.Show();
  174.             Console.WriteLine();
  175.         }
  176.     }
  177. }
Add Comment
Please, Sign In to add comment