Beispiel #1
0
        public static void Main(string[] args)
        {
            Model M = new Model();
            Triangle Trian = new Triangle();
            while (true)
            {
                Console.Clear();
                bool gonext = false;
                while (!gonext)
                {
                    //
                    Console.WriteLine("Enter A side in cm:");
                    var a = Console.ReadLine();
                    while (!a.HasNumberOnly())  //
                    {
                        Console.WriteLine("Wrong A. One more...");
                        a = Console.ReadLine();
                    }
                    double A = double.Parse(a);
                    //
                    Console.WriteLine("Enter B side in cm:");
                    var b = Console.ReadLine();
                    while (!b.HasNumberOnly())  //
                    {
                        Console.WriteLine("Wrong B. One more...");
                        b = Console.ReadLine();
                    }
                    double B = double.Parse(b); //
                    //
                    Console.WriteLine("Enter C side in cm:");
                    var c = Console.ReadLine();
                    while (!c.HasNumberOnly())
                    {
                        Console.WriteLine("Wrong C. One more...");
                        c = Console.ReadLine();
                    }
                    double C = double.Parse(c);

                    M.A = A; M.B = B; M.C = C;

                    gonext = Trian.IsValid(M);
                }

                // Calculate S triangle

                var square = Trian.Squre(M);
                Console.WriteLine("Square of triangle is {0} cm^2", square);
                Console.WriteLine("If You want calculate squre again with new sides enter \"Yes\", another - exit.");
                var ye = Console.ReadLine();
                if (!(ye == "Yes" || ye == "yes"))
                {
                    return;
                }

            }
        }
Beispiel #2
0
 public bool IsValid(Model mod)
 {
     if ((mod.A + mod.B > mod.C) && (mod.A + mod.C > mod.B) && (mod.C + mod.B > mod.A))
     {
         return true;
     }
     else
     {
         Console.WriteLine("Wrong size sides. Received figure is not a triangle");
     }
     return false;
 }
Beispiel #3
0
 private double SemiPerimetr(Model mod)
 {
     double p = (mod.A + mod.B + mod.C) / 2;
     return p;
 }
Beispiel #4
0
 public double Squre(Model mod)
 {
     double p = SemiPerimetr(mod);
     return S = Math.Sqrt(p * (p - mod.A) * (p - mod.B) * (p - mod.C));
 }