Advertisement
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;
- namespace _10_2
- {
- class Triangle
- {
- private int a;
- private int b;
- private int c;
- public Triangle()
- {
- }
- public Triangle(int a, int b, int c)
- {
- if (((a + b) > c) && ((b + c) > a) && ((a + c) > b))
- {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- else
- {
- this.a = 1;
- this.b = 1;
- this.c = 1;
- Console.WriteLine("Triangle with these sides {0}, {1}, {2} can not be create, it will create triangle with sides of unit!", a, b, c);
- }
- }
- //public Triangle(int a, int b, int c)
- //{
- // this.a = a;
- // this.b = b;
- // this.c = c;
- //}
- public void LengthsOfTheSide()
- {
- Console.WriteLine("Length of the first side: {0}", a);
- Console.WriteLine("Length of the second side: {0}", b);
- Console.WriteLine("Length of the third side: {0}", c);
- }
- public int Perimeter()
- {
- return a + b + c;
- }
- public double Square()
- {
- double S;
- double p = ((double)(a + b + c)) / 2;
- S = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
- return S;
- }
- public int A
- {
- get
- {
- return a;
- }
- set
- {
- if (((value + b) > c) && ((b + c) > value) && ((value + c) > b))
- a = value;
- else Console.WriteLine("The side a can not be change");
- }
- }
- public int B
- {
- get
- {
- return b;
- }
- set
- {
- if (((a + value) > c) && ((value + c) > a) && ((a + c) > value))
- b = value;
- else Console.WriteLine("The side b can not be change");
- }
- }
- public int C
- {
- get
- {
- return c;
- }
- set
- {
- if (((a + b) > value) && ((b + value) > a) && ((a + value) > b))
- c = value;
- else Console.WriteLine("The side c can not be change");
- }
- }
- public bool IfTriangle
- {
- get
- {
- if (((a + b) > c) && ((b + c) > a) && ((a + c) > b))
- return true;
- else return false;
- }
- }
- public int this[int i]
- {
- get
- {
- if (i == 0) return a;
- else if (i == 1) return b;
- else if (i == 2) return c;
- else
- {
- Console.WriteLine("Inadmissible index!");
- return -1;
- }
- }
- set
- {
- if (i == 0)
- {
- if (((value + b) > c) && ((b + c) > value) && ((value + c) > b))
- a = value;
- else Console.WriteLine("The side [0] can not be change");
- }
- else if (i == 1)
- {
- if (((a + value) > c) && ((value + c) > a) && ((a + c) > value))
- b = value;
- else Console.WriteLine("The side [1] can not be change");
- }
- else if (i == 2)
- {
- if (((a + b) > value) && ((b + value) > a) && ((a + value) > b))
- c = value;
- else Console.WriteLine("The side [2] can not be change");
- }
- else Console.WriteLine("Inadmissible index!");
- }
- }
- public static Triangle operator ++(Triangle tmp)
- {
- tmp.a++;
- tmp.b++;
- tmp.c++;
- return tmp;
- }
- public static Triangle operator --(Triangle tmp)
- {
- tmp.a--;
- tmp.b--;
- tmp.c--;
- return tmp;
- }
- public static bool operator true(Triangle tmp)
- {
- if (tmp.IfTriangle)
- return true;
- else return false;
- }
- public static bool operator false(Triangle tmp)
- {
- if (!tmp.IfTriangle)
- return false;
- else return true;
- }
- public static Triangle operator *(Triangle tmp, int x)
- {
- tmp.a *= x;
- tmp.b *= x;
- tmp.c *= x;
- return tmp;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Triangle first = new Triangle(4, 2, 5);
- Triangle second = new Triangle(3, 4, 5);
- Triangle third = new Triangle(1, 2, 3);
- first.LengthsOfTheSide();
- Console.WriteLine("Perimetere of the first Triangle is: {0}", first.Perimeter());
- Console.WriteLine("Square of the first Triangle is: {0,0}", first.Square());
- first.Square();
- first.A = 6;
- first.B = 0;
- first.C = 6;
- first.LengthsOfTheSide();
- first[0] = 9;
- first[1] = 12;
- first[2] = 7;
- first.LengthsOfTheSide();
- first++;
- first.LengthsOfTheSide();
- second--;
- second.LengthsOfTheSide();
- if (first) Console.WriteLine("Треугольник существует");
- else Console.WriteLine("Треугольник не существует");
- if (third) Console.WriteLine("Треугольник существует");
- else Console.WriteLine("Треугольник не существует");
- Triangle four = second * 3;
- four.LengthsOfTheSide();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement