August
1999 QUESTION 3 Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
The Singapore
Football League requires a program to maintain information about the football league. Each
team in the league has a name (a character string), a current league position (an integer)
and the number of games they have played (an integer).
|
||
(a) | Give a declaration of the class Team which
contains
|
[5] |
A sample definition of Team follows: Class Team { private:
|
||
(b) | A league is a collection of 20 teams. Give a definition of a class League, which contains an array of 20 teams. | [2] |
A sample definition of League follows: class League {
|
||
(c) | Since each team in the league plays each other team, the total number of games played for all teams is an even number. Write a function, called check_fixture, which sums all of the games played by all teams in the league, and returns 0 if it is an even number, or -1 otherwise. | [6] |
A sample definition of check_fixture follows: int League : :check_fixture( ) { for(i= 0; i< 20;
i++) return (count%2);
|
||
(d) | Write a function display_league, which takes an object of type League,prints the names of the teams in that league in descending order of position, from position 1 to 20. You should use a simple sequential search to locate the teams. | [7] |
A sample definition of display_league follows: void printout_league(League division) {
|