# 10 - Interpret Correct or Complete Algorithms #2

1. What does this algorithm do?
```function add(firstNum, secondNum)
total = firstNum + secondNum
endfunction

None of the above

two arguments are taken and the total is always equivalent to 5 or 3

two arguments firstNum and secondNum are taken and added together

two numbers (always 5 and 3) are taken and subtracted

2. The following algorithm prints out the times table of the number entered using a count controlled loop
```01 input b
02 for x = 1 to 100
03     print b * x
04 next```

FALSE

TRUE

3. In the following code, line 2 is an assignment operator/ assigns a value to x and….
```01 input y
02 x = y MOD 5
03 if x == 0 then
04     print “True”
05 end if
```

Line 03 = is a comparison operator / compare the value of x with 0.

Line 03 = is a calculation (division by zero)

None of the above

Line 03 = is also an assignment operator but it assigns the value 0 to x

4. In the following algorithm, what is one input that would cause the program to OUTPUT 'True'.
```01 input y
02 x = y MOD 5
03 if x == 0 then
04     print “True”
05 end if```

Any real number that is between 0 and 5 e.g. 3.4

Any integer value divisible by 5 e.g. 10

Any integer value that is between 1 and 5, e.g. 4

Any integer value from 1 to 100 e.g. 19

5. The two programming constructs that have been used in this code are ITERATION and STRING MANIPULATION
```	01 input y
02 x = y MOD 5
03 if x == 0 then
04     print “True”
05 end if
```

FALSE

TRUE

6. Analyse the following algorithm and explain what it is doing.
```word = input(“Enter a word”)
count = 0
while count < 3
for x = 1 to word.length
if x.upper = “A” then
count = count + 1
endif
next x
endwhile```

Counts how many words are entered by the user and outputs the result

counts the number of letters in the word entered by the user and outputs that count + 1

Counts how many times the letter 'A' appears in the word entered by the user

counts the number of letters in the word entered by the user and outputs that count (e.g. "Ruth" would output 4)

7. The following algorithm is supposed to print out the times table of the number entered but there is an error. What is it?
```input b
x = 1
while x <=10
print b * x
endwhile```

while x <=10 should be changed to while x <=0, as otherwise the loop will not run

There is no error - this code will work fine

The value of x should start at 10 in order for the stopping condition to work

There is no incrementation (x = x+1) needs to go after print b*x

8. For the following algorithm, if the user enters '3', what will happen?
```input age
for x = 1 to age
print “happy birthday”
next x ```

It will print the message "happy birthday" infinite number of times until it crashes

It will cause an error because x = 1, this needs to be changed to x = age

None of the above

It will print the message "happy birthday" three times

9. The following pseudocode will accept a password string as a parameter passed into the function, returning _____ if the password is a valid length or ______ if it is not valid.
```function checkpassword(password)
return True
else
return False
endfunction```

True / False

False / True

True / True

False / False

10. A car dealer uses the following algorithm to determine the price to charge for cars. What is the output if p = 1000 i=2 and a = 12?
```01 p = input(“purchase price of car”		02 i = input(“number of improvements made”)
03 a = input(“age of car in years”)
04 s = p + (i*100)
05 if a <= 10 then
06     s = s + s
07 endif
08 print  “sale price is “ + s```

10600

1200

None of the above

16000