For this , you are expected to write an interactive program which, according to the user input, creates dynamic responses and do simple calculations.
A compound object will be defined interactively and you program will keep track of a simple property and return a result based on the composition of the object.
Example:
Suppose that you want to calculate the total cost of a compound object. In this case your compound object is a bicycle. A bicycle has many parts and some of the parts are also compound objects individually. So, a hierarchical structure can be used in order to model such a compound object. You can visualize it as a tree. Nodes are the parts and the children of a particular node are the parts which make up the part associated with that node.
Price
Bicycle x 1
Wheel x 2
Rim x 1 60.0
Spoke x 28 12.0
Hub x 1
Gear x 6 25.0
Axle x 1
Nut x 7 0.15
Bolt x 5 0.1
Frame x 1
Rearframe x 1 170.0
Frontframe x 1
Fork x 2 21.5
Handle x 1 12.0
Figure 1: Composition of a bicycle
Figure 1 shows parts of a bicycle. A bicycle can be described as an object which consists of 2 wheels and a frame. We can create a more detailed description by including the description of the individual parts, wheel and frame. A description includes number of the parts, part name and, if no further description is needed, prices of the part or parts.
Your program does not know anything about the compound object. The expectation is; either there is a compound object which can be specified by its parts or there is a simple object which can be specified by its property.
For this example, the propery is the price of the object. Your program will ask questions to the user and eventually calculate the total price of the bicycle described by the user.
Below is a simple dialog which the user describes the object ‘bicycle’ to the program: (Comments are not parts of the output)
Name the object: Bicycle Define Bicycle?:
2 Wheel 1 Frame Comment: A bicycle consists of 2 Wheels and 1 Frame.