Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 operator

Explanation / 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; }; #endif