Thursday, 2 May 2013

Calculate rectangle | square | triangle and circle in C#

Calculate rectangle | square | triangle and circle in C#

Object


Write a program which offers the user options to calculate area of different shapes including rectangle, square, triangle and circle. Pass the required parameters to the functions to return calculated area for shape selected by the user.

Code


public class program2
    {
         double res=0;
       public static double area(int num, int r)
        {
         
       
             Console.Write("Result is ::");
              res = 3.14 * r * r;

              return res;
        }
       Public static double radius(int num, int r)
       {

          Console.Write("Result is ::");
           res = 2 * 3.14 * r;
           return res;
       }
       Public static double diameter(int num, int d)
       {

           Console.Write("Result is ::");
           res = d / 2;
           return res;
       }


    }

int num, r, d;
               


                Console.WriteLine("1....for Area Calculate");
                Console.WriteLine("2....for Radius Calculate");
                Console.WriteLine("3....for Diameter Calculate");

                Console.WriteLine("Enter The Number What You Want ?");
                num = int.Parse(Console.ReadLine());
                switch (num)
                {
                    case 1:
                        {
                            Console.Write("Enter The value :: ");
                            r = int.Parse(Console.ReadLine());
                           
                           double print= program.area(num, r);
                           Console.Write(+print);
                            break;
                        }
                    case 2:
                        {
                            Console.Write("Enter The value :: ");
                            r = int.Parse(Console.ReadLine());
                            
                           double print= program.radius(num, r);
                            Console.Write(+print);
                            break;
                        }
                    case 3:
                        {
                            Console.Write("Enter The value :: ");
                            d = int.Parse(Console.ReadLine());

                           double print program.diameter(num, d);
                           Console.Write(+print);
                            break;
                        }
                    default:
                        {
                            Console.Write("Enter The Correct Number/n ");
                            break;
                        }

                }

Screen Shot 

No comments:

Post a Comment