C++ Program to find area of square using constructor
Program
#include <iostream>
#include<math.h>
#define PI 3.141
using namespace std;
class AreaSquare
{
private:
float area;
public:
AreaSquare(float side)
{
area = pow(side, 2);
}
void display()
{
cout << "Area:\t" << area << endl;
}
};
int main()
{
cout << "Enter value of side:\t";
float side;
cin >> side;
AreaSquare area(side);
area.display();
return 0;
}
Output
Enter value of side: 4.2
Area: 17.64