December 1999
OP216 : OBJECT ORIENTED PROGRAMMING

QUESTION 3

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 3

 

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 .

 

[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 constructor function,which takes the type ,the value and the name as parameters;
•An accessor method,called Value ,which returns the value ;
•An accessor method,called Name ,which returns the name ;
•An accessor method,called Type ,which returns the type ;

 

[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 .

 

[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);

 

[7]