当前位置:首页 > A-LEVEL COMPUTER SCIENCE-PAPER2 9608 > 正文内容

3.     You will need to refer to the list of pseudocode string-h

3.     You will need to refer to the list of pseudocode string-handling functions in the Appendix.

 

 

ASCII code table (part)

 

Character

 

Decimal

 

Character

 

Decimal

 

Character

 

Decimal

<Space>

32

I

73

R

82

A

65

J

74

S

83

B

66

K

75

T

84

C

67

L

76

U

85

D

68

M

77

V

86

E

69

N

78

W

87

F

70

O

79

X

88

G

71

P

80

Y

89

H

72

Q

81

Z

90

 

(a)   For each statement, write the value assigned to the variable.

 

(i)    Term    CHARACTERCOUNT("TSUNAMI")

 

Term ............................................................................................................................[1]

 

(ii)    Answer1    ASC('G') + ASC(<Space>)

 

Answer1 ......................................................................................................................[1]

 

(iii)    Answer2    CHR(CHARACTERCOUNT("HELLO") + 70)

 

Answer2 ......................................................................................................................[1]

 

(iv)    Word    SUBSTR("Welcome home", 4, 7) )

 

Word ............................................................................................................................[1]

 

 

(b)  A programmer wants to design a procedure to calculate a customer ID number from the customer’s surname.

 

The procedure will:

 

•      input the surname

•      isolate each character in the surname and find the corresponding ASCII code

•      calculate the total of all these ASCII codes

•      this total is the customer ID

 

(i)    Complete the pseudocode for this procedure.

 

You will need to refer to the list of pseudocode string-handling functions in the Appendix.

 

PROCEDURE CalculateCustomerID 

     OUTPUT "Key in surname" 

     INPUT Surname

     Length <-- ............................................................................................................

 

     CustomerID <--   0

 

      FOR i <--  1 TO Length

 

            // NextChar is a single character from Surname

 

            NextChar <--...................................................................................................

 

            NextCodeNumber <--   ASC(NextChar)

 

             CustomerID  <--  CustomerID + ...................................................................

 

     ENDFOR

 

 

     OUTPUT "Customer ID is ", CustomerID

ENDPROCEDURE

                                                                                       [3]

 

 

(ii)   Write program code for procedure CalculateCustomerID.

 

Visual Basic and Pascal: You should include declaration statements for variables.

Python: You should show a comment statement for each variable used with its data type. Programming language .....................................................................................................

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

...........................................................................................................................................

 

.......................................................................................................................................[6]

 

 (c)   The programmer decides that it would be better to write the procedure as a function.

The user will now input the surname in the main program. Write program code for the following:

State your programming language ...........................................................................................

 

 

 

(i)    The function header for this new function CalculateCustomerID

 

.......................................................................................................................................[3]

 

 

 

(ii)    The additional statement required within the function body to complete the change from a procedure to a function.

 

...........................................................................................................................................

 

.......................................................................................................................................[1]

 

 

 

(iii)    The statement in the main program which:

 

•      calls the function for surname Wilkes

•      assigns the result to variable ThisID

 

.......................................................................................................................................[3]

 

 

 

(d)   (i)    The new function CalculateUserID is an example of a ‘user-defined function’.

 

State two differences between a built-in function and a user-defined function.

 

1 ........................................................................................................................................

 

...........................................................................................................................................

 

 

 

2 ........................................................................................................................................

 

.......................................................................................................................................[2]

 

 

 

(ii)    State two things that built-in and user-defined functions have in common.

 

1 ........................................................................................................................................

 

...........................................................................................................................................

 

 

 

2 ........................................................................................................................................

 

.......................................................................................................................................[2]


 

 

XX

扫描二维码免费使用微信小程序搜题/刷题/查看解析。

版权声明:本文由翰林刷题小程序授权发布,如需转载请注明出处。

本文链接:https://20230611.cn/post/18182865.html