0% found this document useful (1 vote)
51 views

CS Test 1 - Memo Problem - Solving and Design

The document discusses a computer science exam with 8 questions. Question 1 asks about pseudocode features, flowcharts, and data types. Question 2 describes an algorithm to count character occurrences in a string. Question 3 is about identifying input, process, and output statements. Question 4 evaluates expressions and variable assignments. Question 5 identifies a CASE control structure. Question 6 describes loop types. Question 7 provides pseudocode for calculating array averages and zero counts. Question 8 changes an algorithm to a procedure that modifies parameters.

Uploaded by

dkandpal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
51 views

CS Test 1 - Memo Problem - Solving and Design

The document discusses a computer science exam with 8 questions. Question 1 asks about pseudocode features, flowcharts, and data types. Question 2 describes an algorithm to count character occurrences in a string. Question 3 is about identifying input, process, and output statements. Question 4 evaluates expressions and variable assignments. Question 5 identifies a CASE control structure. Question 6 describes loop types. Question 7 provides pseudocode for calculating array averages and zero counts. Question 8 changes an algorithm to a procedure that modifies parameters.

Uploaded by

dkandpal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

COMPUTER SCIENCE (AS)

8 February 2024
Length: 60 Minutes Total Allocated Marks: 50

1. Study the following pseudocode.

FUNCTION Search() RETURNS INTEGER


DECLARE N, C : INTEGER
DECLARE V, L : REAL
V GetLevel()
L V * 1.34
C 0
FOR N 1 TO 10
V GetLevel()
IF V > L
THEN
C C + 1
ENDIF
ENDFOR
OUTPUT "Process complete"
RETURN C
ENDFUNCTION

a. This pseudocode lacks features that would make it easier to read and understand.

State three such features.

Feature 1: meaningful / sensible identifier names

Feature 2: blank lines / white space

Feature 3: comments [3]

Computer Science Page 1 of 7


b. Draw a program flowchart to represent the algorithm implemented in the pseudocode.

Variable declarations are not required in program flowcharts. [6]

1(a)(ii) Mark as follows: 6


• One mark for START and END
• One mark per area outlined

At least one decision box label (YES/NO) must be


present

Computer Science Page 2 of 7


c. Programming languages support different data types.
Complete the table by giving a suitable data type for each example value. [4]

Example value Data type

"NOT TRUE" STRING

− 4.5 REAL

NOT FALSE BOOLEAN

132 INTEGER

2. A student is developing a program to count how many times each character of the alphabet
(A to Z) occurs in a given string. Upper case and lower case characters will be counted as the
same. The string may contain non-alphabetic characters, which should be ignored.

The program will:


check each character in the string to count how many times each alphabetic character occurs
output each count together with the corresponding character.

The student has written a structured English description of the algorithm:


1. START at the beginning of the string
2. SELECT a character from the string
3. CONVERT the character to upper case
4. CHECK whether the character is alphabetic and INCREMENT as required.
5. REPEAT from step 2 until last character has been checked
6. OUTPUT a suitable message giving the count of each alphabetic character

Step 4 above is not described in sufficient detail.

The student decides to apply a process to increase the level of detail given in step 4.
State the name of the process and use this process to write step 4 in more detail. Use
structured English for your answer.

Process : Stepwise Refinement / Top-down design

Structured English :

IF character IN ‘A’ to ‘Z’

THEN INCREMENT counter by 1

[4]

Computer Science Page 3 of 7


3. Simple algorithms usually consist of input, process and output.

Complete the table by placing ticks (‘3’) in the relevant boxes. [4]

Pseudocode statement Input Process Output

Temp SensorValue * Factor ✓

WRITEFILE "LogFile.txt", TextLine ✓

WRITEFILE "LogFile.txt", MyName & MyIDNumber ✓

READFILE "AddressBook.txt", NextLine ✓

4. Computer programs have to evaluate expressions.

Study the sequence of pseudocode statements.

Give the value assigned to each variable.

The statement may generate an error. If so, write ERROR.

The & operator is used to concatenate strings.

DECLARE N1, N2 : INTEGER


DECLARE
DECLARE
N2 : INTEGER
Answer : REAL
i. Answer ← 2.0
DECLARE Found, IsValid : BOOLEAN
N1 3
N2 9
ii. Answer ← 7.5

