Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Theme 05: Algorithms

Worksheet 2 –Operators

Questions

1. Determine the results of the following pseudo code instructions;

a. Let a = 4
Let b = 10
result = (a * b) / 2
output result

b. Let a = true
Let b = false
output a||b

c. Let y = true
Let x = true
result = x&&y
Output !result

d. Let Age = 18
Output (Age < 18)

e. Step 1: Let Total = 0


Step 2: Let value = 0
Step 3: value = value + 1
Step 4: total = Total + value
Step 5: target = (value == 10)
Step 6: IF (target == TRUE) goto step 8
Step 7: goto step 3
Step 8: Output Total

2. Determine the inputs necessary to generate the output “TRUE”

a. Input Age
Input Name
NameOK = (Name == “Freda”)
AgeOK = (Age ===18)
AllDataOK = AgeOK && NAMEOK
Output AllDataOK

b. Input Age
Input Name
NameOK = (Name == “Freda”)
AgeOK = (Age ===18)
AllDataOK = AgeOK !! NAMEOK

| Kaplan International Pathways | 1 | kaplanpathways.com


Output AllDataOK

3. Assuming a quadratic equation has the form ax 2 + bx + c = 0 write down the algorithm to ask the user for the
values of a, b and c and the output the two values of x.
Hint: You should use the quadratic formula

4. A computer is connected to three switches that can be on or off and one bulb that can be on or off.
It can read the state of each of the switches into variables, e.g:
var1 = switch1
It can turn the bulb on or off using a line of code, e.g.
Bulb = TRUE
Bulb = var1

Write short algorithms to meet the following scenarios;

a. Turn the bulb on when all three switches are on


b. Turn the bulb on when switch 1 is on and the other switches are off
c. Turn the bulb off when switch 2 is on and the other switches are off
d. Turn the bulb on when switch 3 is on and either switch 1 or 2 is on, but not both
e. Turn the bulb on when only one switch is on
f. Turn the bulb on when any two switches are on and the remaining switch is off

5. What is the statement needed to complete the algorithm below for a simple vending machine? Add ‘Yes’
and ‘labels’ as necessary.

| Kaplan International Pathways | 2 | kaplanpathways.com


| Kaplan International Pathways | 3 | kaplanpathways.com

You might also like