Answer to Question #325627 in C# for Zarifa

Question #325627

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)

1
Expert's answer
2022-04-09T17:55:23-0400
using System;

namespace ConsoleApp1
{
    class Program
    {
        public class Rectangle
        {
            double l, b;
            public Rectangle(double length, double breadth)
            {
                l = length;
                b = breadth;
            }
            public double Area()
            {
                return l * b;
            }
        }

        static void Main(string[] args)
        {
            Rectangle rect1 = new Rectangle(4, 5);
            Rectangle rect2 = new Rectangle(5, 8);

            Console.WriteLine("Area of the first rectangle: {0}", rect1.Area());
            Console.WriteLine("Area of the second rectangle: {0}", rect2.Area());
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS