Intro to Programming 2
Intro to Programming 2
4. What is the difference between the following pairs of control structures? Write a
simple code to illustrate the differences.
a. IF-THEN and IF-THEN-ELSE
b. FOR loops and WHILE loops [4 marks]
5. List any four steps that are involved in problem-solving [2 marks]
6. Give the truth table (decision table) of the AND and OR operator. [4 marks]
SECTION B
Compulsory
8. Write a program to input the maximum and minimum temperature of a day. If the
maximum temperature is greater than 30 degrees celcius, output the message “It
was a hot day!”. The program should also output the difference in the maximum
and minimum temperature. [5 marks]
SECTION C
Answer any TWO questions
10. Write a pseudocode that reads two values which are then stored in A and B. If A
is larger than B it should divide A by B and print the results else it should print “A
is not larger. The program must continue to read two more values and terminate
only if the second value is equal to zero. [10 marks]
11. The rate to travel in Kingston is $100 per km travelling by a taxi. A journey
involves two trips. Use the algorithm outline in the flowchart below to write the
corresponding pseudocode. Note DO NOT rewrite the words in the pseudocode.
[1O
marks]
Start
If total
cost is No
greater
than or
equal to
$500
Yes
Calculate a 10% discount for the
Add $50 to the total cost
passenger
Stop