0% found this document useful (0 votes)
4 views2 pages

C# Constructor Overloading for Area Calculation

The document contains a C# program demonstrating constructor overloading in a class named 'Area'. It calculates and displays the area of a square, rectangle, and circle using both default and parameterized constructors. The program prompts the user to input dimensions for the shapes and outputs the calculated areas accordingly.

Uploaded by

haniyamody02
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

C# Constructor Overloading for Area Calculation

The document contains a C# program demonstrating constructor overloading in a class named 'Area'. It calculates and displays the area of a square, rectangle, and circle using both default and parameterized constructors. The program prompts the user to input dimensions for the shapes and outputs the calculated areas accordingly.

Uploaded by

haniyamody02
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

using System;

using [Link];
using [Link];
using [Link];
using [Link];

namespace _5BCAConsoleApp
{
class Area
{
int side, length, breadth;
double radius;

public Area()
{
side = 20;
length = 10;
breadth = 30;
radius = 8;
[Link]("Using Default Constructor: ");
[Link]("Area of Square= "+ (side*side) + "[Link].");
[Link]("Area of Rectangle= " + (length * breadth) + "[Link].");
[Link]("Area of Circle= "+ (3.14*radius*radius) + "[Link].");
}

public Area(int s)
{
side = s;
[Link]("Area of Square= " + (side * side) + "[Link].");
}

public Area(int l, int b)


{
length = l;
breadth = b;
[Link]("Area of Rectangle= " + (length * breadth) + "[Link].");
}

public Area(double r)
{
radius = r;
[Link]("Area of Circle= " + (3.14 * radius * radius) + "[Link].");
}

}
class ConstructorOverloading
{
public static void Main()
{
int s, l, b;
double r;

Area ob = new Area();

[Link]();

[Link]("Using Parameterized Constructor: ");


[Link]("Enter the side of a square: ");
s = [Link]([Link]());

Area ob1 = new Area(s);

[Link]("Enter the length and breadth of the rectangle: ");


l = [Link]([Link]());
b = [Link]([Link]());

Area ob2 = new Area(l, b);

[Link]("Enter the radius of a circle: ");


r = [Link]([Link]());

Area ob3 = new Area(r);


}
}
}

You might also like