KEMBAR78
As Compsci Mock p2 | PDF | Boolean Data Type | Integer (Computer Science)
0% found this document useful (0 votes)
24 views17 pages

As Compsci Mock p2

The document contains a series of questions related to computer science concepts, including pseudocode, algorithms, program development life cycle, validation functions, and state-transition diagrams. It also includes tasks for completing tables, writing pseudocode, and explaining constructs in programming. The document is structured as an examination paper with multiple sections and questions for students to answer.

Uploaded by

Ahmad Jailbreak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views17 pages

As Compsci Mock p2

The document contains a series of questions related to computer science concepts, including pseudocode, algorithms, program development life cycle, validation functions, and state-transition diagrams. It also includes tasks for completing tables, writing pseudocode, and explaining constructs in programming. The document is structured as an examination paper with multiple sections and questions for students to answer.

Uploaded by

Ahmad Jailbreak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Refer to the insert for the list of pseudocode functions and operators.

1 (a) (i) Complete the following table by giving the appropriate data type in each case.

Variable Example data value Data type


Name "Catherine"
Index 100
Modified FALSE
Holiday 25/12/2020
[4]

(ii) Evaluate each expression in the following table by using the initial data values shown in
part (a)(i).

Expression Evaluates to
Modified OR Index > 100
LENGTH("Student: " & Name)
INT(Index + 2.9)
MID(Name, 1, 3)
[4]

(b) Each pseudocode statement in the following table contains an example of selection,
assignment or iteration.

Put one tick (‘✓’) in the appropriate column for each statement.

Statement Selection Assignment Iteration


Index Index + 1
IF Modified = TRUE THEN
ENDWHILE
[3]

9618 Computer Science - Paper 2 1 of 17


2 An algorithm will:

1. prompt and input a sequence of 100 integer values, one at a time


2. sum the positive integers
3. output the result of the sum.

(a) Write pseudocode for the algorithm.

Assume the value zero is neither positive nor negative.

You must declare all variables used in the algorithm.

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [5]

(b) The algorithm requires the use of basic constructs. One of these is sequence.

Identify one other basic construct required by the algorithm and describe how it is used.

Construct ..................................................................................................................................

Use ...........................................................................................................................................

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

9618 Computer Science - Paper 2 2 of 17


3 A software developer follows a program development life cycle. The life cycle divides the
development process into various stages.

(a) The following table lists some development activities.

Complete the table by writing the name of the life cycle stage for each activity.

Activity Name of life cycle stage

The walkthrough method is used.

An algorithm is implemented in a programming language.

The client is interviewed about problems with the current system.

The program is modified to run on new hardware.

Records and file structures are defined.

[5]

(b) The program contains a validation function.

(i) The function will:

• take an integer value as a parameter


• return TRUE if the value is within the range 24 to 37, inclusive
• otherwise return FALSE.

Complete the table to define a test plan to thoroughly test the operation of the function.

Type of test data Test data value Expected result

Normal 30 TRUE

[4]

(ii) The function is to be tested on its own. When it is shown to work correctly the function
will be combined with other modules and testing will continue.

Identify the type of testing that this represents.

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

9618 Computer Science - Paper 2 3 of 17


4 A program contains six modules with headers as follows:

Pseudocode module header


PROCEDURE Connect()
FUNCTION Activate(H1 : STRING, Code : INTEGER) RETURNS BOOLEAN
FUNCTION Sync(T1 : BOOLEAN, S2 : REAL) RETURNS INTEGER
PROCEDURE Initialise(BYREF ID : INTEGER, BYVAL CC : INTEGER)
FUNCTION Reset(RA : STRING) RETURNS INTEGER
FUNCTION Enable(SA : INTEGER) RETURNS BOOLEAN

Module Connect() will call either Activate() or Sync(). This is decided at run-time.

(a) Complete the structure chart for these modules.

Connect

T1

[5]

(b) Explain the meaning of the curved arrow symbol used in the diagram in part (a).

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

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

9618 Computer Science - Paper 2 4 of 17


5 An algorithm has three steps. It will:
1. repeatedly input a pair of numeric values A and B
2. count the number of pairs that are input until A has been greater than B 10 times
3. output the number of pairs that were input.

(a) Complete the program flowchart.

START

INPUT A, B

Yes

No

END

[5]

9618 Computer Science - Paper 2 5 of 17


6 A shop sells sandwiches and snacks. The owner chooses a ‘daily special’ sandwich which is
displayed on a board outside the shop. Each ‘daily special’ has two different fillings and is made
with one type of bread.

The owner wants a program to randomly choose the ‘daily special’ sandwich.

The program designer decides to store the possible sandwich fillings in a 1D array of type string.

The array is declared in pseudocode as follows:

DECLARE Filling : ARRAY [1:35] OF STRING

Each element contains the name of one filling.

An example of the first five elements is as follows:

Index Element value


1 "Cheese"

2 "Onion"

