We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Thursday, June 25, 2015

     Create Structure to display different types of shapes like  triangle , rectangle and square. Whenever we select particular shape it has to display specific values of shape like  length, height,  area and perimeter.
 struct Shape
    {
        public int lenght;
        public int width;
        public int bas;
        public int height;
        public int side;
        public int side1;
        public int side2;
        public double area;
        public int perimeter;

        public void Ractangle()
        {
            Console.WriteLine("Enter the lenth of the ractangle");
            lenght = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the width of the ractangle");
            width = int.Parse(Console.ReadLine());
            area = lenght * width;
            perimeter = 2*(lenght + width);
            Console.WriteLine("Lenght of the ractangle:{0}", lenght);
            Console.WriteLine("Width of the ractanle:{0} ", width);
            Console.WriteLine("Area of the Ractangle:{0} ", area);
            Console.WriteLine("Perimeter of the ractangle:{0} ", perimeter);
        }
        public void Tringle()
        {
            Console.WriteLine("Enter the base of the triangle");
            bas = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the hight of the triangle");
            height = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the first side");
            side1 = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the second side");
            side2 = int.Parse(Console.ReadLine());
            area = 0.5 * bas * height;
            perimeter = bas + side1 + side2;
            Console.WriteLine("First side of the triangle:{0} ", side1);
            Console.WriteLine("Second side of the triangle:{0} ", side2);
            Console.WriteLine("Hight of the triangle:{0} ", height);
            Console.WriteLine("Base of the triangle:{0} ", bas);
            Console.WriteLine("Area of the trianlge:{0} ", area);
            Console.WriteLine("Perimeter of the triangle:{0} ", perimeter);
        }
        public void Squre()
        {
            Console.WriteLine("Enter the side of the Squre");
            side = int.Parse(Console.ReadLine());
            area = side * side;
            perimeter = 4 * side;
            Console.WriteLine("Side of the Squre:{0} ", side);
            Console.WriteLine("Area of the Squre:{0} ", area);
            Console.WriteLine("Perimeter of the Squre:{0}", perimeter);
        }
        static void Main(string[] args)
        {
            Shape sap=new Shape();
            Console.WriteLine("Select the shape");
            Console.WriteLine("1-Ractangle");
            Console.WriteLine("2-Triangle");
            Console.WriteLine("3-Squre");
            Console.WriteLine("So please select any one");
            int input = int.Parse(Console.ReadLine());
            switch(input)
            {
                case 1:
                    sap.Ractangle();
                    break;
                case 2:
                    sap.Tringle();
                    break;
                case 3:
                    sap.Squre();
                    break;
                default :
                    Console.WriteLine("Invalid option");
                    break;
            }
            Console.ReadLine();
        }
    }
output:

No comments: