You are on page 1of 12

2001-CE

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

COMPUTER STUDIES PAPER 1


(SECTIONS B & C)
Question-Answer Book

8:30 am – 10:30 am (2 hours)


This paper must be answered in English Marker’s Examiner’s
Use Only Use Only
Marker No. Examiner No.

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.

4. Supplementary answer sheets will be supplied


upon request. Write your Candidate Number on
each sheet and fasten them with string inside this
book.

Checker’s Use Only

Checker No.

Total

2001-CE-COMP STUD 1B & C-1 (C Version)


Section B (40 marks)
Answer ALL questions in this section.

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:

4-digit Student Number Score of Test 1 Score of Test 2


Below are the data files for the years 1999 and 2000:

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

2001-CE-COMP STUD 1B & C-2 (C Version)


Mr. Lee’s program is shown below:

Line Number Program Statement


10 #include <stdio.h>

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;

90 printf("File name? ");


100 scanf("%s", "fn");
110 f = fopen(fn, "r");
120 strcpy(MaxNum, "0000");
130 MaxScore = 100;
140 Count = 0;
150 Sum = 0;
160 while ( feof(f) )
170 {
180 fscanf("%s%d%d", Num, &Test1, &Test2);
190 Score = (double) Test1 + Test2 / 2;
200 if ( Score < MaxScore )
210 {
220 MaxScore = Score;
230 }
240 Sum = Sum + 1;
250 Count = Count + 1;
260 }
270 fclose(f);
280 printf("Overall mean score: %.2f\n", Sum / Count);
290 printf("Highest average score: %.1f\n", MaxScore);
300 printf("Student number of the best student: %s\n", MaxNum);

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.

Line Number Corrected Statement

(10 marks)

2001-CE-COMP STUD 1B & C-3 (C Version)


7. The algorithm below converts a denary (base 10) number to a binary (base 2) number.

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)

2001-CE-COMP STUD 1B & C-4 (C Version)


8. The declaration of a global array variable list and procedure P are given below:

#define true 1
#define false 0

int list[16];

void P(int t, int f, int e, int* r)


{
int m;
int flag;

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:

P(36, 0, 15, &SearchResult);

write the output by completing the following:

Before the Segment X, f = e = m =


After the Segment X, f = e = m =
Before the Segment X, f = e = m =
After the Segment X, f = e = m =
Before the Segment X, f = e = m =
After the Segment X, f = e = m =

(4 marks)

2001-CE-COMP STUD 1B & C-5 (C Version)


(b) Suppose the values in the array list are now in reverse order as follows:

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.

(ii) After the execution of the following statement:

P(41, 0, 15, &SearchResult);

what is the value of SearchResult?

(5 marks)

(c) What is the algorithm used in procedure P?

(1 mark)

2001-CE-COMP STUD 1B & C-6 (C Version)


9. In an election, there can be at most 30,000 candidates, numbered 1 to 30,000. Each voter can select only one candidate by
writing the number of his/her preferred candidate on the ballot.

Cindy is going to write a C program to perform the following tasks:

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

Candidate number (enter 0 to stop data entry): 3


Candidate number (enter 0 to stop data entry): 1
Candidate number (enter 0 to stop data entry): 3
Candidate number (enter 0 to stop data entry): 3
Candidate number (enter 0 to stop data entry): 4
Candidate number (enter 0 to stop data entry): 68
Candidate number (enter 0 to stop data entry): 3
Candidate number (enter 0 to stop data entry): 1
Candidate number (enter 0 to stop data entry): 1
Candidate number (enter 0 to stop data entry): 0

Result
======
Candidate 1 |***
Candidate 2 |
Candidate 3 |****

2001-CE-COMP STUD 1B & C-7 (C Version)


Cindy has already written the declaration and the main body of the program. Some procedures are missing. Part of the
program is as follows:

#include <stdio.h>

int vote[30001];

Missing procedures here

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)

2001-CE-COMP STUD 1B & C-8 (C Version)


(b) Write the procedure CountBallots which will perform Task B.

void CountBallots(int n)
{
int ballot;

}
(4 marks)

(c) Write the procedure ShowChart which will perform Task C.

void ShowChart(int n)
{
int i, j;

}
(3 marks)

END OF SECTION B

2001-CE-COMP STUD 1B & C-9 (C Version)


Section C (16 marks plus a maximum of 4 marks for effective communication)

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)

2001-CE-COMP STUD 1B & C-10 (C Version)


(c) Mr Lee wants to have remote control of his devices at home and connects his network to the Internet. After the
connection, he can use his mobile phone to control his home devices. Give a potential risk that he may face when he
remotely controls the devices.

(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

2001-CE-COMP STUD 1B & C-11 (C Version)


A Partial Character List for ASCII

Character ASCII Character ASCII Character ASCII


0 48 J 74 d 100
1 49 K 75 e 101
2 50 L 76 f 102
3 51 M 77 g 103
4 52 N 78 h 104
5 53 O 79 I 105
6 54 P 80 j 106
7 55 Q 81 k 107
8 56 R 82 l 108
9 57 S 83 m 109
: 58 T 84 n 110
; 59 U 85 o 111
< 60 V 86 p 112
= 61 W 87 q 113
> 62 X 88 r 114
? 63 Y 89 s 115
@ 64 Z 90 t 116
A 65 [ 91 u 117
B 66 \ 92 v 118
C 67 ] 93 w 119
D 68 ^ 94 x 120
E 69 _ 95 y 121
F 70 ` 96 z 122
G 71 a 97 { 123
H 72 b 98 | 124
I 73 c 99 } 125

List of Operators and Reserved Words (C)

#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

2001-CE-COMP STUD 1B & C-12 (C Version)

You might also like