Eng.
Omar El Sa,y OL Computer Science
Programming Quiz 1
Name: ……………………………………..……………………………………..
1 Write down the most appropriate data type for the following examples:
Example Data Type
The age of a student integer
The full name of a student String
Whether the student has attended or not boolean
[3]
2 The variables Number1, Number2, Number3 are used to store numbers to be entered by the
user.
Write a program that would meet the following requirements:
• allow the user to input three numbers
• calculate and output the sum of the three numbers
• calculate and output the average of the three numbers
You should add comments to explain how your code works.
……………………………………………………………………………………………………………………………………
Declare Number1,Number2,Number3, Sum, Average :REAL
//entering the numbers
……………………………………………………………………………………………………………………………………
Output "Enter 3 numbers"
……………………………………………………………………………………………………………………………………
Input Number1, Number2 , Number3
……………………………………………………………………………………………………………………………………
//Calculating the sum and average
Sum <--- Number1+ Number2 + Number3
……………………………………………………………………………………………………………………………………
//Instead of re-writing it we just use 'Sum'
……………………………………………………………………………………………………………………………………
Average <--- Sum / 3
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
//outputting the answers
Output "The sum is ",Sum
……………………………………………………………………………………………………………………………………
Output "The average is ", Average
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
Eng. Omar El Sa,y OL Computer Science
[5]
3 Write a program using pseudocode that takes from the user a student mark in an exam and
the program should calculate and output the percentage.
The exam is out of 25
Percentage = (Mark / 25) * 100
Output Invalid mark if the user entered a negative number or a number greater than 25
You should add comments to explain how your code works.
DECLARE Mark: INTEGER
……………………………………………………………………………………………………………………………………
DECLARE Percentage: REAL
……………………………………………………………………………………………………………………………………
//Inputting the mark
Output "What was your mark?"
……………………………………………………………………………………………………………………………………
Input Mark
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
//calculating that the mark should not be over or under
……………………………………………………………………………………………………………………………………
IF Mark >25 OR Mark <0 THEN
Output "Invalid Mark"
……………………………………………………………………………………………………………………………………
Else
……………………………………………………………………………………………………………………………………
Percentage <--- (Mark/25) * 100
……………………………………………………………………………………………………………………………………
//calculated the percentage
Output "Percentage = ",Percentage [5]
ENDIF
Eng. Omar El Sa,y OL Computer Science
4 The variable pH is used to store the pH value of a chemical solution.
Write a program that would meet the following requirements:
• output Invalid pH if the pH is less than 0 or greater than 14
• output Acidic if the pH is between 0 and 6 inclusive
• output Alkaline if the pH is between 8 and 14 inclusive
• output Neutral if the pH is greater than 6 and less than 8
You should add comments to explain how your code works.
DECLARE pH : INTEGER
……………………………………………………………………………………………………………………………………
Output "Enter the pH"
……………………………………………………………………………………………………………………………………
Input pH
……………………………………………………………………………………………………………………………………
//checking that is not negative or greater than 14
……………………………………………………………………………………………………………………………………
IF pH <0 OR pH >14 THEN
……………………………………………………………………………………………………………………………………
Output "Invalid pH"
ELSE
……………………………………………………………………………………………………………………………………
IF pH >=0 AND pH <=6 THEN
……………………………………………………………………………………………………………………………………
//Must be within the range to output that answer
……………………………………………………………………………………………………………………………………
Output "Acidic"
……………………………………………………………………………………………………………………………………
ELSE
IF pH >=8 AND pH <=14 THEN
……………………………………………………………………………………………………………………………………
Output "Alkaline"
……………………………………………………………………………………………………………………………………
ELSE
……………………………………………………………………………………………………………………………………
Output "Neutral"
ENDIF
……………………………………………………………………………………………………………………………………
ENDIF
……………………………………………………………………………………………………………………………………
ENDIF
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………………
[6]
Eng. Omar El Sa,y OL Computer Science
5 State the output of the following program if the value stored in Number1 is 4 and the value
stored in Number2 is 5
IF Number1 = Number2 THEN
OUTPUT "Equal"
ELSE
IF Number1 > Number2 THEN
OUTPUT "The larger number is ", Number1
ELSE
OUTPUT "The larger number is ", Number2
ENDIF
ENDIF
………………………………………………………………………………………………………………………………[1]
-The larger number is 5
6 The following program should display Valid if the weight is greater than or equal to 0 and
display Invalid otherwise.
01 DECLARE Weight : REAL
02 INPUT Weights
03 IF Weight > 0 THEN
04 OUTPUT "Invalid"
05 ELSE
06 OUTPUT "Valid"
07 ENDIF
(a) Give the line number(s) from the algorithm of
lines 3,5,7
a conditional statement ………………………………………………………………………………………………….
line 2
an input statement ………………………………………………………………………………………………………...
lines 4,6
an output statement ……………………………………………………………………………………………………….
[3]
There are two errors in the code.
(b) Identify the two errors in the pseudocode and suggest corrections.
line 3
Error 1 …………………………………………………………………………………………………………………………
should be IF Weight >=0 THEN
……………………………………………………………………………………………………………………………………
Line 2
Error 2 …………………………………………………………………………………………………………………………
should be INPUT Weight not weights
……………………………………………………………………………………………………………………………………
[2]