C++ Program to find area of rectangle using constructor
Program
#include <iostream>
#include<math.h>
#define PI 3.141
using namespace std;
class AreaRectangle
{
private:
float area;
public:
AreaRectangle(float length, float breadth)
{
area = length * breadth;
}
void display()
{
cout << "Area:\t" << area << endl;
}
};
int main()
{
float length, breadth;
cout << "Enter the length:\t";
cin >> length;
cout << "Enter the breadth:\t";
cin >> breadth;
AreaRectangle area(length, breadth);
area.display();
return 0;
}
Output
Enter the length: 47.12
Enter the breadth: 3.61
Area: 170.103