Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question #1 (30 points) A C++ class that models a cube is to be developed. A cube is simply a geometric solid where each of

image text in transcribedimage text in transcribedimage text in transcribed
Question #1 (30 points) A C++ class that models a cube is to be developed. A cube is simply a geometric solid where each of three attributes (length, width, height) have exactly the same value. This class will become part of a program class library. Programmers that use the completed Cube class shall be able to set the value of a Cube object's data value (it should be named side) and shall be able to retrieve the value of a Cube object's data attribute. The data type for the side attribute shall be double. Only positive numeric values for the data attribute are permitted. An attempt to set an invalid value shall result in an error message being displayed. The default value for the data attribute shall be one (1). A Cube object must remember its surface area at all times during its use. The formula for surface area is 6 * side * side. All member functions shall be designed so that a programmer can tell from a function's prototype whether the function can or cannot modify an attribute value, and this should be enforced by the compiler. Accessor functions for appropriate member attributes shall be provided in your implementation. Write the complete source code for a Cube class definition.Question #2 (30 points) The UML diagram below specifies that a composition relationship exists between class A and class B and between class C and class D and an inheritance relationship exists between class A and class C. Recall that a composition relationship is the strong form of aggregation in which the aggregating object controls the lifetime of the aggregated object(s). Note also that the data members aobj and cobj are raw pointers. A B -aObj: B* -bData: int = 0 +A0 +setB( :int ):void +A() +getB(): int C D -cObj: D* -dData: int = 0 +CO) +setD( int ):void +-C() +getD():intWrite the code for the class A and class C constructors and destructors so that the following code executes correctly: int main ()| A aobj ; A *ptr = new C; delete ptr; return 0; Question #3 (40 points) A project team is developing a C++ application that will serve as an educational tool to help children learn about various concepts such as vehicles, animals, sounds, etc. The application shall have a need to draw various objects (e.g., animals and vehicles) on the video display as well as to play sounds (if applicable) that are associated with an object. The project manager has specified that all objects in the application shall use a common interface for requesting behaviors like drawing, playing sounds, and rotating objects. These interfaces shall be reusable for future projects as well. Functions named drawObject (), rotateObject (), and playSound () shall be used for these behaviors. The project team shall develop a prototype to test the overall concepts desired by using an Animal class and a Vehicle class. For prototype purposes an Animal object shall have a name attribute, shall be drawable, rotatable, and can make sounds. A Vehicle object shall have a name, a weight, and shall be drawable, rotatable, and can make sounds. When a drawObject () function is invoked a message indicating "Drawing an Animal" or "Drawing a Vehicle" shall be displayed. Similar messages shall be displayed for the rotateObject () and playSound () functions. The prototype shall be tested using a main() function as follows: A single array shall be used to store information about a collection of Animal and Vehicle objects. The array will have 4 members...2 associated with Animal objects and 2 associated with Vehicle objects. A single for-loop shall be used to iterate over the array and call each of the 3 functions. Runtime polymorphism must be used to invoke these functions, so the type of object associated with each array element must not be checked. Your submitted solution must contain a class diagram of the design and all source code. I am primarily concerned with the correctness of the design and not whether the source code is perfect

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions