Program Assignment Help

I know people do not usually put questions like this on me but please help me with this program! I am a beginner and am really stuck! :)





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 wizard’s 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.
Topic archived. No new replies allowed.