2-Write a C# application that asks the user to input the required data to implem
ID: 3772248 • Letter: 2
Question
2-Write a C# application that asks the user to input the required data to implement thefour methods below:
(Use Method Overloading to write the methods)
Method Area that take as input an int value ‘side’, calculates the area of a square, and displays it.
Method Area that take as input an int value ‘L’ and an int value ‘B’, calculates the area of a rectangle, and displays it.
Method Area that takes as input a double value ‘R’, calculates the area of a circle, and displays it.
Method Area that take as input a double value ‘B’, and a double value ‘H’, calculates the area of a triangle, and displays it.
Enter the side of the square: Enter the length of the rectangle: 1 Enter the breadth of the rectangle: 20 Enter the radius of the circle: 10.5 Enter the base of the triangle: 15.5 Enter the height of the triangle: 20.4 The area of square is 225 The area of rectangle is 200 The area of circle is 346.185 The area of triange is 158.1Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace methods_for_area
{
class Program
{
static void area(int side)
{
int a = side * side;
Console.WriteLine("The area of square is " + a);
}
static void area(int l, int b)
{
int a = l * b;
Console.WriteLine("The area of rectangle is " + a);
}
static void area(double r)
{
double a = 3.142*r*r;
Console.WriteLine("The area of circle is " + a);
}
static void area(double b, double h)
{
double a = 0.5 * b * h;
Console.WriteLine("The area of triangle is " + a);
}
static void Main(string[] args)
{
int s, l, b;
double r, br, h;
Console.WriteLine("Enter the side of the sqaure");
s = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the length of the rectangle");
l = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the breadth of the rectangle");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the radius of the circle");
r = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the base of the triangle");
br = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the height of the triangle");
h = Convert.ToDouble(Console.ReadLine());
area(s);
area(l, b);
area(r);
area(br, h);
Console.ReadKey();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.