7.1 Worksheet 4-1 2
7.1 Worksheet 4-1 2
7.1 Worksheet 4-1 2
Task 1
An algorithm has been given below.
1 MoreItems TRUE
2 A 0
3
4 REPEAT
5 INPUT ItemPrice
6 A A + ItemPrice
7 INPUT More
8 IF More = "No"
9 THEN
10 MoreItems FALSE
11 ENDIF
12 UNTIL NOT MoreItems
13
14 OUTPUT A
(a) What is the minimum number of times that the loop will be run?
(b)The user enters the text “Yes” in line 7. What will the value of MoreItems be at the ENDIF in
line 11?
(c) The user enters the text “No” in line 7. What will the value of MoreItems be at the ENDIF in
line 11?
1
(f) Give a more suitable name for the variable currently named A.
Task 2
An array named Ages is set up that has five numbers stored in it:
1 2 3 4 5
Ages 17 15 13 14 16
Make use of a FOR loop to calculate the average for all the ages in the array. Output the
average that is calculated.
2
Task 3
An array named Players is set up that has five names stored in it:
1 2 3 4 5
10
11
14
16
3
(b) State the name of this algorithm.
1. What are the last two names after the first pass?
2. What are the first two names after the second pass?
3. What are the third and fourth names after the third pass?
4. What are the seventh and eighth names after the fourth pass?
5. What are the fourth and fifth names after the fifth pass?
4
6. What are the first two names after the sixth pass?
5
Task 5: Algorithms
You have studied three algorithms for sorting.
Look at the following algorithm written in pseudo-code for one type of sorting algorithm.
1. There is a for loop at the end of the algorithm (lines 13-15) which contains the
pseudo-code:
OUTPUT names[i]
What do you think this does?
2. At the start of the program, the array called names is initialised with six names.
What will the value be that is stored in numItems?
6
3. Look at lines 5 to 10 in the code and explain what they are doing.