December 1999
OP216 : OBJECT ORIENTED PROGRAMMING

QUESTION 4

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 4

 

A confectionery shop requires a system to maintain details of products which it vends.You are to implement such a system.

 

 
(a)

Identify the difference between private and protected members of a class.

 

[2]
(b)

An item of confectionery contains a calorie count (an integer)and a name (a pointer to an array of characters). Declare the class Confectionery that contains:

•These private data items;
•An accessor method called Calories ,which returns the calorie count;
•A method,called Display ,the signature of which is given below,which prints out the name and the calorie count on a single line.
void Display();

 

[3]
(c)

Minstrels are a type of confectionery that have a calorie count of 100,and an integer value specifying the number of minstrels in a packet.Using inheritance,declare a class Minstrels ,which contains a constructor which takes a number of Minstrels and initialises all of its variables appropriately.

 

[5]
(d)

A SelectionBox is a collection of di .erent types of Confectionery .Consider the following de .nition of the class SelectionBox :

class SelectionBox {
private:
//Some private declarations
public:
SelectionBox(); //Return current confectionery item in list
Confectionery current(); //Move to next confectionery item in list
void next(); //Return 1 if all items have been looked
int empty(); //at,0 otherwise
     
}    

Write a function,called TotalCalories ,the signature of which is given below,which takes a reference to a SelectionBox object and returns the sum of all the Calories which are contained within that SelectionBox .
int TotalCalories(SelectionBox&s);

[5]