Chapter 1&2(With Answer)
Chapter 1&2(With Answer)
Page 1 of 19
(i) Complete the table to show the output for each cargo item. (3)
Ans: Determining which size shipping container is needed for the indicated cargo.
Page 2 of 19
(b) Each ship is registered to a state.
Page 3 of 19
Page 4 of 19
Cargo ships have maximum weight loads.
The algorithm should identify the size of cargo ship required for any load. There is an error
on line 9
Ans:
Complete the trace table for an input of 50500 to show what happens due to the error on line
9 in the pseudocode in Figure 4.
You may not need to fill in all the rows in the table.(2)
Page 5 of 19
(ii) Construct a single line of pseudocode to correct line 9.(2)
1. Use of AND operator (in the test of relevant conditions) (1)
Use of suitable function to find the length of the array using a correct comparison
to index(1)
Example:
Page 6 of 19
2) A software engineer is working with some algorithms.
(a) An algorithm needs to be developed.
The algorithm must:
• check for a change of hour every minute
• use the library subprogram getHour() to get the hour part of the current time
in the 24-hour clock (0 to 23)
• output “Good morning” when the hour is between 3 and 12, inclusive
• output “Good afternoon” when the hour is between 13 and 19, inclusive
• output “Good night” at all other times.
Complete the flowchart to represent this algorithm, in the space provided on the
next page.
The call to the library subprogram getHour() has already been included.
Use this subprogram symbol to show waiting for 1 minute.
Page 7 of 19
Page 8 of 19
(b) Another algorithm determines when to change the flavoured syrups for a drinks
dispensing machine.
Page 9 of 19
1) Isaac is a program developer.
(i) (a) Figure 3 shows an algorithm Isaac has written.
(i) Complete the trace table. You may not need to use all of the rows.(5)
Page 10 of 19
Page 11 of 19
(ii) Give the purpose of the algorithm.
Ans:
• To reverse the contents of the array (1)
• To reverse the order of the numbers (1)
The algorithm should display the average of the numbers that have been input.
(i) Explain why the Actual result is not the same as the Expected result.(2)
Award two marks for a linked explanation such as:
• Isaac has included the -1 as a number in the addition (1) but the number has not
been added to the count (1)
• Isaac has misunderstood the WHILE loop (1) as it should not execute after the -1
has been input (1)
• Isaac is expecting the wrong result (1) it should be 3 (1)
• The count is 1 too many as the -1 is counted as a number (1) and the total is
incorrect as 1 is subtracted from the total (1)
(ii) Give the number of the line that contains the error.
Line 3 (1)
Line 10 (1)
(iii) Amend a single line of pseudocode to correct the error.(1)
SET count TO -1 (1)
SET average TO (total + 1) / (count – 1)
Page 12 of 19
2) Algorithms can be used to perform calculations and to process data.
(a) State what is meant by the term algorithm.
• a step-by-step description of a process that completes a task (1)
• a set of instructions that describes how to get something done (1)
1) Complete this trace table for the algorithm. You may not need to use all the
rows.(5)
Page 13 of 19
(ii) The benefits of using a trace table include that they allow variable states,
outputs and decisions to be recorded.
Give one other benefit of using a trace table to test an algorithm. (1)
(c) An algorithm is needed to count and display the number of vowels in a word.
The vowels are a, e, i, o, and u.
The completed algorithm must:
• count the number of vowels
• create a message as a single string (e.g. there are number vowels)
• print the message to the display.
Here is a partially completed algorithm written in pseudocode.
Complete the algorithm in the spaces provided. (5)
Page 14 of 19
Page 15 of 19
2) Reba likes writing programs.
(a) She is writing a guessing game.
She needs a flowchart to show the logic of the game.
(i) These are the components needed to draw the flowchart.
Draw the flowchart for the algorithm in the box on the next page.
Page 16 of 19
(ii) Identify an alternative method for writing the algorithm.
(b) Reba wants to develop a program that will convert a temperature in Fahrenheit
to Celsius. Here are four steps in the algorithm. The steps are not in the correct order.
Page 17 of 19
Award one mark for:
•D
(ii) Give the letter of the step that inputs a value.(1)
•B
c) Figure 2 shows the pseudocode for an early version of an algorithm that Reba has written
for another game.
The algorithm:
• asks the user to input a colour or input –1 to end the game
• awards 1 point for red
• awards 8 points for orange
• generates the score for the game
• displays the results of the game.
Page 18 of 19
(ii) Give the line number of the pseudocode that contains the error.(1)
23
Page 19 of 19