Unit 8 - Com Science Exam - Style Q
Unit 8 - Com Science Exam - Style Q
Dakshesh
PART 1 - ARRAYS
Q1.1
(a) Line Numbers for Statements:
- Assignment statement: Line , Line , Line , Line
- Selection statement: Line , Line
- Iteration statement: Line , Line
Q1.2
(a) Linear Search Algorithm in Pseudocode:
FOR I ← 1 TO 49
FOR J ← 1 TO (50 - I)
IF Values[J] > Values[J + 1] THEN
Temp ← Values[J]
Values[J] ← Values[J + 1]
Values[J + 1] ← Temp
ENDIF
NEXT J
NEXT I
Q1.3
(a) Purpose of the Pseudocode Algorithm:
The purpose of this algorithm is to input a list of names and sort them in ascending order.
Q2.2
A programmer uses procedures and parameters to:
- Modularize code, making it easier to manage and reuse.
- Pass data between different parts of a program without redundancy.
Q2.3
DIV: The DIV routine performs integer division, returning the quotient without the remainder.
ROUND: The ROUND routine rounds a real number to a specified number of decimal places.
Q2.4
MOD: The MOD routine returns the remainder of integer division between two numbers.
RANDOM: The RANDOM routine generates a random number within a specified range.
Q2.5
When a function is called during program execution:
- The program control is transferred to the function.
- The function executes its statements and may return a value.
- After execution, control returns to the point where the function was called.
Q3.1
(a)
(b)
Q3.2
Q3.3
(a)
Q3.4
(a)
LengthOfPhrase ← LENGTH(Phrase)
OUTPUT LPhrase // Outputs length of string.
OUTPUT UCASE(Phrase) // Outputs string in upper case.
(b) Output should produce:
Q3.5
(a)
DECLARE P : STRING
DECLARE Q : CHAR
P ← "The world"
Q ← 'w'
(b)
(c) After execution, if 'P' is "THE WORLD", Position will hold the value corresponding to 'W'.
Q3.6
(a)
(b)