Calculate the Area of  Triangle and Rectangle

 

using System;

 namespace Lab_Assignment

{

    abstract class Shape

    {

        protected int Lenght;

        protected int Width;

        protected int Areaoftriangle;

        protected int Areaofrectangle;

        public Shape()

        {

      }

        public Shape(int lenght,int width)

        {

            this.Lenght = lenght;

            this.Width = width;

        }

        public void Input()

        {

            Console.WriteLine(" value of Height:");

            Lenght = int.Parse(Console.ReadLine());

            Console.WriteLine(" value of Width:");

            Width = int.Parse(Console.ReadLine());

        }

        public abstract void CalculateSurface();

    }

    class Triangle:Shape

    {

 

        public override void CalculateSurface()

        {

            Areaoftriangle = Lenght * Width / 3;

            Console.WriteLine("Area Of Triangle is :{0}", Areaoftriangle);

        }

    }

    class Rectangle : Shape

    {

        public override void CalculateSurface()

        {

            Areaofrectangle = Lenght * Width;

            Console.WriteLine("Area Of Rectangle is :{0}",Areaofrectangle);

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            Shape shape = new Triangle();

            shape.Input();

            shape.CalculateSurface();

            Console.WriteLine("________________________");

            Shape shape1 = new Rectangle();

            shape1.Input();

            shape1.CalculateSurface();

        }

    }

}

Comments

Popular posts from this blog