Use the class rectangletype to illustrate how to overload the operators +,*, ==,
ID: 3654276 • Letter: U
Question
Use the class rectangletype to illustrate how to overload the operators +,*, ==, !=, >> and <<. First redefine the class rectangletype by declaring the instance variables as protected and then overload additional operators as defined in parts a to c a) Overload the pre- and post-increment and decrement operators to increment and decrement, respectively, the length and width of a rectangle by one unit. b) Overload the binary operatorExplanation / Answer
#ifndef H_rectangleType #define H_rectangleType #include using namespace std; class rectangleType { //Overload the stream insertion and extraction operators friend ostream& operator > (istream&, rectangleType &); public: void setDimension(double l, double w); double getLength() const; double getWidth() const; double area() const; double perimeter() const; void print() const; rectangleType operator+(const rectangleType&) const; //Overload the operator + rectangleType operator*(const rectangleType&) const; //Overload the operator * bool operator==(const rectangleType&) const; //Overload the operator == bool operator!=(const rectangleType&) const; //Overload the operator != rectangleType(); rectangleType(double l, double w); private: double length; double width; }; #endifRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.