December
1998 QUESTION 3 Total Marks: 20 Marks |
Click here to access other
questions
Click to access
|
(a) | What is a friend function in C++?
|
[2] |
(b) | Give one situation when a friend
function might be used in C++.
|
[1] |
(c) | An airport has a number of stands where
an aeroplane may be parked. When a passenger is checked in for a flight
on an aeroplane, the weight of the passenger and his/her luggage is added to the weight of
the aeroplane. If the aeroplane is too heavy, it cannot take off. Consider the classes
below. class Aeroplane { class Passenger { class Airport {
|
|
(i) Implement the constructor Passenger that takes two integers a and b and sets weight to a and luggage to b. Ensure that the
default value of weight is 75 and luggage is 25.
|
[3] | |
(ii) Give the definition of the
Airport method check_in that takes a
stand number (an integer index for an aeroplane) and a passenger, and performs the
check-in procedure detailed above.
|
[3] | |
(iii) Give the definition of the Airport take_off that takes a stand number and an integer
maximum take_off weight, and removes the aeroplane from the Airport (by replacing its
entry with a NULL pointer) if it is not too heavy. If the aeroplane is too heavy,
print an error message.
|
[4] | |
(iv) Give the definition of the Airport method land that takes an aeroplane, and assigns it to
the first free stand in the airport and prints the number of the chosen land. You may assume that a spare stand exists. |
[7] |