August 2000
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 sales manager requires a program to maintain details of his customers. He wishes to split his customers up into four categories, depending on their location, which can be one of Singapore, India, Malaysia or China. In addition to this, for each customer, he wishes to store their name, which is a string, the customer’s average expenditure, in Singapore Dollars, which is an integer, and a transaction record, which is an array of objects of type Transaction.

(a) Define a suitable enumerated type, called Location, which can take on any of the values of location given above. [1 mark]

(b) Define a class, called Customer, which can be used to store all of the customer’s details given above. [5 marks]

(c) Add to your class an inline method, called GetName which returns a copy of a customer’s name. [3 marks]

(d) Briefly explain what is special about an inline method in C++, and give an example of where it may be useful to declare a method inline. [2 marks]

(e) Implement a constructor for the Customer class, such that it takes as parameters the customer’s location, the customer’s name, the customer’s average expenditure and the customer’s Transaction record, and initialises them appropriately. [4 marks]