Write a program to print the area of two rectangles having sides (4,5) and (5,8) respectively by creating a class named 'Rectangle' with a function named 'Area' which returns the area. Length and breadth are passed as parameters to its constructor.( For C sharp with easy code)
using System;
namespace rectangle_class
{
class Rectangle
{
public int area;
public int side1;
public int side2;
public Rectangle(int side_a, int side_b)
{
side1 = side_a;
side2 = side_b;
}
public int Area()
{
area = side1 * side2;
return area;
}
}
class Program
{
public static void Main(string[] args)
{
Rectangle rectangle1 = new Rectangle(4, 5);
Rectangle rectangle2 = new Rectangle(5, 8);
Console.WriteLine("Area rectangle 1 = {0}", rectangle1.Area());
Console.WriteLine("Area rectangle 2 = {0}", rectangle2.Area());
Console.Write("\nPress any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment