Starting from:
$30

$24

CSE-Homework #5 – Shape Hierarchy Solved

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.

  





Shape




+display()

                          
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 CSE-40477




(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




(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




(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




(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




(1 point) Implement a test program in a file named “hw5.cpp”. Your test program should do the following:



Define an array of four pointers to Shapes.



Use the new operator to create a Circle, Square, Sphere, and Cube. Store pointers to these objects in the array of pointers to Shapes.



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.



(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.

More products