Advertisement
myname0

10_3

Nov 13th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _10_2
  7. {
  8.     class Triangle
  9.     {
  10.         private int a;
  11.         private int b;
  12.         private int c;
  13.  
  14.         public Triangle()
  15.         {
  16.         }
  17.  
  18.         public Triangle(int a, int b, int c)
  19.         {
  20.             if (((a + b) > c) && ((b + c) > a) && ((a + c) > b))
  21.             {
  22.                 this.a = a;
  23.                 this.b = b;
  24.                 this.c = c;
  25.             }
  26.             else
  27.             {
  28.                 this.a = 1;
  29.                 this.b = 1;
  30.                 this.c = 1;
  31.                 Console.WriteLine("Triangle with these sides {0}, {1}, {2} can not be create, it will create triangle with sides of unit!", a, b, c);
  32.             }
  33.         }
  34.  
  35.         //public Triangle(int a, int b, int c)
  36.         //{
  37.         //        this.a = a;
  38.         //        this.b = b;
  39.         //        this.c = c;
  40.  
  41.         //}
  42.  
  43.         public void LengthsOfTheSide()
  44.         {
  45.             Console.WriteLine("Length of the first side: {0}", a);
  46.             Console.WriteLine("Length of the second side: {0}", b);
  47.             Console.WriteLine("Length of the third side: {0}", c);
  48.         }
  49.  
  50.         public int Perimeter()
  51.         {
  52.             return a + b + c;
  53.         }
  54.  
  55.         public double Square()
  56.         {
  57.             double S;
  58.             double p = ((double)(a + b + c)) / 2;
  59.             S = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
  60.             return S;
  61.         }
  62.  
  63.         public int A
  64.         {
  65.             get
  66.             {
  67.                 return a;
  68.             }
  69.  
  70.             set
  71.             {
  72.                 if (((value + b) > c) && ((b + c) > value) && ((value + c) > b))
  73.                     a = value;
  74.                 else Console.WriteLine("The side a can not be change");
  75.             }
  76.         }
  77.  
  78.         public int B
  79.         {
  80.             get
  81.             {
  82.                 return b;
  83.             }
  84.  
  85.             set
  86.             {
  87.                 if (((a + value) > c) && ((value + c) > a) && ((a + c) > value))
  88.                     b = value;
  89.                 else Console.WriteLine("The side b can not be change");
  90.             }
  91.         }
  92.  
  93.         public int C
  94.         {
  95.             get
  96.             {
  97.                 return c;
  98.             }
  99.  
  100.             set
  101.             {
  102.                 if (((a + b) > value) && ((b + value) > a) && ((a + value) > b))
  103.                     c = value;
  104.                 else Console.WriteLine("The side c can not be change");
  105.             }
  106.         }
  107.  
  108.         public bool IfTriangle
  109.         {
  110.             get
  111.             {
  112.                 if (((a + b) > c) && ((b + c) > a) && ((a + c) > b))
  113.                     return true;
  114.                 else return false;
  115.             }
  116.         }
  117.  
  118.         public int this[int i]
  119.         {
  120.             get
  121.             {
  122.                 if (i == 0) return a;
  123.                 else if (i == 1) return b;
  124.                 else if (i == 2) return c;
  125.                 else
  126.                 {
  127.                     Console.WriteLine("Inadmissible index!");
  128.                     return -1;
  129.                 }
  130.             }
  131.  
  132.             set
  133.             {
  134.                 if (i == 0)
  135.                 {
  136.                     if (((value + b) > c) && ((b + c) > value) && ((value + c) > b))
  137.                     a = value;
  138.                     else Console.WriteLine("The side [0] can not be change");
  139.                 }
  140.                 else if (i == 1)
  141.                 {
  142.                     if (((a + value) > c) && ((value + c) > a) && ((a + c) > value))
  143.                         b = value;
  144.                     else Console.WriteLine("The side [1] can not be change");
  145.                 }
  146.                 else if (i == 2)
  147.                 {
  148.                     if (((a + b) > value) && ((b + value) > a) && ((a + value) > b))
  149.                         c = value;
  150.                     else Console.WriteLine("The side [2] can not be change");
  151.                 }
  152.                 else Console.WriteLine("Inadmissible index!");
  153.             }
  154.  
  155.         }
  156.  
  157.         public static Triangle operator ++(Triangle tmp)
  158.         {
  159.             tmp.a++;
  160.             tmp.b++;
  161.             tmp.c++;
  162.             return tmp;
  163.         }
  164.  
  165.         public static Triangle operator --(Triangle tmp)
  166.         {
  167.             tmp.a--;
  168.             tmp.b--;
  169.             tmp.c--;
  170.             return tmp;
  171.         }
  172.  
  173.         public static bool operator true(Triangle tmp)
  174.         {
  175.             if (tmp.IfTriangle)
  176.                 return true;
  177.             else return false;
  178.         }
  179.  
  180.         public static bool operator false(Triangle tmp)
  181.         {
  182.             if (!tmp.IfTriangle)
  183.                 return false;
  184.             else return true;
  185.         }
  186.  
  187.         public static Triangle operator *(Triangle tmp, int x)
  188.         {
  189.             tmp.a *= x;
  190.             tmp.b *= x;
  191.             tmp.c *= x;
  192.             return tmp;
  193.         }
  194.     }
  195. }
  196.  
  197.  class Program
  198.     {
  199.         static void Main(string[] args)
  200.         {
  201.             Triangle first = new Triangle(4, 2, 5);
  202.             Triangle second = new Triangle(3, 4, 5);
  203.             Triangle third = new Triangle(1, 2, 3);
  204.  
  205.             first.LengthsOfTheSide();
  206.             Console.WriteLine("Perimetere of the first Triangle is: {0}", first.Perimeter());
  207.             Console.WriteLine("Square of the first Triangle is: {0,0}", first.Square());
  208.             first.Square();
  209.             first.A = 6;
  210.             first.B = 0;
  211.             first.C = 6;
  212.             first.LengthsOfTheSide();
  213.             first[0] = 9;
  214.             first[1] = 12;
  215.             first[2] = 7;
  216.             first.LengthsOfTheSide();
  217.             first++;
  218.             first.LengthsOfTheSide();
  219.             second--;
  220.             second.LengthsOfTheSide();
  221.             if (first) Console.WriteLine("Треугольник существует");
  222.             else Console.WriteLine("Треугольник не существует");
  223.             if (third) Console.WriteLine("Треугольник существует");
  224.             else Console.WriteLine("Треугольник  не существует");
  225.             Triangle four = second * 3;
  226.             four.LengthsOfTheSide();
  227.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement