Q1 Write the operator type (Logical, Boolean Arithmetic) for the
following operators: [3]
1. <>:_________________
2. OR:________________
3. MOD:________________
4. NOT:________________
5. <=:________________
6. +:________________
Q2 Mach with correct descriptions: [4]
Q3 State the data type of the following variable: [3]
1. A<-“Elephant” :________________
2. B<-150:________________
3. C<- TRUE:________________
4. D<-“120” :________________
5. E<-‘%’ :________________
6. F<-12.5:________________
Q4 Numbers are input. The number -1 is the last number to be input and
is ignored.
(a) Write an algorithm in pseudocode to count and output how
many even numbers were input.You do not need to validate the
input. [4]
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
(b) Write an algorithm in pseudocode to total and output the sum of all
odd numbers input.You do not need to validate the input. [4]
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q5 Use a CASE statement to ask the user to enter a number between 1
and 7 and display the day of the week (1 = Monday, ..., 7 = Sunday).
Otherwise, display "Invalid day". [5]
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q6 Use IF statement. Input temperature and display: [4]
"Freezing" if < 0
"Cold" if between 0 and 15
"Warm" if between 16 and 30
"Hot" if > 30
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q7 A programmer has written a program that will be maintained by
another programmer. Explain how the program can be written to
make sure it can be easily maintained by the other programmer. [6]
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q8 a)Write a procedure named average that takes two numbers as
parameter and outputs their average. [3]
b) Write the pseudocode to use a procedure named Average that
passes the values 25 and 50 to the procedure.[2]
__________________________________________________________
__________________________________________________________
c) Outline the role of procedures and functions in creating a
program that is easier to maintain. [3]
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q9 a)Write a function called FindMax that:
Takes two integers as parameters
Returns the larger of the two values [4]
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
b) Then write a line of pseudocode to call the function using inputs a
and b, and store the result in a variable called maxValue [2]
__________________________________________________________
__________________________________________________________
Q10 Write pseudocode that: [5]
Asks the user to enter a password
Repeats until the user enters the correct password "Open123"
When the correct password is entered, display "Access
Granted"
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q11 Write pseudocode to: [4]
Ask the user to input a number (e.g., 7)
Use a FOR loop to output the first 10 multiples of that number
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q12 The function LENGTH(X) finds the length of a string X.
The function SUBSTRING(X, Y, Z) finds a substring of X starting at position Y
and Z characters long. The first character in X is in position 1.
Write pseudocode statements to: [6]
Store the string "Data structures are useful" in variable A
Find the length of the string and store it in variable L
Extract the word "useful" from the string and output it
Output original string in lower case
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
Q13 A function LENGTH(X) finds the length of a string X and a function
SUBSTRING(X, Y, Z) finds a substring of X starting at position Y and Z
characters long. The first character in the string is position 1.
Show the value of the variable after each pseudocode statement has been
executed:[5]
01 A ← "Artificial Intelligence":______________________________
02 B ← LENGTH(A) :______________________________
03 C ← SUBSTRING(A, 12, 5) :______________________________
04 D ← LENGTH(C) :______________________________
05 E ← SUBSTRING(C, 2, 3) :______________________________