Answer on Question #45145, Engineering, Other
Task: Write a program that computes the perimeter and the area of a rectangle. Define your own values for the length and width. (Assuming that L and W are the length and width of the rectangle, Perimeter = 2*(L+W) and Area = L*W.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication30
{
class Rectangle
{
double Length, Width;
double area;
public Rectangle(double L, double W)
{
Length = L;
Width = W;
}
public double Area(double L, double W)
{
return L * W;
}
public double Perimeter(double L, double W)
{
return 2 * (L + W);
}
}
```
class Program
{
static void Main(string[] args)
{
double L, W;
Console.Write("Enter Length: ");
L = double.Parse( Console.ReadLine());
Console.Write("Enter Width: ");
W = double.Parse(Console.ReadLine());
}
Rectangle r = new Rectangle(L,W);
Console.WriteLine("Area of Rectangle:" + r.Area(L,W));
Console.WriteLine("Perimeter of Rectangle:" + r.Perimeter(L, W));
Console.ReadLine();
}
http://www.AssignmentExpert.com/
Comments