Answer to Question #325953 in C# for Zarifa

Question #325953

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)


1
Expert's answer
2022-04-11T12:12:45-0400
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);
        }
    }
}

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