Beispiel #1
0
    static void Main(string[] args)
    {
        Squre     sqr = new Squre();
        Ractangle rac = new Ractangle();

        int g, p, e;

        Console.WriteLine("Квадрат розміру N:");
        g = Convert.ToInt32(Console.ReadLine());
        sqr.Drav(g);

        Console.WriteLine("Прямокутник висота і довжина відповідно:");
        p = Convert.ToInt32(Console.ReadLine());
        e = Convert.ToInt32(Console.ReadLine());
        rac.Drav(p, e);
        Console.ReadKey();
    }
Beispiel #2
0
        static void IsAEvil()
        {
            //квадрат частный случай прямоугольник
            //следовательно квадрат можно унаследовать от прямоугольника
            Rect rect = new Rect {
                Height = 2, Width = 5
            };
            int rectarea = AreaCalc.CalculateSquare(rect);

            Console.WriteLine($"React area = {rectarea}");

            //наследование
            //значит можно объявить базовым классом
            //А проинициализировать наследником

            //можем сделать разные стороны у квадрата :((
            Rect square = new Squre {
                Height = 2, Width = 10
            };

            AreaCalc.CalculateSquare(square);
            //нерепрезантивное наследование
            //реальность не соответсвует ООП
            //лучше использовать интрефейс

            IShape rect2 = new Rect2()
            {
                Height = 2, Width = 6
            };
            IShape square2 = new Squre2()
            {
                SideLength = 5
            };

            rect2.CalcSquare();
            square2.CalcSquare();
        }
        static void Main(string[] args)
        {
            /*Inheritance*/
            Area a1 = new Area();

            Console.WriteLine("ENTER HEIGHT");
            a1.Height = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("ENTER WIDTH");
            a1.Width = Convert.ToDouble(Console.ReadLine());
            a1.getdata(a1.Height, a1.Width);
            double area = a1.area();

            Console.WriteLine($"Area Of Rectengle IS :-  {area}");

            dog d1 = new dog();

            d1.eat();
            d1.sleep();
            d1.walk();

            /* Interface */
            IsFile s1 = new File();;

            Console.WriteLine("Please Enter The Content");
            string Content = Console.ReadLine();

            s1.Writing(Content);
            s1.Reading();

            File f1 = new File();

            f1.Reading();
            f1.Extra();
            f1.Writing(Content);

            /*Abstraction*/

            Console.WriteLine("RECTENGLE");
            Console.WriteLine("Enter THE Height");
            double height = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Enter The Width");
            double     width = Convert.ToDouble(Console.ReadLine());
            Rectenglee r1    = new Rectenglee(height, width);
            double     areaa = r1.GetArea();

            Console.WriteLine("Area Of Rectengle :-" + areaa);

            Console.WriteLine("Squre");
            Console.WriteLine("ENTER THE LENGTH");
            double length = Convert.ToDouble(Console.ReadLine());
            Squre  sq     = new Squre(length);
            double areaaa = sq.GetArea();

            Console.WriteLine("Area Of The Squre Is :-" + areaaa);

            /*Polymorphism*/

            Shape sh = new Shape();

            sh.draw();
            sh = new Tringle();
            sh.draw();
            sh = new Cube();
            sh.draw();
            sh = new Circle();
            sh.draw();
        }
 public static int CalculateSquare(Squre squre)
 {
     return(squre.Height * squre.Height);
 }