Develop a C++ program to perform constructor overloading upon default, parameterized and copy constructors in a class named "Rectangle" and include member function for calculating area and perimeter of a rectangle.
#include<iostream>
using namespace std;
class Rectangle
{
private:
	float width;
	float height;
public:
	Rectangle(){
		this->width=0;
		this->height=0;
	}
	Rectangle(float width,float height){
		this->width=width;
		this->height=height;
	}
	// Copy constructor
	Rectangle(const Rectangle &rectangle) {
		this->width=rectangle.width;
		this->height=rectangle.height;
	}
	float area()
	{
		return width*height;
	}
	float perimeter()
	{
		return 2*(width+height);
	}
};
int main(){
	Rectangle rectangle1(4,5);
	Rectangle rectangle2(rectangle1);
	cout<<"Area of the rectangle 1: "<<rectangle1.area()<<"\n";
	cout<<"Area of the rectangle 1: "<<rectangle1.perimeter()<<"\n";
	cout<<"\nArea of the rectangle 2: "<<rectangle2.area()<<"\n";
	cout<<"Area of the rectangle 2: "<<rectangle2.perimeter()<<"\n";
	system("pause");
	return 0;
}
Comments