I have figured out this assignment, but I am having a hard time figuring out the...

80.2K

Verified Solution

Question

Programming

I have figured out this assignment, but I am having ahard time figuring out the extra credit, Thanks!

Creating a Rectangle class

We have created a representation of a rectangle in C++ andextended it to create multiple representation's of rectangles.Classes can simplify that process considerably. In this assignment,your task is to convert the representation of a rectangle wecreated earlier in the semester to a Rectangle class. The Rectangleclass shall consist of the following:

  1. The private data shall consist of 4 members:
    1. length
    2. width
    3. area
    4. perimeter
  2. Have 1 constructor with the following parameters: length andwidth.
  3. Have 2 mutators:
    1. setLength to set/modify the length.
    2. setWidth to set/modify the width.
  4. Have 5 accessors:
    1. getLength to return the length.
    2. getWidth to return the width.
    3. getPerimeter to return the perimeter.
    4. getArea to return the area.
    5. printObjet to print the representation of the rectangle (usingthe same output criteria of the previous incarnations). NOTE: Thisroutine must print out the following: \"You created a rectangle withthe following characteristics:\" followed by a blank line beforeprinting out the values of the class data.

You then need to create a 'main' program and instantiate 3rectangle objects with different parameters. You also need to printeach rectangle's characteristics.

For this assignment you need to turn in 1 file which containsthe class header and declaration/implementation, and the mainprogram. Don't forget to include your file header.

Expected Output:

Your output shall look like this given the inputs below:

Enter the length of the 1st rectangle: 3
Enter the width of the 1st rectangle: 5
You created a rectangle with the following characteristics:

    width = 5
    length = 3
    perimeter = 16
    area = 15

Enter the length of the 2nd rectangle: 4
Enter the width of the 2nd rectangle: 6
You created a rectangle with the following characteristics:

    width = 6
    length = 4
    perimeter = 20
    area = 24

Enter the length of the 3rd rectangle: 4.1
Enter the width of the 3rd rectangle: 6.2
You created a rectangle with the following characteristics:

    width = 6.2000
    length = 4.1000
    perimeter = 20.6000
    area = 25.4200

EXTRA CREDIT

For 7 points of extra credit:

Store 10 rectangle objects you created in a vector and sequencethrough the vector to print out the 10 rectangle objects.

Answer & Explanation Solved by verified expert
4.4 Ratings (752 Votes)
ScreenshotProgramrectanglehCreate a class rectangleclass Rectangle Instance variablesprivate double length double width double perimeter double area Member functionspublic    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students