Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this C++ program! :) For this program, you will implement the ShapeBuilder class. The ShapeBuilder will ask the user what kind

Please help me with this C++ program! :)

For this program, you will implement the ShapeBuilder class.

The ShapeBuilder will ask the user what kind of shape he/she would like to build, and then ask for the appropriate dimensions of the shape.

For example, a circle will only need a radius and a rectangle will need a height and width.

Upon definition, the ShapeBuilder will display the shape to the screen. If the user likes what he/she sees, then they have the option to save the shape to a file (shapes.txt). The saving operation will be performed by the ShapeSaver class, which has one saveShape function, which accepts only a Shape* object into the function.

The ShapeBuilder then asks the user if they would like to build/save another shape or to exit the program.

Implementation Details

You must implement a ShapeBuilder class, a ShapeSaver class, a Shape base class, and the following classes derived from Shape: Circle, EquilateralTriangle, and Rectangle.

A circle is defined by its diameter. Valid sizes are 1 to 80.

An isosceles triangle is defined by its edge size. Valid sizes are 1 to 80.

A rectangle is defined by its height and width. Valid sizes are 1 to 80 each.

Each class must have a separate .H and .cpp file.

The Shape class must contain:

A dynamically allocated 2-D character array

The pure virtual function build(), which is implemented by the derived classes

The build function will ask the user for shape dimensions, allocate the appropriate memory, and assign the appropriate values into the 2-D character array {use x for the shape; all other characters will be spaces}

You should try to put all common information into the base Shape class. Avoid repeating member variables throughout each derived class.

All dynamically allocated memory must be freed at the appropriate moment.

Your main function will be very simple:

int main(){

ShapeBuilder sb;

sb.run();

return 0;

}

Hints

Try starting with the rectangle case. That is the simplest. Move from there to implement triangle and then circle.

Note that the indices for the data array are integers, but the triangle and circle shape representations will necessarily have cases where the perimeter of the shape lies between the indices. This means circles with an even numbered diameter will appear off-center. All triangles will look like a wizards hat at the peak. This is ok.

At the end of this document, there are sample representations for circle and triangle.

Your implementation need not follow these representations exactly. However, your shapes must be able to be interpreted as a circle or as an isosceles triangle or as a rectangle. That is, you should be close to those representations, if not exact.

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago