2002-CE COMP STUD
Candidate Number
PAPER I (SECT B & C)
Centre Number HONG KONG EXAMINATION AND ASSESSMENT AUTHORITY HONG KONG CERTIFICATE OF EDUCATION EXAMINATION 2002
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 Use Only Marker No.
Examiner’s Use Only Examiner No.
Q.6 Q.7 Instructions: 1.
Write your Candidate Number, Centre Number and Seat Number in the spaces provided.
2.
Answer all questions.
Q.8 Q.9 Q.10 Q.10
0
1
2
3
4
0
1
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
2002-CE-COMP STUD 1B & C-1 (C Version)
2
3
4
Section B (40 marks) Answer ALL questions in this section. 6.
Mr. Lee wants to write a program to simulate the ‘find and replace’ function of a word processing software package. Given a text file ‘CE.TXT’ stored in a diskette with the following contents: Hong Kong Examination Authority* Hong Kong Certificate of Education Examination 2002* Computer Studies* Paper 1B and 1C* Each line ends with an asterisk (*). The program is to read the text line by line to replace all space characters by colon (:), and to produce the output on the VDU as shown below: Output: Hong:Kong:Examination:Authority* Hong:Kong:Certificate:of:Education:Examination:2002* Computer:Studies* Paper:1B:and:1C* Number of replacements: 13
2002-CE-COMP STUD 1B & C-2 (C Version)
Mr. Lee’s program is shown below: Line Number Program Statement #include <stdio.h> 100 110 int main() 120 { 130 const char SearchChar = ' '; 140 const char ReplaceChar = ':'; 150 const char FileName[] = "CE.TXT"; 160 FILE* DiskFile; 170 string ch; 180 int TotalReplaced; 190 char temp[80]; 200 210 DiskFile = fopen(FileName); 220 while ( feof(DiskFile) ) 230 { 240 do 250 { 260 fscanf(DiskFile, "%s", &ch); 270 if ( ch == ReplaceChar ) 280 { 290 printf("%c", SearchChar); 300 TotalReplaced + 1 = TotalReplaced; 310 else 320 printf("%c", ch); 330 } while ( ch == '*' ); 340 printf("\n"); 350 fgets(temp, 80, DiskFile); 360 } 370 fclose(DiskFile); 380 printf("Number of replacements: %d\n", TotalReplaced); 390 400 return 0; 410 } 420 However, there are several mistakes after line 170 in the program. Fill in the following table to show the location of each mistake and its correction. Line Number
Corrected Statement
(10 marks)
2002-CE-COMP STUD 1B & C-3 (C Version)
7.
Below is an algorithm of a program that generates a sequence of positive integers. The integers should be less than or equal to the value stored in an integer variable limit. The value is entered via the keyboard by a user during execution of the program. Step 1: Step 2: Step 3: Step 4: Step 5: Step 6:
Declare former, latter, limit and cnt to be integer variables. Read an integer into variable limit. Assign 1 to variable former. Assign 1 to variable latter. Assign 0 to variable cnt. As long as the value of variable former is smaller than or equal to the value of variable limit, repeat steps 7 to 11: Step 7: Display the value of variable former having the cursor stay on the same line. Step 8: Increase the value of variable latter by the value of variable former. Step 9: Subtract the value of variable former from that of variable latter, and assign the result into variable former. Step 10: Increase the value of variable cnt by 1. Step 11: If the value of variable cnt is divisible by 6, advance the cursor to the next line. Convert the algorithm into a C program.
(10 marks)
2002-CE-COMP STUD 1B & C-4 (C Version)
8.
The program below provides an encoding procedure Encode for an English word and a corresponding decoding procedure Decode to decode the encoded English word. Some program statements of the Decode procedure are missing. Line Number 100
Program Statement #include <stdio.h>
110
const int M = 5, D = 21, N = 26, A = 65;
120 130 140 150 160
void Encode(char* C, char* P) { char Ch; char Tmp[2]; int Len, Count, Asc; strcpy(P, ""); strcpy(Tmp, " "); Len = strlen(C); for ( Count = 0; Count < Len; Count++ ) { Ch = C[Count]; Asc = (int) Ch - A; Asc = (M * Asc) % N; Tmp[0] = (char) (Asc + A); strcat(P, Tmp); }
170 180 190 200 210 220 230 240 250 260 270 280
}
290 300 310 320 330
void Decode(Missing statement) { char Ch; char Tmp[2]; int Len, Count, Asc; strcpy(C, ""); strcpy(Tmp, " "); Missing statements
340 350 800
}
810 820 830
int main() { char ENG[1024], SEC[1024];
840 850 860 870
printf("Please type an English word:"); scanf("%s", ENG); Encode(ENG, SEC); printf("The resulting secret word is:%s\n", SEC);
880 890 900 910
printf("Please type a secret word:"); scanf("%s", SEC); Decode(SEC, ENG); printf("The original English word is:%s\n", ENG);
920 930
return 0; }
2002-CE-COMP STUD 1B & C-5 (C Version)
You are not allowed to add any new variable in answering the question. (a)
(i)
If the program segment from lines 840 to 870 is executed and the string variable ENG stores ‘ABLE’ as input, complete the following: After executing the for loop when Count equals 0, Ch =
, Tmp =
,P=
.
After executing the for loop when Count equals 1, Ch =
, Tmp =
,P=
.
After executing the for loop when Count equals 2, Ch =
, Tmp =
,P=
.
After executing the for loop when Count equals 3, Ch =
, Tmp =
,P=
.
In line 870, SEC = (ii)
.
The encoding and the decoding formulae in the program are P = (5 C) mod 26 and C = (21 P) mod 26 respectively where P and C are integers from 0 to 25. By using these two formulae, complete the procedure Decode to decode the string stored in the variable SEC generated by the procedure Encode. void Decode( { char Ch; char Tmp[2]; int Len, Count, Asc;
)
strcpy(C, ""); strcpy(Tmp, " ");
} (iii)
(b)
Write down the output of the variable ENG if the above procedure Decode is applied to the string stored in the variable SEC in (a)(i) and the decoding formulae is changed to C = (20 P) mod 26.
(8 marks) If this program is going to handle only small case letters (a ... z), one statement in the program should be changed. Write down the line number and the amended statement. (2 marks)
2002-CE-COMP STUD 1B & C-6 (C Version)
9.
Tom writes a C program to check whether an English word is an anagram of another English word. One English word is an anagram of another English word if the second word is made by changing the order of the letters of the first word. For example,
(1) ITEM is an anagram of TIME (2) EXAM is not anagram of TIME Assume that all inputs are correct English words composed of letters of the English alphabet only. Tom is going to write a C program to perform the following tasks: Task I. Initialise two arrays to store the frequencies of the letters in each of the two words. Task II. Input two English words. Task III. Check whether the number of letters in the two words are equal. Task IV. Change all the letters in the words into upper case. Task V. Calculate the frequencies of letters in each word. Task VI. Check whether the second word is an anagram of the first word. Task VII. Display the result of this checking. The following shows sample outputs of the program. (In these outputs, all the data following a colon is entered by the user via the keyboard. All other items are output from the program.) Sample Output 1 Input the first English word:TIME Input the second English word:ITEM ITEM is an anagram of TIME Sample Output 2 Input the first English word:time Input the second English word:ITEM ITEM is an anagram of TIME Sample Output 3 Input the first English word:TIME Input the second English word:EXAM EXAM is not an anagram of TIME
2002-CE-COMP STUD 1B & C-7 (C Version)
Tom 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> #define true 1 #define false 0 int freq1[26], freq2[26]; char word1[1024], word2[1024]; int match; void Init() { int i; for ( i = 0; i < 26; i++ ) { freq1[i] = 0; freq2[i] = 0; } }
Missing procedures int main() { match = true; Init(); InputWords(); CheckLength(); if ( match ) { ChangeUpper(word1); ChangeUpper(word2); CalFreq(); CheckMatching(); } if ( match ) printf("%s is an anagram of %s\n", word2, word1); else printf("%s is not an anagram of %s\n", word2, word1); return 0; } The following indicates the description of each identifier used in this program: Identifiers freq1 freq2 word1 word2 i match st
Description an array used to store the frequency of letters in the first English word an array used to store the frequency of letters in the second English word a variable used to store the first English word a variable used to store the second English word an integer variable used as a counter in procedures Init, ChangeUpper, CalFreq, CheckMatching a Boolean variable a string variable parameter in procedure ChangeUpper
2002-CE-COMP STUD 1B & C-8 (C Version)
You are not allowed to use any new variable in answering the question unless otherwise stated. (a)
Write the procedure InputWords that will perform Task II. void InputWords() {
} (1 mark) (b)
Write the procedure CheckLength that will perform Task III. void CheckLength() {
} (2 marks)
2002-CE-COMP STUD 1B & C-9 (C Version)
(c)
Complete the procedure parameter and write the procedure ChangeUpper that will perform Task IV. void ChangeUpper( { int i;
)
} (3 marks) (d)
Write the procedure CalFreq that will perform Task V. void CalFreq () { int i;
} (2 marks)
2002-CE-COMP STUD 1B & C-10 (C Version)
(e)
Write the procedure CheckMatching that will perform Task V. void CheckMatching() { int i;
} (2 marks)
2002-CE-COMP STUD 1B & C-11 (C Version)
Section C (16 marks plus a maximum of 4 marks for effective communication) 10.
Mr. Wong is the owner of a large bookstore in a shopping center in Hong Kong operating 12 hours a day. All books are sold to customers directly in the bookstore. He would like to build a web site for his bookstore to further develop his book selling business. Mary is a consultant. After talking with Mr. Wong, she proposed to establish a web site by following the steps below: • • • • • • •
Define the contents of the web site. Scan pictures and book covers. Compose the web pages. Set up a data connection line to connect to the Internet. Set up a web server to store the web pages. Set up an electronic mail server to handle electronic mail. Set up a database server to process customer information and enquiries.
Amy, Betty, Catherine and David are the senior assistants in the bookstore. They discussed the situation with Mr. Wong. Below are some of their comments: Mr. Wong: ‘Amy is experienced in managing information technology (IT) projects. She should take up this new task.’ Amy: ‘I need two more IT professionals to help me compose the web pages.’ Betty: ‘We have good face-to-face enquiry customer service in our shop. I do not think we need the electronic mail service. It is redundant.’ Catherine: ‘We should not provide too many services at the very beginning. We only need to provide essential services on the web site so that the customers can enjoy the services as if they are visiting our shop.’ David: ‘The web site will bring a huge profit to our bookstore immediately.’ (a)
(i)
What type of software can be used to view the web pages via the Internet?
(ii)
When ordering books through the Internet, customers are afraid that their personal information may be disclosed to unknown parties during data transmission. Suggest one method to protect data from unauthorized access.
(2 marks) (b)
Suggest two types of IT professionals who could help Amy compose web pages for the bookstore.
(2 marks)
2002-CE-COMP STUD 1B & C-12 (C Version)
(c)
Mr. Wong disagreed with Betty’s opinion. Though electronic mail service cannot provide face-to-face customer service, it has some advantages for providing enquiry service. State THREE advantages.
(3 marks) (d)
Mr. Wong agreed with Catherine’s opinion. Suggest and describe THREE essential services that the web site should provide in addition to the electronic mail service.
(6 marks) (e)
Mr. Wong disagreed with David’s opinion. Give THREE reasons to support Mr. Wong’s view.
(3 marks)
END OF SECTION C END OF PAPER
2002-CE-COMP STUD 1B & C-13 (C Version)
A Partial Character List for ASCII Character 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I
ASCII 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
Character J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c
ASCII 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
Character d e f g h I j k l m n o p q r s t u v w x y z { | }
ASCII 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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
2002-CE-COMP STUD 1B & C-14 (C Version)