Assignment 4

Due date – November 5th. before class


This assignment is a slight modification to the previous one.


Techniques - Aggregation, Inheritance, Virtual functions.


Problem -
You have a Container. This Container contains some Items. (You could keep a count of the number of elements for each container). The Items can be either Fruits or other Containers. (so you could have a container which has other containers & fruits. The inner container could again have fruits or containers.. and so on..)
The fruits are like in the previous assignment - either citrus(oranges/grapefruit) or non-citrus(apple/bananas).

The task now is to find total price of all elements in the container, as well as have subtotals for each of the inner containers. Also use virtual functions and state what type of fruits are being encountered.

You can take in the input whichever way you like. One scenario could be-


 

enter # of elements in container > 5
types = (C)ontainer, (A)pple, (O)range, (B)ananas..
element 1 > A
element 2 > C
enter # of elements in container > 2
types = (C)ontainer, (A)pple, (O)range, (B)ananas..
element 1> O
element 2> A
end container
element 3> O
element 4> O
element 5> B
end container
//end input
total is ...:

 

 

 

 

 

 

The output after I ran my program looks like: You should print the subtotal for each container as well as the total price of fruits in the baskets ( sum of all subtotals!).

[alnitak: ~/temp] > ovirt

Enter # of elements in the container> 3

Types are (A)pples , (B)askets...

Element 1> A

Element 2> A

Element 3> B

Enter # of elements in the container> 2

Types are (A)pples , (B)askets...

Element 1> A

Element 2> A

Sub-total for basket 1 is: 40

Sub-total for basket 2 is: 40

The TOTAL price of fruits in the basket is 80

 

 

What to turn in:

  1. Print out of source code with ample comments
  2. Print out of at least 3-4 test cases that show that your program runs.