Exercise 3: Consider a rectangle class that contains two attributes (length and width of real type). 1. Write a program that allows you to create this class that contains: o Both data private members. o The three constructors. o A destructor that displays a message indicating the destruction of the object. o An input function that allows you to input private member values according to the following two conditions. ▪ Length = width. Length > width. 2. Overload the == operator to compare two rectangles. Two rectangles are equal if at least one of their dimensions (length and width) is equal (They are equal in length or width, or the length of one is equal to the width of the other). 3. Overload the + operator to add two rectangles. o The result of the addition is a rectangle. o The resulting rectangle has two dimensions: the common dimension between the two rectangles and the dimension of the other is the sum of the two remaining dimensions (see figure below). o The longer between them is the length and the other is the width. o If the two rectangles do not have equal dimensions, The resulting rectangle will have (-1,-1) as dimensions.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

C++

common widths
R1
R2
R1
common lengths
R1
R2
R2
length of one rectangle equal to the width of the other
4. In the main function:
o Create three uninitialized rectangles R1, R2 and R3 and use the input
function to enter the dimensions of R1 and R2.
o Calculate R3=R1+R2.
o Use exception handling to display an error message if R1 and R2 do not
have equal dimensions.
Transcribed Image Text:common widths R1 R2 R1 common lengths R1 R2 R2 length of one rectangle equal to the width of the other 4. In the main function: o Create three uninitialized rectangles R1, R2 and R3 and use the input function to enter the dimensions of R1 and R2. o Calculate R3=R1+R2. o Use exception handling to display an error message if R1 and R2 do not have equal dimensions.
Exercise 3:
Consider a rectangle class that contains two attributes (length and width of
real type).
1. Write a program that allows you to create this class that contains:
o Both data private members.
o The three constructors.
o A destructor that displays a message indicating the destruction of the
object.
o An input function that allows you to input private member values according
to the following two conditions.
▪ Length = width.
▪ Length > width.
man
2. Overload the == operator to compare two rectangles. Two rectangles are
equal if at least one of their dimensions (length and width) is equal (They are
equal in length or width, or the length of one is equal to the width of the
other).
3. Overload the + operator to add two rectangles.
o The result of the addition is a rectangle.
o The resulting rectangle has two dimensions: the common dimension
between the two rectangles and the dimension of the other is the sum of the
two remaining dimensions (see figure below).
o The longer between them is the length and the other is the width.
o If the two rectangles do not have equal dimensions, The resulting rectangle
will have (-1,-1) as dimensions.
Transcribed Image Text:Exercise 3: Consider a rectangle class that contains two attributes (length and width of real type). 1. Write a program that allows you to create this class that contains: o Both data private members. o The three constructors. o A destructor that displays a message indicating the destruction of the object. o An input function that allows you to input private member values according to the following two conditions. ▪ Length = width. ▪ Length > width. man 2. Overload the == operator to compare two rectangles. Two rectangles are equal if at least one of their dimensions (length and width) is equal (They are equal in length or width, or the length of one is equal to the width of the other). 3. Overload the + operator to add two rectangles. o The result of the addition is a rectangle. o The resulting rectangle has two dimensions: the common dimension between the two rectangles and the dimension of the other is the sum of the two remaining dimensions (see figure below). o The longer between them is the length and the other is the width. o If the two rectangles do not have equal dimensions, The resulting rectangle will have (-1,-1) as dimensions.
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Software Development
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage