2003 Ce Cs Paper Ibc C Version

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 2003 Ce Cs Paper Ibc C Version as PDF for free.

More details

  • Words: 2,385
  • Pages: 14
2003-CE COMP STUD

Candidate Number

PAPER I (SECT B & C)

Centre Number HONG KONG EXAMINATION AND ASSESSMENT AUTHORITY HONG KONG CERTIFICATE OF EDUCATION EXAMINATION 2003

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

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

2

3

4

Section B (40 marks) Answer ALL questions in this section. (Question 6 is out of the syllabus of Computer and Information Technology 2005) 7.

The following program is written to perform validation of a library card number. The rightmost digit is the check digit of a library card number. Line Number 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540

Program Statement #include <stdio.h> #define true 1 #define false 0 const int card_len = 8; void Read_string(char* x) { int flag; int i; do { flag = true; printf("Input card number: "); scanf("%s", x); if ( strlen(x) != card_len ) { flag = false; printf("Incorrect no. of digits!\n"); } } while ( !flag ); } int main() { char inp[80]; int i, sum, n; Read_string(inp); sum = 0; for ( i = 0; i < card_len; i++ ) { if ( (i + 1) % 2 != 0 ) { n = ((int) inp[i] - (int) '0') * 2; sum = sum + (n % 10) + (n / 10); } else { n = (int) inp[i] - (int) '0'; sum = sum + n; } } if ( sum % 10 == 0 ) printf("valid card number.\n"); else printf("invalid card number.\n"); return 0; }

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

You are not allowed to add any new variables in answering the question. Otherwise no marks will be scored. (a)

What is a check digit used for?

(1 mark) (b)

The program is executed and a user inputs ‘23731654’ into the program. (i)

Complete the following table. Values of i just after executing the for loop

n

sum

0 1 2 3 (ii)

(c)

After executing the program, (1)

the value of sum is

(2)

the output of the program is

, and . (4 marks)

The procedure Read_string() should be revised in order to perform a range check on the library card number. The number must consist of digits from ‘0’ to ‘9’ only. Insert program statements between lines 220 and 230 in order to perform the range check. Below is part of a sample output for the revised 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.) Input card number: abc18698315gc Digits from “0” to “9” only! Incorrect no. of digits! Input card number:

(3 marks)

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

(d)

The program is now rewritten in order to generate a check digit for each library card number. Suppose the lines 490 - 520 are deleted and the line 130 is modified as follows: const int card_len = 7; Insert a program statement on line 490 so that the program will generate the check digit when a 7-digit library card number is entered. Below is 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.) Input card number: 9845312 Calculated check digit is 6

(2 marks)

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

8.

The algorithm below displays all prime numbers that lie between two numbers inclusively. Step 1: Declare NUM, COUNT, LOWER and UPPER to be integer variables. Step 2: Read in the lower limit and upper limit into the variables LOWER and UPPER respectively. Step 3: Assign the value of variable LOWER to variable NUM. Step 4: As long as the value of variable NUM is less than or equal to the value of variable UPPER, do steps 5 to 9. Step 5: Assign 2 to the variable COUNT. Step 6: As long as the value of variable NUM is not divisible by the value of variable COUNT, do step 7. Step 7: Increase the value of variable COUNT by 1. Step 8: If the value of variable NUM equals the value of variable COUNT, display the value of variable NUM. Step 9: Increase the value of variable NUM by 1. Convert the algorithm into a C program.

(10 marks)

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

9.

David wants to write a C program to play a word guessing game. The program will randomly select a word from a text file which contains a list of words in small letters. It prompts the player to guess the letters belonging to the word. The player will win the game if all the letters in the word are guessed correctly within a certain number of attempts. The program will perform the following tasks: Task A: Task B:

Read all the words from a text file and randomly select a word as a secret word in the game. Initialise (1) a variable to a string of symbols ‘*’ which is of the same length as the secret word, and (2) a variable to the number of attempts remaining which is two times the length of the secret word. Task C: Ask the players to input a guess letter in each round. If the letter is the secret word, it will replace the corresponding symbol ‘*’ in the string variable. The result of the guess and the number of attempts remaining in the game will be displayed on the screen in each round. Task D: The game will terminate when the player has correctly guessed all the letters in the secret word or the number of attempts remaining in the game equals zero. Task E: Display the result to show whether the player wins or loses the program.) 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.) The secret word to be guessed is ***** No. of Attempts remaining = 10 Please input the letter you ****e No. of Attempts remaining = Please input the letter you ****e No. of Attempts remaining = Please input the letter you a***e No. of Attempts remaining = Please input the letter you app*e No. of Attempts remaining = Please input the letter you apple No. of Attempts remaining = You win!

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