3 "Salmon"

4 "Anchovies"

5 "Peanut Butter"

A second 1D array stores the possible bread used:

DECLARE Bread : ARRAY [1:10] OF STRING

Each element contains the name of one type of bread.

An example of the first three elements is as follows:

Index Element value


1 "White"

2 "Brown"

3 "Pitta"

Both arrays may contain unused elements. The value of these will be an empty string and they
may occur anywhere in each array.

A procedure Special() will output a message giving the ‘daily special’ sandwich made from two
randomly selected different fillings and one randomly selected bread.

Unused array elements must not be used when creating the ‘daily special’ sandwich.

Using the above examples, the output could be:

"The daily special is Cheese and Onion on Brown bread."

9618 Computer Science - Paper 2 6 of 17


(a) Complete the pseudocode for the procedure Special().

Assume that both arrays are global.

PROCEDURE Special()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ENDPROCEDURE
[7]

9618 Computer Science - Paper 2 7 of 17


(b) The owner decides that some combinations of fillings do not go well together. For example,
anchovies and peanut butter.

Describe how the design could be changed to prevent certain combinations being selected.

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

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

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

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

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

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

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

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

9618 Computer Science - Paper 2 8 of 17


7 A computer system for a shop stores information about each customer. The items of information
include name and address (both postal and email) together with payment details and order history.
The system also stores the product categories they are interested in and how they would like to be
contacted.

(a) The shop wants to add a program module that will generate emails to be sent to customers
who may be interested in receiving details of new products.

(i) State three items of information that the new module would need. Justify your choice in
each case.

Information ........................................................................................................................

Justification .......................................................................................................................

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

Information ........................................................................................................................

Justification .......................................................................................................................

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

Information ........................................................................................................................

Justification .......................................................................................................................

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

(ii) Identify two items of customer information that would not be required by the new module.
Justify your choice in each case.

Information ........................................................................................................................

Justification .......................................................................................................................

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

Information ........................................................................................................................

Justification .......................................................................................................................

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

9618 Computer Science - Paper 2 9 of 17


(b) The program includes a module to validate a Personal Identification Number (PIN). This is
used when customers pay for goods using a bank card.

A state‑transition diagram has been produced for this module.

The table show the inputs, outputs and states for this part of the program:

Current state Input Output Next state


S1 Input PIN S2
S2 Re‑input PIN Display error S2
S2 Cancel Re‑prompt S1
S2 Valid PIN Enable payment S4
S2 Too many tries Block Account S3

Complete the state‑transition diagram to represent the information given in the table.

S2

START
S1

Cancel | Re-prompt

[4]

9618 Computer Science - Paper 2 10 of 17


8 A computer shop assembles computers using items bought from several suppliers. A text file
Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:
<ItemNum><SupplierCode><Description>

Valid item information is as follows:

Format Comment
unique number for each item in the range
ItemNum 4 numeric characters
″0001″ to ″5999″ inclusive

SupplierCode 3 alphabetic characters to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.

A programmer has started to define program modules as follows:

Module Description
OnlyAlpha() • called with a parameter of type string
(already written)
• returns TRUE if the string contains only alphabetic characters,
otherwise returns FALSE
CheckInfo() • called with a parameter of type string representing a line of item
information
• checks to see whether the item information in the string is valid
• returns TRUE if the item information is valid, otherwise returns
FALSE

9618 Computer Science - Paper 2 11 of 17


(a) Write pseudocode for module CheckInfo().

Module OnlyAlpha() should be used as part of your solution.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

9618 Computer Science - Paper 2 12 of 17


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

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

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

............................................................................................................................................. [7]

(b) A new module is defined as follows:

Module Description
AddItem() • called with a parameter of type string representing valid information
for a new item that is not currently in the Stock.txt file
• creates a new file NewStock.txt from the contents of the file
Stock.txt and adds the new item information at the appropriate
place in the NewStock.txt file

As a reminder, the file Stock.txt is organised in ascending order of ItemNum and does not
contain all possible values in the range.

Write pseudocode for module AddItem().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

9618 Computer Science - Paper 2 13 of 17


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

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

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

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

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

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

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

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

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

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

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

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

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

............................................................................................................................................. [7]

(c) The program contains modules SuppExists() and CheckSupplier(). These have been
written but contain errors. These modules are called from several places in the main program
and testing of the main program (integration testing) has had to stop.

Identify a method that can be used to continue testing the main program before the errors in
these modules have been corrected and describe how this would work.

Method ......................................................................................................................................

Description ................................................................................................................................

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

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

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

9618 Computer Science - Paper 2 14 of 17


Functions
Note: An error will be generated if a function call is not properly formed or if the parameters are of an
incorrect type or an incorrect value.

