Answer to Question #325628 in C# for Zarifa

Question #325628

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)

1
Expert's answer
2022-04-09T17:55:20-0400
using System;
class Area
{
	double length;
	double breadth;
	public void SetDim(double l, double d)
    {
		this.length = l;
		this.breadth = d;
    }

	public double GetArea()
    {
		return length * breadth;
    }
}
class Program
{
	static void Main(String[] args)
	{
        try
        {
            Console.Write("Length: ");
			double length = Double.Parse(Console.ReadLine());
			Console.Write("Breadth: ");
			double breadth = Double.Parse(Console.ReadLine());
			Area area = new Area();
			area.SetDim(length, breadth);
			Console.WriteLine($"Area of the rectangle: {area.GetArea()}");
		}
		catch(Exception ex)
        {
            Console.WriteLine("Try again!");
        }
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS