//метод множення координат ромба на число private static Rhombus Multiply(Rhombus rhomb, double number) { if (number < 0) { throw new Exception("Ne mojna mnojiti na menshe nulya"); } else { Rhombus result = new Rhombus(rhomb); result.A.x = result.A.x * Math.Sqrt(number); result.A.y = result.A.y * Math.Sqrt(number); result.B.x = result.B.x * Math.Sqrt(number); result.B.y = result.B.y * Math.Sqrt(number); result.C.x = result.C.x * Math.Sqrt(number); result.C.y = result.C.y * Math.Sqrt(number); result.C.x = result.C.x * Math.Sqrt(number); result.C.y = result.C.y * Math.Sqrt(number); return(result); } }
//перезавантаження оператору віднімання для віднімання площ public static Rhombus operator -(Rhombus first, Rhombus second) { Rhombus temp = new Rhombus(); double subtraction = first.Square - second.Square; temp = first * (subtraction / first.Square); return temp; }
//Конструктор №3 public Rhombus(Rhombus other) { A.x = other.A.x; A.y = other.A.y; B.x = other.B.x; B.y = other.B.y; C.x = other.C.x; C.y = other.C.y; D.x = other.D.x; D.y = other.D.y; }
//перезавантаження оператору віднімання для віднімання площ public static Rhombus operator -(Rhombus first, Rhombus second) { if (first.Square == 0) { throw new DivideByZeroException("square = 0"); } else { Rhombus temp = new Rhombus(); double subtraction = first.Square - second.Square; temp = first * (subtraction / first.Square); return(temp); } }
//метод множення координат ромба на число private static Rhombus Multiply(Rhombus rhomb, double number) { Rhombus result = new Rhombus(rhomb); result.A.x = result.A.x * Math.Sqrt(number); result.A.y = result.A.y * Math.Sqrt(number); result.B.x = result.B.x * Math.Sqrt(number); result.B.y = result.B.y * Math.Sqrt(number); result.C.x = result.C.x * Math.Sqrt(number); result.C.y = result.C.y * Math.Sqrt(number); result.C.x = result.C.x * Math.Sqrt(number); result.C.y = result.C.y * Math.Sqrt(number); return result; }
static void Main(string[] args) { Rhombus P1 = new Rhombus(); Rhombus P2 = new Rhombus(2, 0, 4, 2, 6, 0, 4, -2); Rhombus P3 = new Rhombus( P2 * 2); Console.WriteLine("Kovalenko Yevhen Is-93 Variant #10"); Console.WriteLine("Perimetr of P1 rhombus: " + P1.Perimetr.ToString("0.00")); Console.WriteLine("Perimetr of P2 rhombus: " +P2.Perimetr.ToString("0.00")); Console.WriteLine("Perimetr of P3 rhombus: " + P3.Perimetr.ToString("0.00")); Console.WriteLine("Square of P1 rhombus: " + P1.Square.ToString("0.00")); Console.WriteLine("Square of P2 rhombus: " + P2.Square.ToString("0.00")); Console.WriteLine("Square of P3 rhombus: " + P3.Square.ToString("0.00")); P1 = P3 - P2; Console.WriteLine("Square of P1 rhombus: " + P1.Square.ToString("0.00")); Console.ReadKey(); }
//перезавантаження оператору множення public static Rhombus operator *(Rhombus rhomb, double number) { Rhombus temp = Rhombus.Multiply(rhomb, number); return temp; }