Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Diameter, Circumference and Area of a Circle) Write a C# method that has one pa

ID: 3716627 • Letter: #

Question

(Diameter, Circumference and Area of a Circle) Write a C# method that has one parameter (named radius) and a return statement that returns the area of a circle.

This method is an instance method (NOT a static function), and will perform the following operations:

? Define a local variable named localRadius and a local variable named area;

? Assign the parameter radius to the local variable localRadius;

? Calculate the area of the circle, the formula of which is area = ?r 2 ;

? Return the area in its return statement.

Then, in the main method, define two variables( named mradius and marea).

The main method creates an instance of the class by calling the default constructor which calls the method above and pass mradius to the method.

After the statements in the method are done, the returned value from the method is assigned to marea. The main method prints the value of marea (using Console.WriteLine())

Explanation / Answer

class Program
{
public double findArea(double radius)
{
double localRadius, area;
localRadius = radius;
area = Math.PI * localRadius * localRadius;
return area;
}
static void Main(string[] args)
{
Program p = new Program();
double mradius, marea;
Console.Write("Enter the radius : ");
mradius = Double.Parse(Console.ReadLine());
marea = p.findArea(mradius);
Console.WriteLine(marea);
Console.Read();
}
  
}

OUTPUT:

Enter the radius : 5
78.5398163397448