December
1999 QUESTION 3 Total Marks: 15 Marks |
Click here to access
other questions
SUGGESTED SOLUTIONS |
Singapore Cycle Shop requires a program to manage details of all the cycles which they stock.They stock three types of cycle:mountain cycles ,racing cycles and hybrid cycles .All of the cycles they store have a price ,which is an int expressed in Singapore Dollars,and a name ,which is a String .
|
|
||||||||||||||||
(a) |
Define a suitable enumerated type,called CycleType ,which can take on any one of the three values mountain ,racing and hybrid . typedef enum CycleType {mountain,racing,hybrid};
|
[1]
|
|||||||||||||||
(b) |
Declare a class,called Cycle ,used to store the details of a particular cycle in the store,which contains the following: •The three private members mentioned
above,type ,value and name ; A sample definition of CycleType follows:
And the following marking scheme should be used: •A correct constructor
function with parameter list;(1 mark)
|
[5]
|
|||||||||||||||
(c) |
The shop wishes to keep a record of all the cycles currently in stock.Give a definition of a class Stock ,which contains two members -a dynamic array of cycles,called CurrentStock ,and an integer specifying the size of the array, SizeOfCurrentStock . A sample definition of Stock follows:
And the following
marking scheme should be used:
|
[2]
|
|||||||||||||||
(d) |
The shop manager decides that she would like a catalogue of all the cycles,arranged by cycle type.Write a function,called SortCycle ,which takes a reference to a Stock object s ,and three other Stock objects m ,r and h ,and places copies of all of the mountain cycles in m ,the racing cycles in r and the hybrid cycles in h .You can assume that the three objects m ,r and h have su .cient space allocated in their arrays. void SortStock(Stock& s,Stock& m,Stock& r,Stock& h); A sample definition of SortStock follows:
And the following
marking scheme should be used: |
[7]
|