/*.............. 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();case 2:
break;
a.SqrArea();default:
break;
Console.WriteLine("oops..!.............Wrong choice buddy, u can leave ");}
break;
Console.ReadLine();
}
}
Note:
steps to compile and execute
- save teh file with .cs extension (i.e) Area.cs
- compilation:
csc Area.cs
- execution:
Area.cs (or) Area.exe
Labels: C# Programming