This chapter uses the class rectangletype to illustrate how


This chapter uses the class rectangleType to illustrate how to overload the operators +, *, ==, !=, >>, and <<. In this assignment, first redefine the class rectangleType by declaring the instance variable 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. (Note that after decrementing the length and width, they must be positive.)

(b) Overload the binary operator - to subtract the dimensions of one rectangle from the corresponding dimensions of another rectangle. If the resulting dimensions are not positive, output an appropriate message and do not perform the operation.

(c) The operators == and != are overloaded by considering the lengths and widths of rectangles. Redefine the functions to overload the relational operator by considering the areas of rectangles as follows: Two rectangles are the same, if they have the same area; otherwise, the rectangles are not the same. Similarly, rectangle yard1 is greater than rectangle yard2 if the area of yard1 is greater than the area of yeard2. Overload the remaining relational operators using similar definition.

(d) Write the definitions of the functions to overload the operators defined in parts a to c.

(e) Write a test program that tests various operations on the class rectangleType.

Solution Preview :

Prepared by a verified Expert
Business Management: This chapter uses the class rectangletype to illustrate how
Reference No:- TGS02179484

Now Priced at $20 (50% Discount)

Recommended (92%)

Rated (4.4/5)