Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp7
- {
- class Rectangle
- {
- int a;
- int b;
- public Rectangle(int a, int b)
- {
- this.a = a;
- this.b = b;
- }
- public void Show()
- {
- Console.WriteLine("a={0}, b={1}", a, b);
- }
- public int Perim(int a, int b)
- {
- return (2 * (a + b));
- }
- public int Plosh(int a, int b)
- {
- return (a * b);
- }
- public int A
- {
- get
- {
- return a;
- }
- set
- {
- a = value;
- }
- }
- public int B
- {
- get
- {
- return b;
- }
- set
- {
- b = value;
- }
- }
- public string kvad
- {
- get
- {
- if (a == b)
- return "Является квадратом";
- else return "Не является квадратом";
- }
- }
- public int this[int i]
- {
- get
- {
- if ((i == 0))
- {
- return a;
- }
- else if ((i == 1))
- {
- return b;
- }
- else
- {
- Console.Write("Недопустимый индекс: {0}; возвращен ", i);
- return 0;
- }
- }
- set
- {
- if (i == 0)
- a = value;
- if (i == 1)
- b = value;
- if (i < 0 && i > 1)
- {
- Console.WriteLine("Недопустимый индекс");
- }
- }
- }
- public static Rectangle operator ++(Rectangle c)
- {
- Rectangle temp = new Rectangle(c.a+1, c.b+1);
- return temp;
- }
- public static Rectangle operator --(Rectangle c)
- {
- Rectangle temp = new Rectangle(c.a - 1, c.b - 1);
- return temp;
- }
- public static Rectangle operator *(Rectangle c, int x)
- {
- Rectangle temp = new Rectangle(c.a * x, c.b * x);
- return temp;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите, пожалуйста, a=");
- int a = int.Parse(Console.ReadLine());
- Console.Write("Введите, пожалуйста, b=");
- int b = int.Parse(Console.ReadLine());
- // конструктор экземпляра
- Rectangle oneRectangle = new Rectangle(a, b);
- Console.WriteLine("______________________________________");
- //вывод сторон треугольника
- oneRectangle.Show();
- Console.WriteLine("______________________________________");
- //вывод периметра
- Console.WriteLine("Периметр: {0}",oneRectangle.Perim(a, b));
- Console.WriteLine("______________________________________");
- //вывод площади
- Console.WriteLine("Площадь: {0}", oneRectangle.Plosh(a, b));
- Console.WriteLine("______________________________________");
- //свойство для записи и чтения сторон
- oneRectangle.A = a;
- oneRectangle.Show();
- Console.WriteLine("______________________________________");
- //свойство для чтения квадрат или нет
- Console.WriteLine(oneRectangle.kvad);
- Console.WriteLine("______________________________________");
- //индексы
- Console.WriteLine("Введите пожалуйста индексы:");
- Console.WriteLine();
- int i1 = int.Parse(Console.ReadLine());
- int i2 = int.Parse(Console.ReadLine());
- int i3 = int.Parse(Console.ReadLine());
- Console.WriteLine();
- Console.WriteLine("{0}", oneRectangle[i1]);
- Console.WriteLine("{0}", oneRectangle[i2]);
- Console.WriteLine("{0}", oneRectangle[i3]); Console.WriteLine();
- Console.WriteLine("______________________________________");
- //инкремент
- Console.Write("Инкремент: ");
- oneRectangle++;
- oneRectangle.Show();
- Console.WriteLine("______________________________________");
- //декремент
- Console.Write("Декремент: ");
- oneRectangle--;
- oneRectangle.Show();
- Console.WriteLine("______________________________________");
- //умножение на скаляр
- Console.Write("Умножение на скаляр (на 2): ");
- oneRectangle = oneRectangle * 2;
- oneRectangle.Show();
- Console.WriteLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment