Suggested Solutions to 2001 HKCEE Computer Studies Paper I Sections B & C (C Version) 6.
Line Number 100 130 160 180 190 200 215/225 240
Program Statement scanf("%s", fn); MaxScore = -1; while ( !feof(f) ) fscanf(f, "%s%d%d", Num, &Test1, &Test2); Score = (double) (Test1 + Test2) / 2; if ( Score > MaxScore ) strcpy(MaxNum, Num); Sum = Sum + Score;
1 1 1 2 1 1 2 1
Notes:
1. For line 130, zero or any negative value can be assigned to MaxScore. 2. The line ‘strcpy(MaxNum, Num);’ can be either inserted between lines 210 and 220 or between lines 220 and 230. 7.
Step 1 lines 40 - 50 Step 2 line 60 Step 3 line 70 Step 4 lines 80, 90 and 150 Step 5 line 100 Step 6 line 110 Step 7 line 120 Step 8 lines 130 – 140 Step 9 line 160 Step 10 lines 170 – 180 Step 11 line 190 10 #include <stdio.h> 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210
8.
(a)
int main() { int dena, remdr; char newnum[80], bina[80];
} f=0 f=0 f=0 f=4 f=4 f=4
1 1 1 1 1 1 1 1 0. 5 0. 5 1
scanf("%d", &dena); strcpy(bina, ""); while ( dena > 1 ) { remdr = dena % 2; dena = dena / 2; sprintf(newnum, "%d", remdr); strcat(newnum, bina); strcpy(bina, newnum); } sprintf(newnum, "%d", dena); strcat(newnum, bina); strcpy(bina, newnum); printf("%s\n", bina); return 0; e = 15 e=6 e=6 e=6 e=6 e=6
m=7 m=7 m=3 m=3 m=5 m=5
2001-CE-COMP STUD 1B & C-1 (C Version)
1 1 0. 5 0. 5 0. 5 0. 5
(b)
(ii) (c)
if ( list[m] == t ) flag = true; else if ( list[m] < t ) e = m - 1; else f = m + 1;
(i)
-1
Binary search
2001-CE-COMP STUD 1B & C-2 (C Version)
or
if ( list[m] == t ) flag = true; else if ( list[m] > t ) f = m + 1; else e = m - 1;
4
1 1
9.
(a)
void Init(int* n) { int i;
1
printf("Number of candidates: "); scanf("%d", n); for ( i = 1; i <= *n; i++ ) vote[i] = 0;
1 1
} (b)
void CountBallots(int n) { int ballot; do { printf("Candidate number (enter 0 to stop data entry): "); scanf("%d", &ballot); if ( ballot > 0 && ballot <= n ) vote[ballot] += 1;
1 1 1
} while ( ballot != 0 );
1
} (c)
void ShowChart(int n) { int i, j; for ( i = 1; i <= n; i++ ) { printf("Candidate %d |", i); for ( j = 1; j <= vote[i]; j++ ) printf("*"); printf("\n"); }
1 1 1
} 10.
(a)
arrange the icons by usage frequency arrange the icons by functional group (any 1 valid answer)
2
(b)
Advantage: can control even at a distance or table space is not needed Disadvantage: cannot control a device when a room is very noisy or when Sunny has a cold that causes his voice changes.
4
(c)
1. 2.
authentication / security problems He may not know the current status of a device before turning it ON/OFF. This may cause hazardous consequence.
2
(d)
User id, device number, on/off record (any 2 valid items)
2
(e)
Unauthorized people may know Apple’s activities via intruding the Internet
2
2001-CE-COMP STUD 1B & C-3 (C Version)
(f)
For each remote control request check if the corresponding device is turned on locally if yes, request failed else fulfill the request For each local request fulfill the request Effective communications: Relevance
0 / 1 /2
Language/Style correct and appropriate
0/1/2
0/1/2/3/4
2001-CE-COMP STUD 1B & C-4 (C Version)