Разработать класс «Прямоугольник» - C#

Узнай цену своей работы

Формулировка задачи:

Разработать класс «Прямоугольник», осуществить перегрузку операций сложения, сравнения. Как осуществить операцию перегрузку сложения?

Решение задачи: «Разработать класс «Прямоугольник»»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.     class Rectangle
  11.     {
  12.         public int a;
  13.         public int b;
  14.  
  15.         public Rectangle(int a, int b)
  16.         {
  17.             this.a = a;
  18.             this.b = b;
  19.  
  20.         }
  21.  
  22.         public  int countPerimetr()
  23.         {
  24.  
  25.             int perimetr = a*2 + b*2;
  26.  
  27.             return perimetr;
  28.         }
  29.  
  30.         public int countPerimetr(int x,int y)
  31.         {
  32.  
  33.             int perimetr = x * 2 + y * 2;
  34.  
  35.             return perimetr;
  36.         }
  37.  
  38.  
  39.         public void compareSides()
  40.  
  41.         {
  42.             if (a > b)
  43.             {
  44.                 Console.WriteLine("Сторона а>b");
  45.             }
  46.             else if (a < b)
  47.             {
  48.                 Console.WriteLine("Сторона b>a");
  49.             }
  50.             else
  51.             {
  52.                 Console.WriteLine("Это квадрат");
  53.             }
  54.  
  55.            
  56.         }
  57.  
  58.         public void compareSides(int x, int y)
  59.  
  60.         {
  61.             if (x > y)
  62.             {
  63.                 Console.WriteLine("Сторона а>b");
  64.             }
  65.             else if (y > x)
  66.             {
  67.                 Console.WriteLine("Сторона b>a");
  68.             }
  69.             else
  70.             {
  71.                 Console.WriteLine("Это квадрат");
  72.             }
  73.  
  74.  
  75.         }
  76.  
  77.  
  78.     }
  79. }
  80.  
  81. using System;
  82. using System.Collections.Generic;
  83. using System.Globalization;
  84. using System.Linq;
  85. using System.Text;
  86. using System.Threading.Tasks;
  87.  
  88. namespace ConsoleApplication1
  89. {
  90.     class Program
  91.     {
  92.    
  93.  
  94.  
  95.         public static int input()
  96.         {
  97.            
  98.             int a = int.Parse(Console.ReadLine());
  99.             return a;
  100.  
  101.         }
  102.  
  103.  
  104.  
  105.         static void Main(string[] args)
  106.         {
  107.  
  108.           Console.WriteLine("введите сторону а:");  int a = input();
  109.             Console.WriteLine("введите сторону b=:"); int b = input();
  110.             Rectangle rect=new Rectangle(a,b);  
  111.             rect.compareSides();
  112.            Console.WriteLine("Периметр ={0}",rect.countPerimetr());
  113.             Console.WriteLine("Вызов перегруженных методов");
  114.             rect.compareSides(rect.a,rect.b);
  115.           Console.WriteLine("Периметр ={0}", rect.countPerimetr(rect.a, rect.b));  
  116.  
  117.             Console.ReadKey();
  118.         }
  119.     }
  120. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

12   голосов , оценка 3.833 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы