Create a console-based application named Area. Include
three overloaded methods that compute the area of a
rectangle when two dimensions are passed to it. One
method takes two integers as parameters, one takes two
doubles, and the third takes an integer and a double.
Write a Main() method that demonstrates each method
works correctly.
I have done this
Console.WriteLine("Enter the hight of the rectangle:");
double stNumber = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the hight of the rectangle:");
double ndNumber = Convert.ToDouble(Console.ReadLine());
AreaOfRectangle(ref stNumber, ref ndNumber);
}
static void AreaOfRectangle(ref int length,ref int width)
{
int area;
area = length * width;
Console.WriteLine("The area of rectangle is {0}", area);
}
static void AreaOfRectangle(ref double length,ref double width)
{
double area;
area = length * width;
Console.WriteLine("The area of rectangle is {0}", area);
}
static void AreaOfRectangle(ref int length,ref double width)
{
double area;
area = length * width;
Console.WriteLine("The area of rectangle is {0}", area);
}
You think there's better way to do it?
Loading
VulpesPosted Jan 16, 2012, 4:36 AM
You need to demonstrate that overload resolution works correctly with all three.
Also you don't need 'ref' parameters here as you're not persisting changes to the calling method.
Taking these points into account, I'd suggest the following: