Write a program to print the area of a rectangle by creating a class named 'Area' having two functions. First function named as 'setDim' takes the length and breadth of the rectangle as parameters and the second function named as 'getArea' returns the area of the rectangle. Length and breadth of the rectangle are entered through keyboard.( For C sharp with easy code)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputeAverageApp
{
class ComputeAverageProgram
{
static void Main(string[] args)
{
Area area = new Area();
Console.Write("Enter length: ");
int length = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter breadth: ");
int breadth = Convert.ToInt32(Console.ReadLine());
area.setDim(length, breadth);
Console.WriteLine("Area = {0}", area.getArea());
Console.ReadLine();
}
}
public class Area
{
int l;
int b;
public void setDim(int length, int breadth)
{
l = length;
b = breadth;
}
public int getArea()
{
return l * b;
}
}
}
Comments
Leave a comment