Assuming there is no error in main() complete the class Rectangle and its functions.
int main()
{
Rectangle rect1(3.4, 5.68);
Rectangle rect2(2.4, 4.68);
if (rect1-- != ++rect2) //increment/decrement will add & subtract by 1 of each data members of class
cout << ”\n Both are not of same size”;
else
cout << ”\n Both are of same size”;
rect1.show(); \\will display values 2.4, 4.68
Rectangle rect3 = rect1 + rect2;
rect3.show(); \\will display values 5.8, 10.36
system(“pause”);
return 0;
}
#include<iostream>
using namespace std;
class Rectangle{
	private:
	double width;
	double length;
	public:
		Rectangle(){
			
		}
		
		Rectangle(double l, double w){
			width = w;
			length = l;
		}
		Rectangle operator ++(){
			Rectangle r(this->length,this->width);
			r.length++ ;
			r.width++ ;
			return r;
		}
	
		Rectangle operator +(Rectangle & rec){
			Rectangle r(this->length,this->width);
			r.length = length + rec.length;
			r.width = width + rec.width;
			return r;
		}
		void show(){
			cout<<"The length is\t"<<length;
			cout<<"The width is\t"<<width;
		}
		bool operator !=(Rectangle rec){
		return (length != rec.length && width != rec.length);
		}
		Rectangle operator --(int){
		Rectangle  r;
		r.length = this->length--;
		r.width = this->width --;
		return r;
			
		}
	
};
Comments