C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Question
Book Icon
Chapter 13, Problem 1PE
Program Plan Intro

Overloading Operators in rectangleType class

The following C++ program defines a class rectangleType and overloads various operators.

Blurred answer
Students have asked these similar questions
Implement a nested class composition relationship between any two class types from the following list: Advisor Вook Classroom Department Friend Grade School Student Teacher Tutor Write all necessary code for both classes to demonstrate a nested composition relationship including the following: a. one encapsulated data member for each class b. inline default constructor using constructor delegation for each class c. inline one-parameter constructor for each class d. inline accessors for all data members e. inline mutators for all data members
This chapter uses the class rectangleType to illustrate how to overload the operators +, *, ==, !=, >>, and <<. In this exercise, first redefine the class rectangleTypeby declaring the instance variables as protected and then overload additional operators as defined in parts 1 to 3. 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.) 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. 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…
... 5. Extend the Rectangle class by adding and implementing the special operator methods for the six relational operations (=, !-, , >=). The relational operators should logically compare the positions of two rectangles on the canvas by comparing the corresponding x- and y-coordinates. For example, the less than operator should determine whether the x- and y-coordinates of one rectangle are less than the x- and y-coordinates of a second rectangle. rectangle.py 1 class Rectangle : 2 #323 # Initializes a Rectangle object. # @param x the x-coordinate for the upper-left corner of the rectangle # @param y the y-coordinate for the upper-left corner of the rectangle # éparam width the width of the rectangle # éparam height the height of the rectangle 3 4 5 6 8 9 10 11 12 13 _init_(self, x, y, width, height): self._x = x self. y = y self. width = width self._height = height def 14 def lt (self, rhs): 15 16 17 18 19 20 ... # Include the new special operator methods here. 21
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning