Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ with COMMENTS PLEASE!!! Write a class to represent rectangles. Attributes and Methods The class includes the fields: length, width, and color. Write each

IN C++ with COMMENTS PLEASE!!!

Write a class to represent rectangles.

Attributes and Methods

The class includes the fields: length, width, and color.

Write each of the methods indicated in the diagram.

You must supply a zero-arguments constructor. Use zero as the default value for length and width. The default color is Blue.

Write a constructor to accept all the arguments, length, with, and color.

Overload the + operator to add two rectangles. The operator will respectively add the lengths and widths of the two rectangles. If both rectangles have the same color the result of the addition retains that color, otherwise the resulting rectangle should be White.

The toString() method returns a string indicating (in this order) the address of the object, its type (Rectangle), its length, width, color, area, and perimeter. Numeric values must be printed with two decimal digits.

Write a function (call it properCap) to turn a string representing a color into a proper-cap string. For example, if the user supplies the value RED, your function converts it to Red.

Validation Rules

The only valid colors are Red, Blue, and White (spelled as listed!). If an invalid color is supplied, change it to White.

Both length and width must be positive numbers. If a negative value is supplied, your app must change it into a positive.

Test the program with the following sequence of operations

1.Create a rectangle -say r1- by calling the zero-arguments constructor.

2.Use mutators to set length, width, and color to 1, -2, RED.

3.Use your toString() function to let the object r1 tell its contents.

4.Create an object r2 with (length, width, color) attributes 10, 20, bluerespectively.

5.Display the contents of r2 using toString().

6.Create a rectangle r3, by adding r1 and r2 (that is, r3 = r1 + r2, use your overloaded + operator).

7.Use toString() to show the contents of r3.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

Contact is an overused word.

Answered: 1 week ago