guess: e 9 guess: A 8 guess: a 7 guess: p 6 guess: l 5

David 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> #include <stdlib.h> #define true 1 #define false 0 char secret[80], solution[80]; int done; char letter; int i; int noOfAttempts; Missing procedures here int main() { init(); done = false; printf("The secret word to be guessed is %s\n", solution); printf("No. of attempts remaining = %d\n\n", noOfAttempts); do { letterGuess(); winCheck(); } while ( done == false ); if ( strcmp(solution, secret) == 0 ) printf("You win!\n"); else printf("You lose!\n"); printf("\n"); getch(); return 0; } The following indicates the description of each identifier used in this program: Identifier Description secret A string variable to store the secret word solution A string variable to store the temporary result of guessing done A Boolean variable letter A character variable used to store the letter inputted by the player i An integer variable used as a counter noOfAttempts An integer variable used to store the number of attempts missing The text file consists of words made up of small letters and stores not more than 50 words. Part of the file is shown below. apple boy dog cat …

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

You are not allowed to add any new variables in answering the question. Otherwise no marks will be scored. (a)

Complete the procedure selectSecret() that will perform Task A. void selectSecret( { char word[50][80]; FILE* fp; int noOfWord;

)

fp = ("Words.txt", ); i = 0; while ( ! ) { fscanf(fp, "%s", word[i]); i = i + 1; } noOfWord = i; srand(time(NULL)); strcpy(secret, word[rand() % noOfWord]); fclose(fp); } (2 marks) (b)

Write the procedure init() that will perform Task B. void init() {

} (2 marks)

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

(c)

Write the procedure letterGuess() that will perform Task B. void letterGuess() {

} (4 marks) (d)

Write the procedure winCheck() that will perform Task B. void winCheck() {

} (2 marks)

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

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

The Automatic Teller Machine (ATM) is commonly used throughout the world for self-service money transaction. With the advancement in technology, a leading commercial bank plans to design ATM ‘kiosks’ with the following services: Existing ATM services Additional ATM services • Money transactions including withdraw, transfer • Ticket sales of movies, sports events and concerts and deposit • Interest rate enquiries • Account information enquiries • Money exchange rate enquiries Peter and Mary are the project assistants in the bank. They discuss the situation with Ms. Lee, the project manager of the bank. Below are some of their comments: Mary: ‘We have already installed a numeric keypad in each ATM kiosk. However, some customers find it inconvenient to select cinema seats when buying movie tickets. Besides a keyboard, additional input devices should be installed.’ Ms. Lee: ‘Usually, customers have to enter their passwords to log onto the ATM system. Nowadays, there are too many passwords to remember. We need other methods of customer identification.’ Peter: ‘Smart cards can be used for customer identification purposes. A memory chip storing a password is embedded in a smart card. We can give a smart card to each of our customers. Customers can insert their smart cards into smart card readers in ATM kiosks in order to log onto the ATM system.’ Ms. Lee: ‘I disagree with the use of smart cards.’ (a)

Suggest two suitable input devices to meet Mary’s concern.

(b)

(i)

Give a reason why Ms. Lee disagreed with the use of smart cards for identification purposes.

(ii)

Other than using smart cards, give another suggestion for logging onto the ATM system.

(2 marks)

(2 marks)

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

(c)

(i)

Customers can do most of their money transactions on the Internet. Give a reason why they still need to use ATMs to do some money transactions.

(ii)

Customers can buy tickets at ATM kiosks as well as on the Internet. State one advantage that buying tickets at ATM kiosks has over buying tickets on the Internet.

(2 marks)

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

The ATM kiosks will be linked up to the district computers using coaxial cables as shown in the following diagram. Each of the district computers A, B and C will store a full copy of all customers’ information.

(d)

(i)

Which ATM kiosk(s) will be affected if the district computer A is out of order?

(ii)

Name one transmission medium which would improve the speed of the data transmission between all the computers.

(iii)

During transmission, data may be read by unknown persons. Briefly describe a method to protect the data.

(4 marks)

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

(e)

Betty wants to cheat the bank. She withdraws all her money from her account in ATM kiosk 3. Then, she immediately goes to ATM kiosk 2 and withdraws money again from her account. What should the ATM system do to prevent the bank from losing money?

(4 marks) (f)

The bank wants to cut expenditure. The district computers A and B will be shut down and all ATM kiosks will be connected to the district computer C. Give two disadvantages of this implementation.

(4 marks)

END OF SECTION C END OF PAPER

2003-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

2003-CE-COMP STUD 1B & C-14 (C Version)

Related Documents