Question: Exercises in this collection involve class-hierarchy development, reference counting of objects, and software-design patterns Exercise 7.1 Design a class hierarchy to represent primitive geometric shapes.
Exercises in this collection involve class-hierarchy development, reference counting of objects, and software-design patterns Exercise 7.1 Design a class hierarchy to represent primitive geometric shapes. Use the concept specialization. The base class of the hierarchy shall be named shape. Possible specializations of a shape are circle, ellipsis, triangle, quadrangle/rectangle, or square. 5pt Hint: Create the class hierarchy as a UML (structure) diagram before creating any source files. Does the class hierarchy violate the Liskov Substitution Principle? Which classes are concrete? Which classes are abstract? Exercise 7.2 Design the data representation for each of the shape specializations. Create attributes in the respective classes (e.g., a circle can be represented by its center point and its radius) Hint: It might be beneficial to use the math3d library from exercise 4 for basic attributes in 3d space (e. g.. point, vector) [5pt] Exercise 7.3 Add the following properties for all shapes to the base class: shapes may have names and are able to compute their area as well as their bounding bax. Decide if concrete implementations belong to the base class or need to be deferred to derived classes. [5 pt] Hint: Extend the UML diagram(s) of the class hierarchy with the respective methods for the requested properties. Define responsibilities before amending the C++ source files Exercise 7.4 Objects of type shape container must be able to hold shapes. Create the class shape container and provide methods for inserting and removing shape objects. Test your implemention 10pt] Exercise 7.5 A shape,container now needs to provide the following functionality output the names of all contained shapes (using a single call) and compute the sum of all contained shapes. Implement and test your additions 10pt] Exercise 7.6 Extend the class shape_container with the behavior of deep copy and shallow copy. The method shape container::clone deep creates a new shape container, which contains true copies of the shapes in the original shape,container. In contrast, the method shape_container::clone shallou creates a new shapecontainer, which contains (pointer to) shapes that are iden- tical to the shapes in the original shape_container 10pt] Exercise 7.7 Extend the base class of the class hierarchy for shapes with a reference-counting mechanism. Reference counting is used to avoid deleting objects, which are still in use by (other) shape containers. The functionality for insertion/removal of shapes from a shape_container can be used to manage the reference counter of a shape object. Implement the methods shape: :rof and shape: : unref to increment and decrement the reference counter, respectively Hint: You should have completed and understood exercise 7.6 before attempting to solve exercise 7.7 10pt]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
