December
1999 QUESTION 4 Total Marks: 15 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
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. Private
members can only be accessed by other members and friends of the class;(1
mark)
|
[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; A sample definition of Confectionery follows:
And the following
marking scheme should be used:
|
[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. A sample definition of Minstrels follows:
And the following
marking scheme should be used:
|
[5]
|
||||||||||||||||||||||||||||||||||||
(d) |
A SelectionBox is a collection of di .erent types of Confectionery .Consider the following de .nition of the class SelectionBox :
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
. A sample definition of TotalCalories is given below:
And the following
marking scheme should be used: |
[5]
|