Professional Documents
Culture Documents
COMP STUD
Candidate Number
PAPER I
Centre Number
(SECT B & C)
HONG KONG EXAMINATION AND ASSESSMENT AUTHORITY
HONG KONG CERTIFICATE OF EDUCATION EXAMINATION 2001 Seat Number
Q.6
Q.7
Q.8
Instructions:
Q.9
1. Write your Candidate Number, Centre Number and
Seat Number in the spaces provided. Q.10
Q.10 0 1 2 3 4 0 1 2 3 4
2. Answer all questions.
Total
3. Write your answers in the spaces provided in this
question-answer book.
Checker No.
Total
6. Mr. Lee is a Mathematics teacher. He uses a text file to record the scores obtained by his students in two tests. In the text
file, each line contains the data of one student. The number of lines in the file is not fixed. There are three data fields in each
line and each data field is separated by a blank character. The format of each line is as follows:
DATA1999.TXT DATA2000.TXT
5760 73 93 4731 47 86
8288 18 25 4667 52 66
7654 45 10 3267 99 72
0157 99 98 1249 17 26
3547 77 41 5738 65 24
7499 60 62
1974 44 50
4537 78 66
6823 92 13
6982 70 22
3085 96 40
1459 53 82
You may assume that each score is a positive integer and the data file contains at least one line.
Mr. Lee writes a program to calculate the overall mean score of his students and find the students who obtained the highest
average score. If there is more than one student with the highest average score, the program will find the first one.
The program should produce the output below on the VDU. (In this output, all the data following a question mark is entered
by the user through the keyboard. All other items are output from the program.)
Sample output 1:
File name? DATA1999.TXT
Overall mean score: 58.63
Highest average score: 98.5
Student number of the best student: 0157
Sample output 2:
File name? DATA2000.TXT
Overall mean score: 55.40
Highest average score: 85.5
Student number of the best student: 3267
20 int main()
30 {
40 int Test1, Test2, I, Count;
50 double Score, MaxScore, Sum;
60 char Num[5], MaxNum[5];
70 char fn[1024];
80 FILE* f;
310 return 0;
320 }
However, there are several mistakes after line 80 in the program. Fill in the following table to show the location of each mistake
and its correction.
(10 marks)
Step 1: Declare dena, remdr to be integer variables, and newnum, bina to be strings.
Step 2: Read a denary number into variable dena.
Step 3: Assign a null string to bina.
Step 4: As long as the value of dena is greater than 1, repeat steps 5 to 8.
Step 5: Calculate the remainder when dena is divided by 2 and store the result to variable remdr.
Step 6: Calculate the quotient when dena is divided by 2 and store the result to variable dena.
Step 7: Convert the variable remdr to a string and store it in newnum.
Step 8: Concatenate newnum and bina, then store the result in bina.
Step 9: Convert the variable dena to a string and store it in newnum.
Step 10: Concatenate newnum and bina, then store the result in bina.
Step 11: Display the value stored in bina.
Convert the algorithm into a C program.
(10 marks)
#define true 1
#define false 0
int list[16];
flag = false;
while ( !flag && f <= e )
{
m = (f + e) / 2;
printf("Before the Segment X, ");
printf("f = %d e = %d m = %d\n", f, e, m);
if ( list[m] == t )
flag = true;
else
if ( list[m] > t ) Segment X
e = m - 1;
else
f = m + 1;
printf("After the Segment X, ");
printf("f = %d e = %d m = %d\n", f, e, m);
}
if ( flag )
*r = m;
else
*r = -1;
}
(a) Suppose the array variable list stores the following values:
m 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
list[m] 10 14 17 24 33 36 39 48 56 61 69 77 82 86 87 99
The variable SearchResult is defined as integer. If the following statement is executed:
(4 marks)
m 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
list[m] 99 87 86 82 77 69 61 56 48 39 36 33 24 17 14 10
(i) Rewrite Segment X so that procedure P can handle the above array.
(5 marks)
(1 mark)
Task A: Input the number of candidates and initialize the number of votes received by each candidate.
Task B: Count the ballots for the candidates by asking the candidate number selected in each ballot. If exactly one
number is shown on a ballot, the number will be entered. No ballot with more than one number shown will
be entered. The program stops counting when the user enters a ‘0’ as a candidate number.
Task C: Display the result of the election in the following format:
Result
======
Candidate 1 |*******
Candidate 2 |*****
… … …
In the chart, an asterisk (*) represents one vote.
The following shows a sample output of the program. (In this output, all the data following a colon is entered by the user
through the keyboard. All other items are output from the program.)
Number of candidates: 3
Result
======
Candidate 1 |***
Candidate 2 |
Candidate 3 |****
#include <stdio.h>
int vote[30001];
int main()
{
int n;
Init(&n);
printf("\n");
CountBallots(n);
printf("\n");
printf("Result\n");
printf("======\n");
ShowChart(n);
return 0;
}
The following indicates the description of each identifier used in this program:
Identifier Description
vote A global array used to store the numbers of votes received by candidates. For convenience, vote[0]
is NOT used and vote[x] stores the number of votes received by candidate x.
n a variable used to store the number of candidates.
You are not allowed to add any new variable in answering the question.
(a) Complete the procedure parameter and write the procedure Init that will perform Task A.
void Init( )
{
int i;
}
(3 marks)
void CountBallots(int n)
{
int ballot;
}
(4 marks)
void ShowChart(int n)
{
int i, j;
}
(3 marks)
END OF SECTION B
10. Mr Lee has decided to connect some electronic and electrical devices in his home to make a CyberHome for the family. He
has installed a network to link up a computer and all the existing devices with a communication box attached to each device.
Existing connections of the communication boxes include lighting controls, microwave oven, stereo systems, TVs, etc. After
the installation of the network and the computer, every device can only be controlled by the computer and each use of the
device is recorded.
When the computer is powered up, an application program is automatically started. It will show a screen of icons. Each icon
represents a device. To use the application program, a user must place his/her own smart card on top of a reader while the
user performs the operations. When a user double-clicks on an icon, the computer will send a message to the corresponding
device to turn it on. When a user single-clicks on an icon, the corresponding device will be turned off.
Each message sent by the computer contains a device number and a set of data items to control the corresponding device.
The current design contains only a device number and one data item, which is for the ON/OFF control of the device.
After using the system for a few days, Mr Lee’s family members have the following comments:
• Mr Lee’s wife said, “As the icons are arranged in alphabetical order, it is quite hard to find the right icon for an
appliance using the CyberHome.”
• Sunny, Mr Lee’s elder son, said, “The idea of the CyberHome is excellent. However, I often need to walk back and
forth from my room to the computer to control the devices which is inconvenient.”
• Apple, Mr Lee’s younger daughter, said, “I feel very uncomfortable since the installation of the CyberHome. Every
time I want to turn on a light, I need to go to the living room. All of my activities are known to everyone. I would
like to go back to the old days.”
(a) Suggest a solution for the icon arrangement problem which Mrs Lee complained about.
(2 marks)
(b) Sunny suggests installing microphones for voice recognition instead of using a mouse as the input device. Give ONE
advantage and ONE disadvantage of this suggestion.
(4 marks)
(2 marks)
(d) Mr Lee wants to have one monthly device usage report of each member of his family. What essential data should be
used to generate the report?
(2 marks)
(e) Apple thinks there has been an invasion of her privacy after the set up of the CyberHome. Give an example of
privacy invasion that may occur after connecting to the Internet.
(2 marks)
(f) Apple opposes the idea of remote controlled home devices. She is afraid that Mr Lee can limit her access to the home
devices, like the stereo or TV. Suggest the steps that the system will have to perform to handle local and remote
requests differently and, thus, solve the problem raised by Apple.
(4 marks)
END OF SECTION C
END OF PAPER
#include, +, -, *, /, ++, --, +=, -=, *=, /=, %=, ==, %, >, <, =, >=, <=, !=, &&, ||, !, sqrt, rand, abs, strcat, strncat, strlen,
atoi, strcpy, strncpy, const, void, return, int, float, char, \0, strcmp, strncmp, true, false, FILE, main, /*…*/, if…else, for,
while, do…while, switch…case…break, break, continue, scanf, printf (%d, %f, %c, %s), \n, \t, fopen, getc, fgets, putc,
fputs, EOF, fclose