/*.............. Progr@m to calculate area of rectangle and square.........*/

using System;

class Area
{
static int res;//.............declaring static variable.

public static void RecArea()//........... defining a static func.
{
int l, b;

Console.WriteLine("Enter the length :\t");
l=Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter the breadth :\t");
b=Convert.ToInt32(Console.ReadLine());

res=l*b;
Console.WriteLine("The area of a rectangle is :{0}",res);

// (or) Console.WriteLine("The area of rectangle is :\t"+res);
}
public static void SqrArea()//........... defining a static func.
{
int side;

Console.WriteLine("Enter the side of the square:\t");
side=Convert.ToInt32(Console.ReadLine());

res=side*side;
Console.WriteLine("The area of a square is :{0}",res);
}
}
class Result
{
public static void Main(string [] arg)
{
int option;
Area a=new Area();

Console.WriteLine("Main Menu");
Console.WriteLine("1. Area of Rectangle ");
Console.WriteLine("2. Area of Square ");
Console.WriteLine("Enter the option :\t");
option=Convert.ToInt32(Console.ReadLine());

switch(option)
{
case 1:

a.RecArea();
break;
case 2:
a.SqrArea();
break;
default:
Console.WriteLine("oops..!.............Wrong choice buddy, u can leave ");
break;
}
Console.ReadLine();
}
}

Note:

steps to compile and execute
  1. save teh file with .cs extension (i.e) Area.cs
  2. compilation:
    csc Area.cs
  3. execution:
    Area.cs (or) Area.exe

0 Comments:

Post a Comment



Newer Post Older Post Home