String and Character Functions

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"
RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING
returns rightmost X characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"
MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING
returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns string "BCD"
LENGTH(ThisString : STRING) RETURNS INTEGER
returns the integer value representing the length of string ThisString
Example: LENGTH("Happy Days") returns 10
LCASE(ThisChar : CHAR) RETURNS CHAR
returns the character representing the lower-case equivalent of ThisChar
Alphabetic characters that are not upper case are returned unchanged.
Example: LCASE('W') returns 'w'
UCASE(ThisChar : CHAR) RETURNS CHAR
returns the character representing the upper-case equivalent of ThisChar
Alphabetic characters that are not lower case are returned unchanged.
Example: UCASE('a') returns 'A'
TO_UPPER(ThisString : STRING) RETURNS STRING
returns a string formed by converting all characters of ThisString to upper case.
Example: TO_UPPER("Error 803") returns "ERROR 803"
TO_LOWER(ThisString : STRING) RETURNS STRING
returns a string formed by converting all characters of ThisString to lower case.
Example: TO_LOWER("JIM 803") returns "jim 803"
NUM_TO_STR(x : <datatype1>) RETURNS <datatype2>
returns a string representation of a numeric value.
Note: <datatype1> may be REAL or INTEGER, <datatype2> may be CHAR or STRING
Example: NUM_TO_STR(87.5) returns "87.5"
STR_TO_NUM(x : <datatype1>) RETURNS <datatype2>
returns a numeric representation of a string.
Note: <datatype1> may be CHAR or STRING, <datatype2> may be REAL or INTEGER
Example: STR_TO_NUM("23.45") returns 23.45

9618 Computer Science - Paper 2 15 of 17


String and Character Functions

IS_NUM(ThisString : <datatype>) RETURNS BOOLEAN


returns the value TRUE if ThisString represents a valid numeric value.
Note: <datatype> may be CHAR or STRING
Example: IS_NUM("-12.36") returns TRUE
ASC(ThisChar : CHAR) RETURNS INTEGER
returns an integer value (the ASCII value) of character ThisChar
Example: ASC('A') returns 65, ASC('B') returns 66, etc.
CHR(x : INTEGER) RETURNS CHAR
returns the character whose integer value (the ASCII value) is x
Example: CHR(65) returns 'A', CHR(66) returns 'B', etc.

Numeric Functions

INT(x : REAL) RETURNS INTEGER


returns the integer part of x
Example: INT(27.5415) returns 27
RAND(x : INTEGER) RETURNS REAL
returns a real number in the range 0 to x (not inclusive of x).
Example: RAND(87) could return 35.43

Date Functions

Note: Date format is assumed to be DD/MM/YYYY unless otherwise stated.

DAY(ThisDate : DATE) RETURNS INTEGER


returns the current day number from ThisDate
Example: DAY(04/10/2003) returns 4
MONTH(ThisDate : DATE) RETURNS INTEGER
returns the current month number from ThisDate
Example: MONTH(04/10/2003) returns 10
YEAR(ThisDate : DATE) RETURNS INTEGER
returns the current year number from ThisDate
Example: YEAR(04/10/2003) returns 2003
DAYINDEX(ThisDate : DATE) RETURNS INTEGER
returns the current day index number from ThisDate where Sunday = 1, Monday = 2, etc.
Example: DAYINDEX(12/05/2020) returns 3
SETDATE(Day, Month, Year : INTEGER) RETURNS DATE
returns a variable of type DATE with the value of <Day>/<Month>/<Year>
TODAY() RETURNS DATE
returns a variable of type DATE with the value set to the current date.

9618 Computer Science - Paper 2 16 of 17


Text File Functions

EOF(FileName : STRING) RETURNS BOOLEAN


returns TRUE if there are no more lines to be read from file FileName
Note: The function will generate an error if the file is not already open in READ mode.

Operators

Note: An error will be generated if an operator is used with a value or values of an incorrect type.

Concatenates (joins) two strings


& Example: "Summer" & " " & "Pudding" evaluates to "Summer Pudding"
Note: May also be used to concatenate a CHAR with a STRING

Performs a logical AND on two Boolean values


AND
Example: TRUE AND FALSE evaluates to FALSE

Performs a logical OR on two Boolean values


OR
Example: TRUE OR FALSE evaluates to TRUE

Performs a logical NOT on a Boolean value


NOT
Example: NOT TRUE evaluates to FALSE

Finds the remainder when one number is divided by another


MOD
Example: 10 MOD 3 evaluates to 1

Finds the quotient when one number is divided by another


DIV
Example: 10 DIV 3 evaluates to 3

Comparison Operators

= Used to compare two items of the same type. Returns TRUE if the condition is true,
otherwise returns FALSE
>
Notes:
<
• may be used to compare types REAL and INTEGER
• may be used to compare types CHAR and STRING
>=
• case sensitive when used to compare types CHAR or STRING
• cannot be used to compare two records.
<= Examples:
• "Program" = "program" evaluates to FALSE
<> • count = 4 evaluates to TRUE when variable count contains the value 4

9618 Computer Science - Paper 2 17 of 17

You might also like