Sale!

Homework #5 – Shape Hierarchy

$30.00

Category:

Description

In this assignment you are asked to implement a hierarchy of classes representing shapes in two and three dimensional space. The following UML class diagram shows the attributes and behaviors of the classes in the shape hierarchy.
Important notes: UML type Float will map to type double when implemented in C++. A class name in italics indicates that the class is abstract. A member function name in italics indicates that the function is pure virtual.
Figure 1. UML class diagram for Shape hierarchy
1. (1 point) Meet these basic requirements: a. All classes must be implemented in a namespace based on your first and last name (e.g. “RayMitchell”). b. All class definitions must all be placed in a file named “Shapes.h”. c. All member function implementations must all be placed in a file named “Shapes.cpp”. d. Member functions must be marked as const where appropriate.
2. (1 point) Implement class Shape as shown in the UML diagram.
3. (1 point) Implement class TwoDimensionalShape as shown in the UML diagram.
4. (1 point) Implement class ThreeDimensionalShape as shown in the UML diagram.
Shape
+display()
TwoDimensionalShape
+getArea(): Float
ThreeDimensionalShape
+getSurfaceArea(): Float +getVolume(): Float
Circle
-radius: Float
+Circle(radius: Float) +display() +getArea(): Float
Square
-lengthOfSide: Float
+Square(lengthOfSide: Float) +display() +getArea(): Float
Sphere
-radius: Float
+Sphere(radius: Float) +display() +getSurfaceArea(): Float +getVolume(): Float
Cube
-lengthOfSide: Float
+Cube(lengthOfSide: Float) +display() +getSurfaceArea(): Float +getVolume(): Float
CSE-40477
5. (1 point) Implement class Circle as shown in the UML diagram. Function display should output the Circle’s radius and area in the following format:
Circle with radius 2 has area 12.5664
6. (1 point) Implement class Square as shown in the UML diagram. Function display should output the Square’s length of side and area in the following format:
Square with length of side 3 has area 9
7. (1 point) Implement class Sphere as shown in the UML diagram. Function display should output the Sphere’s radius, surface area, and volume in the following format:
Sphere with radius 4 has surface area 201.062 and volume 268.083
8. (1 point) Implement class Cube as shown in the UML diagram. Function display should output the Cube’s length of side, surface area, and volume in the following format:
Cube with length of side 5 has surface area 150 and volume 125
9. (1 point) Implement a test program in a file named “hw5.cpp”. Your test program should do the following: a. Define an array of four pointers to Shapes. b. Use the new operator to create a Circle, Square, Sphere, and Cube. Store pointers to these objects in the array of pointers to Shapes. c. Loop over the array of pointers to Shapes. Each time through the loop call the display function on the current Shape then destroy the Shape using the delete operator.
10. (1 point) Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, follows a consistent style, and is ANSI-compliant.
Place all source code and a screen capture of the output produced by your program in a single Word or PDF document. Submit this document.

(0)