Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using CoolerLibrary;
- namespace Lab10
- {
- public class Triangle
- {
- private double _a;
- private double _b;
- private double _c;
- static int _count = 0;
- public double A
- {
- set
- {
- try
- {
- if (value <= 0)
- {
- Console.WriteLine("Length must be more than 0");
- }
- else
- {
- _a = value;
- }
- }
- catch
- {
- Console.WriteLine("can't setup the side");
- }
- }
- get { return _a; }
- }
- public double B
- {
- set
- {
- try
- {
- if (value <= 0)
- {
- throw new Exception("Length must be more than 0");
- }
- else
- {
- _b = value;
- }
- }
- catch
- {
- Console.WriteLine("can't setup the side");
- }
- }
- get { return _b; }
- }
- public double C
- {
- set
- {
- try
- {
- if (value <= 0)
- {
- throw new Exception("Length must be more than 0");
- }
- else
- {
- _c = value;
- }
- }
- catch
- {
- Console.WriteLine("can't setup the side");
- }
- }
- get { return _c; }
- }
- public Triangle(double a, double b, double c)
- {
- this._a = a;
- this._b = b;
- this._c = c;
- _count++;
- }
- public Triangle(Random rnd)
- {
- //Random rnd= new Random();
- this.A = rnd.Next(1, 30);
- this.B = rnd.Next(1, 30);
- this.C = rnd.Next(1, 30);
- _count++;
- }
- public static int Count
- {
- get { return _count; }
- }
- public override string ToString()
- {
- string s = System.String.Format("a={0,2}, b={1,2}, c={2,2}",_a,_b,_c);
- return s;
- }
- public double Square()
- {
- if ((_a + _b > _c) && (_b + _c > _a) && (_a + _c > _b))
- {
- double p = (_a + _b + _c) / 2.0;
- return Math.Sqrt(p * (p - _a) * (p - _b) * (p - _c));
- }
- else
- {
- return -1;
- }
- }
- public static Triangle operator ++(Triangle triangle)
- {
- triangle._a++;
- triangle._b++;
- triangle._c++;
- return triangle;
- }
- public static Triangle operator --(Triangle triangle)
- {
- try
- {
- triangle._a--;
- triangle._b--;
- triangle._c--;
- if (triangle._a * triangle._b * triangle._c == 0 || triangle._a * triangle._b * triangle._c < 0)
- {
- throw new Exception("Side can't be smaller 0");
- }
- else
- {
- return triangle;
- }
- }
- catch
- {
- Console.WriteLine("EXCEPTION: Side can't be smaller 0, no decrease");
- return triangle++;
- }
- }
- public static bool operator >(Triangle tr1, Triangle tr2)
- {
- bool flag = false;
- if (tr1.Square() > tr2.Square() && tr1.Square() > 0)
- {
- flag = true;
- }
- else
- {
- try
- {
- if (tr2.Square() > 0)
- {
- flag = false;
- }
- else
- {
- throw new SystemException("This value can't be matched");
- }
- }
- catch
- {
- Console.WriteLine("EXCEPTION:This value can't be matched");
- }
- }
- return flag;
- }
- public static bool operator <(Triangle tr1, Triangle tr2)
- {
- bool flag = false;
- if (tr1.Square() > tr2.Square() && tr1.Square() > 0)
- {
- flag = false;
- }
- else
- {
- try
- {
- if (tr2.Square() > 0)
- {
- flag = true;
- }
- else
- {
- throw new SystemException("This value can't be matched");
- }
- }
- catch
- {
- Console.WriteLine("This value can't be matched");
- }
- }
- return flag;
- }
- public static implicit operator double(Triangle tr)
- {
- return tr.Square();
- }
- public static explicit operator bool(Triangle tr)
- {
- if (tr.Square() > 0)
- return true;
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement