Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercises in this collection involve class-hierarchy development, reference counting of objects, and software-design patterns Exercise 7.1 Design a dass hierarchy to represent primitive geometric shapes.

image text in transcribed
image text in transcribed
Exercises in this collection involve class-hierarchy development, reference counting of objects, and software-design patterns Exercise 7.1 Design a dass hierarchy to represent primitive geometric shapes. Use the concept specialiation. The base class of the hierarchy shall be named shape Possible specializations of a shape aro cirde, elipis. triang, qubrdt/rectangle, iquare. 5pt1 Hint: Create the class hierarchy as a UML (structure) diagram before ceating any sounce fles. Does the class hierarchy violate the Liskov Substitution Principle? Which classes are concrete? Which dases are abstract? Exercise 7.2 Design the data representation for each of the shape specializatioms. Ceate attributes in the respective classes (e.ga cirele can be represented by its center point and its radius) 5pt] Hint: It might be beneficial to use the sath 3d library from exercise 4 for basic attributes in 3d space (e.point, vector). Exercise 7.3 Add th, folow ng properties for al sh,apes to the base class shapes may havo n_ and able to compte their area as well as their bounding box Decide if concrete implementations belong to the base class or meed to be deferred to derived classes 5pt Hint: Extend the URAL diagram(s) of the class hierarchy with the respective-ods the reg ested properties. Define esponsibilities before amending the Ct+ sounce files Exercise 7.4 Objects of type shape,contaiper must be able to hold shapes Create the class abape container and provide methods for nserting and removing shape objects. Test your implemention. [10pt] Exercise 7.5 A shape-container now needs to provide the folowing functionality 0..mans of all contained shapes (using a single call) and compute the sum of all contained shapes. Implement and test your additions [10pel Exercise 7.6 Extend the cass shape container with the behavior of deep copy and shalow copy The method shape containerisclone deep creates a new shape_contasser, which conans true ams of the shapes the orignal shape.coetainer ln contrast, the method shape container:sclone shallou creates a new shape container, wich contains (pointer to) shapes that are iden tical to the shapes in the original shape,container Exercise 7.7 Extend the base class of the class hierarchy for shapes with a neference-couting mechanim Reference counting is used to avoid deleting objects, which are still in use by (other) shape containers. The fundtionality for insertion/removal of shapes froma shape,contaiser can be used to manage the reference counter of a shape object Implement the methods shape: :ret and shape: :unref to increment and decrement the reference counter, respectively Hint: You should have completed and understood exercise 7.6 before empting to solve xecise 7.7 10pt] Exercise 7.8 Replace the use of a shape container with the composite design patterm. Extend the abape hierarchy with the class compoaite. Objects of type composite ve shapes, which composed of shapes Provide ds for mertng and removing shapes from coaposite objects Using a composite class allows now for creating hierarchicall structures at run time. Create a (small) scene of shapes distributed over several composite objeas Ensure that the f uity cf shape-container variant is preserved with the compoaite variant. Hint: Hierarchical structures using caeposite objects suggest a Pmtdld Aggegate chlen in composite instances using an appropriate container type from the Ct+ standard ay and justify the choice of container Exercise 7.8 Replace the use of a shape container with the composite design pattern. Extend the shape hierarchy with the class composite Objects of type composite are shapes, which are composed of shapes. Provide methods for inserting and removing shapes from composite objects. Using a composite class allows now for creating hierarchical structures at run time. Create a (small) scene of shapes distributed over several composite objects. Ensure that the functionality level of the shape_container variant is preserved with the composite variant. Hint: Hierarchical structures using cosposite objects suggest a parent-child relationship. Aggregate children in composite instances using an appropriate container type from the Ct+standard library and justify the choice of container 15pt Exercise 7.9 Use the visitor design pattern to compute the complexity of a scene. Lookup the visitor design pattern and familiarize yourself with it and its behavior. Extend the shape hierarchy with the method accept (shape visito Implement the base class shape visitor, which defines the interface of derived concrete visitors Derive a class trianglecount visitor from the base class shape visitor triangle count visitor determines the number of triangles in a run-time hierarchy of shapes. Apply an instance of triangle_count visitor to a (non-empty) scene of your choice. Hint: The triangle count visitor assumes that a rectangle/quadrangle will be represented by two triangles and that a circle or ellipsis is represented by 24 triangles. 20pt] Exercises in this collection involve class-hierarchy development, reference counting of objects, and software-design patterns Exercise 7.1 Design a dass hierarchy to represent primitive geometric shapes. Use the concept specialiation. The base class of the hierarchy shall be named shape Possible specializations of a shape aro cirde, elipis. triang, qubrdt/rectangle, iquare. 5pt1 Hint: Create the class hierarchy as a UML (structure) diagram before ceating any sounce fles. Does the class hierarchy violate the Liskov Substitution Principle? Which classes are concrete? Which dases are abstract? Exercise 7.2 Design the data representation for each of the shape specializatioms. Ceate attributes in the respective classes (e.ga cirele can be represented by its center point and its radius) 5pt] Hint: It might be beneficial to use the sath 3d library from exercise 4 for basic attributes in 3d space (e.point, vector). Exercise 7.3 Add th, folow ng properties for al sh,apes to the base class shapes may havo n_ and able to compte their area as well as their bounding box Decide if concrete implementations belong to the base class or meed to be deferred to derived classes 5pt Hint: Extend the URAL diagram(s) of the class hierarchy with the respective-ods the reg ested properties. Define esponsibilities before amending the Ct+ sounce files Exercise 7.4 Objects of type shape,contaiper must be able to hold shapes Create the class abape container and provide methods for nserting and removing shape objects. Test your implemention. [10pt] Exercise 7.5 A shape-container now needs to provide the folowing functionality 0..mans of all contained shapes (using a single call) and compute the sum of all contained shapes. Implement and test your additions [10pel Exercise 7.6 Extend the cass shape container with the behavior of deep copy and shalow copy The method shape containerisclone deep creates a new shape_contasser, which conans true ams of the shapes the orignal shape.coetainer ln contrast, the method shape container:sclone shallou creates a new shape container, wich contains (pointer to) shapes that are iden tical to the shapes in the original shape,container Exercise 7.7 Extend the base class of the class hierarchy for shapes with a neference-couting mechanim Reference counting is used to avoid deleting objects, which are still in use by (other) shape containers. The fundtionality for insertion/removal of shapes froma shape,contaiser can be used to manage the reference counter of a shape object Implement the methods shape: :ret and shape: :unref to increment and decrement the reference counter, respectively Hint: You should have completed and understood exercise 7.6 before empting to solve xecise 7.7 10pt] Exercise 7.8 Replace the use of a shape container with the composite design patterm. Extend the abape hierarchy with the class compoaite. Objects of type composite ve shapes, which composed of shapes Provide ds for mertng and removing shapes from coaposite objects Using a composite class allows now for creating hierarchicall structures at run time. Create a (small) scene of shapes distributed over several composite objeas Ensure that the f uity cf shape-container variant is preserved with the compoaite variant. Hint: Hierarchical structures using caeposite objects suggest a Pmtdld Aggegate chlen in composite instances using an appropriate container type from the Ct+ standard ay and justify the choice of container Exercise 7.8 Replace the use of a shape container with the composite design pattern. Extend the shape hierarchy with the class composite Objects of type composite are shapes, which are composed of shapes. Provide methods for inserting and removing shapes from composite objects. Using a composite class allows now for creating hierarchical structures at run time. Create a (small) scene of shapes distributed over several composite objects. Ensure that the functionality level of the shape_container variant is preserved with the composite variant. Hint: Hierarchical structures using cosposite objects suggest a parent-child relationship. Aggregate children in composite instances using an appropriate container type from the Ct+standard library and justify the choice of container 15pt Exercise 7.9 Use the visitor design pattern to compute the complexity of a scene. Lookup the visitor design pattern and familiarize yourself with it and its behavior. Extend the shape hierarchy with the method accept (shape visito Implement the base class shape visitor, which defines the interface of derived concrete visitors Derive a class trianglecount visitor from the base class shape visitor triangle count visitor determines the number of triangles in a run-time hierarchy of shapes. Apply an instance of triangle_count visitor to a (non-empty) scene of your choice. Hint: The triangle count visitor assumes that a rectangle/quadrangle will be represented by two triangles and that a circle or ellipsis is represented by 24 triangles. 20pt]

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

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books