Answer ← (N1 + N2) / 6


Answer ← 3 * (N1 – 2) + N2 / 2 iii. IsValid ← False
IsValid ← (N1 > N2) AND (N2 = 9)

Found ← FALSE iv. IsValid ←True


IsValid ← (N1 > N2 / 2) OR (Found = FALSE)

Answer ← "1034" & " + " & "65" v. Answer ← ERROR


[5]

Computer Science Page 4 of 7


5. The following lines of code are taken from a program in a high-level language.

ON x {
15: Call ProcA
20: y := 0
25: y := 99
NONE: Call ProcError
}

Identify the type of control structure and describe the function of the code.

Control structure: A CASE structure

Description : Max 3 for remaining points:


 Selecting on / using variable X
 Calling ProcA if X = 15
 Assigning a value of 0 to Y if X = 20 and assign 99 to Y if X = 25
 Calling ProcError if no match (previous conditions not satisfied) // Call
ProcError if x = NONE [3]

6. One type of loop that may be found in an algorithm is a count-controlled loop.

State two other type and explain when each should be used.

Type: Post-conditional loop (repeat [loop-termination condition])

Explanation:
• executes the statements within the loop at least once.
• If the condition is FALSE the statements within the loop are executed again.
• If the condition evaluates to TRUE, execution will go to the next statement after the loop.
• The number of iterations is not known / dependent on a condition [2]

Type: Pre-conditional loop (while [loop-continuation condition])

Explanation:

• Evaluates the condition before the statements within the loop are executed.
• If the condition is TRUE the statements within the loop are executed.
• If the condition evaluates to FALSE, execution will go to the next statement after the
loop.
• The number of iterations is not known / dependent on a condition [2]

Computer Science Page 5 of 7


7. A student is developing an algorithm to search through a 1D array of 100 elements. Each
element of the array, Result, contains a REAL value.

The algorithm will output:


• the average value of all the elements
• the number of elements with a value of zero.

The structured English description of the algorithm is:

1. SET Total value to 0


2. SET Zero count to 0
3. SELECT the first element
4. ADD value of element to Total value
5. IF element value is 0 then INCREMENT Zero count
6. REPEAT from step 4 for next element, until element is last element
7. SET Average to Total / 100
8. OUTPUT a suitable message and Average
9. OUTPUT a suitable message and Zero count

Write pseudocode for this algorithm. [7]

TotalValue ← 0
ZeroCount ← 0

FOR Index ← 1 TO 100


TotalValue ← TotalValue + Result[Index]
IF Result[Index] = 0.0
THEN
ZeroCount ← ZeroCount + 1
ENDIF
ENDFOR

OUTPUT "The average is ", (TotalValue / 100)


OUTPUT "The number of elements with a zero value is ", ZeroCount

One mark for each of the following:

1 Both initialisations
2 Loop 100 times
3 Adding individual element to TotalValue in a loop
4 Check if element value is zero in a loop
5 If so increment ZeroCount in a loop
6 Average is calculated after the loop
7 Both OUTPUT statements, including message and variables

Computer Science Page 6 of 7


8. The student decides to change the algorithm and implement it as a procedure, ScanArray(),
which will be called with three parameters.

ScanArray(AverageValue, ZeroCount, ArrayName)

ScanArray() will modify the first two parameters so that the new values are available to the
calling program or module.

Write the pseudocode procedure header for ScanArray().

PROCEDURE ScanArray (BYREF AverageValue: REAL, _BYREF ZeroCount:


INTEGER, ArrayName : ARRAY)
[4]

9. Chris is asked to work on a program that has been coded in a language he is not familiar with.

He has identified that the program contains the constructs: sequence, iteration and selection.

Identify three other features of the program that he should expect to recognise.

One mark per bullet point to max 3


• Functions / Procedures / Modules / subtasks
• Parameters
• Variable / constant declaration / assignment / Data types
• Input / Output
• Arithmetic / logic operations
• Classes / Objects [3]

10. Programming languages usually contain a range of built-in functions, such as a random
number generator.

State three advantages of using built-in functions.

• Saves development time / no need to write it / can’t write it….


• Pre-compiled and tested / Increased reliability / reduces chance of error
• Is available to all programs [3]

Computer Science Page 7 of 7

You might also like