Tutorial Sheet
Tutorial Sheet
TUTORIAL SHEET
Question One
a) What is the difference between a programme and a programming language?
b) Programming language are classifies as Machine language, Assembly language, High-level
languages and Natural languages or very high-level languages. Describe advantages and
disadvantages of each.
c) What do compilers and interpreters do, and how do they differ?
Question Two
a) What is the output of the following pseudocode? (Assume the user enters 21 and all output
is displayed on the same line)
input myNumber
if myNumber > 4 then
display myNumber
else
increase myNumber by 1
endif
display myNumber
b) Design an algorithm expressed in terms of flowchart and pseudo-code for
i) Finding the sum of N numbers.
ii) Adding the test scores as given as: 26, 49, 98, 87, 62, 75
iii) Reading four numbers. If the first number is positive the algorithm should calculate
the sum of all four numbers otherwise the algorithm must calculate the average of
the last three numbers.
c) Write the basic pseudo code IF-THEN-ELSE statement for each of the following:
i) If sum is greater than 100, print sum.
ii) If sum is greater than 5, print sum else add 10 to sum.
iii) If grade is greater than or equal to 90, print “A” else if grade is greater than or equal 80,
print “B”, else print “F”.
Question Three
a) Trace through the following pseudo-code and see what output you get:
FOR row = 1 to 5
FOR col = 1 to 5
DISPLAY row + col,
DISPLAY new-line
b) Provide the output of the following program
INIT sum = 0
FOR i = 1 to 5
DISPLAY "Total ", i, ": ",
FOR j = 1 to 3
DISPLAY i + j,
sum = sum + i + j
DISPLAY " sum: ", sum
sum = 0
c) What is the output of this pseudo-code if user enters 60 at first, 70 at second, 80 at third
and -10 lastly?
Initialise: Grade = 0, Total-Grades = 0, Counter = 0
REPEAT
READ Grade
ADD Grade to Total-Grade
ADD 1 to Counter
UNTIL Grade < 0
Average-Grade = Total-Grade / Counter
WRITE "Average grade is" Average-Grad
d) Using user inputs as specified in part (c) above, what is the output of this pseudocode?
Initialise: Grade = 0, Total-Grades = 0, Counter = 0
WHILE Grade >= 0
ADD 1 to Counter
READ Grade
ADD Grade to Total-Grade
ENDWHILE
Average-Grade = Total-Grade / Counter
WRITE "Average grade is" Average-Grade
WRITE “Loop has gone ” counter “times”
Question Four
The following pseudocode describes the policy of a company to award the bonus to an
employee. If users inputs are specified as follows what is the programs output?
Cases Pay Position code Years
Case 1 $500 1 8
Case 2 $750 2 12
Case 3 $1000 3 1
Input
Employee number, pay, position code & years.
IF
position code = 1
THEN
set bonus to 1 week’s pay
ELSE
IF position code = 2
THEN
IF 2 weeks pay > 700
THEN
set bonus to 700
ELSE
set bonus to 2 week’s pay
END IF
ELSE
set Bonus to 1.5 week’s pay
END IF
END IF