Разработать класс «Прямоугольник» - C#
Формулировка задачи:
Разработать класс «Прямоугольник», осуществить перегрузку операций сложения, сравнения. Как осуществить операцию перегрузку сложения?
Решение задачи: «Разработать класс «Прямоугольник»»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Rectangle
{
public int a;
public int b;
public Rectangle(int a, int b)
{
this.a = a;
this.b = b;
}
public int countPerimetr()
{
int perimetr = a*2 + b*2;
return perimetr;
}
public int countPerimetr(int x,int y)
{
int perimetr = x * 2 + y * 2;
return perimetr;
}
public void compareSides()
{
if (a > b)
{
Console.WriteLine("Сторона а>b");
}
else if (a < b)
{
Console.WriteLine("Сторона b>a");
}
else
{
Console.WriteLine("Это квадрат");
}
}
public void compareSides(int x, int y)
{
if (x > y)
{
Console.WriteLine("Сторона а>b");
}
else if (y > x)
{
Console.WriteLine("Сторона b>a");
}
else
{
Console.WriteLine("Это квадрат");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public static int input()
{
int a = int.Parse(Console.ReadLine());
return a;
}
static void Main(string[] args)
{
Console.WriteLine("введите сторону а:"); int a = input();
Console.WriteLine("введите сторону b=:"); int b = input();
Rectangle rect=new Rectangle(a,b);
rect.compareSides();
Console.WriteLine("Периметр ={0}",rect.countPerimetr());
Console.WriteLine("Вызов перегруженных методов");
rect.compareSides(rect.a,rect.b);
Console.WriteLine("Периметр ={0}", rect.countPerimetr(rect.a, rect.b));
Console.ReadKey();
}
}
}