Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.IO;
- namespace Example
- {
- class Rectangle
- {
- private int a, b;
- public Rectangle(int a, int b)
- {
- if (a < 1 || b < 1)
- {
- throw new Exception("Недопустимые длины сторон");
- }
- else
- {
- this.a = a;
- this.b = b;
- }
- }
- public void Show()
- {
- Console.WriteLine("стороны прямоугольника: {0}X{1}", a, b);
- }
- public int Perimetr()
- {
- return 2 * (a + b);
- }
- public int Square()
- {
- return a * b;
- }
- public bool Quadrate
- {
- get
- {
- if (a == b)
- return true;
- else
- return false;
- }
- }
- public Rectangle ABleng //сразу две стороны
- {
- get
- {
- return new Rectangle(a,b);
- }
- set
- {
- a = value.a;
- b = value.b;
- }
- }
- public int Aleng //первая сторона
- {
- get
- {
- return a;
- }
- set
- {
- a = value;
- }
- }
- public int Bleng //вторая сторона
- {
- get
- {
- return b;
- }
- set
- {
- b = value;
- }
- }
- public int this[int c]
- {
- get
- {
- if (c == 1)
- return b;
- else if (c == 0)
- return a;
- else
- throw new Exception("Недопустимый индекс");
- }
- set
- {
- if (c == 0)
- a = value;
- else if (c == 1)
- b = value;
- else
- throw new Exception("Недопустимый индекс");
- }
- }
- public static Rectangle operator ++(Rectangle a)
- {
- return new Rectangle(++a.a, ++a.b);
- }
- public static Rectangle operator --(Rectangle a)
- {
- return new Rectangle(--a.a, --a.b);
- }
- public static Rectangle operator *(Rectangle a, int c)
- {
- return new Rectangle(a.a * c, a.b * c);
- }
- }
- class Program
- {
- static void Main()
- {
- Rectangle[] ar = new Rectangle[5];
- char[] delimiterChars = { ' ', '\n' };
- string line;
- using (StreamReader fileIn = new StreamReader("input.txt"))
- {
- line = fileIn.ReadToEnd();
- }
- string[] info = line.Split(delimiterChars);
- for(int i=0,k=0;i<info.Length;i+=2,k++)
- {
- Rectangle c = new Rectangle(int.Parse(info[i]), int.Parse(info[i + 1]));
- ar[k] = c;
- }
- ar[0].Show();
- int per = ar[1].Perimetr();
- Console.WriteLine("Периметр равен {0}",per);
- int squar = ar[2].Square();
- Console.WriteLine("Площадь равна {0}", squar);
- if(ar[3].Quadrate)
- Console.WriteLine("прямоугольник является квадратом");
- int m = ar[4].Aleng;
- int n = ar[4].Bleng;
- Console.WriteLine("длина прямоугольника равна {0}, а ширина {1}",m,n);
- ar[0][1] = 5; //задаем новое значение ширины
- int t = ar[0][1];
- Console.WriteLine("ширина прямоугольника равна {0}", t);
- ar[1]++;
- ar[1].Show();
- ar[1]--;
- ar[1].Show();
- Rectangle s = ar[1] * 10;
- s.Show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement