Answer to Question #326394 in C# for Chinara

Question #326394

7. Write a program to print the area of a rectangle by creating a class named 'Area' taking the values of its length and breadth as parameters of its constructor and having a function named 'returnArea' which returns the area of the rectangle. Length and breadth of the rectangle are entered through keyboard c#

1
Expert's answer
2022-04-10T05:24:15-0400
using System;
class Area
{
	double length;
	double breadth;
	public Area(double l, double d)
	{
		length = l;
		breadth = d;
	}


	public double ReturnArea()
	{
		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(length, breadth);
			Console.WriteLine($"Area of the rectangle: {area.ReturnArea()}");
		}
		catch (Exception ex)
		{
			Console.WriteLine($"{ex.Message} 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