English, asked by itcompengmy2342, 3 months ago

Write A program in C++ to Find the Area of the Square?
( Using Class and Constructor and Destructor)

Answers

Answered by ferozpurwale
6

Answer:

uctors have same name of the class but with number of arguments. Constructors can be overloaded.

Following program is displaying the work of overloaded constructors.

#include<iostream>

#include<math.h>

#include<cstdlib>

using namespace std;

class area

{

float ar;

public:

area(float r)

{

ar=3.14*r*r;

}

area(float l, float b)

{

ar=l*b;

}

area(float a, float b, float c)

{

float s;

s=(a+b+c)/2;

ar=s*(s-a)*(s-b)*(s-c);

ar=pow(ar,0.5);

}

void display()

{

cout<<"\n Area : "<<ar;

}

};

int main()

{

int ch;

float x, y, z;

do

{

<<"\n\n 1. Area of Circle";

cout<<"\n 2. Area of Rectangle";

cout<<"\n 3. Area of Triangle";

cout<<"\n 4. Exit";

cout<<"\n\n Enter Your Choice : ";

cin>>ch;

Similar questions