0% found this document useful (0 votes)
36 views

Chapter 1&2(With Answer)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Chapter 1&2(With Answer)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Chapter 1 & 2

1) Ships carry cargo around the world in containers.

(a) Containers come in two sizes.

Figure 2 shows an algorithm written using flowchart symbols.

Page 1 of 19
(i) Complete the table to show the output for each cargo item. (3)

(ii) State the purpose of the algorithm in Figure 2. (1)

Ans: Determining which size shipping container is needed for the indicated cargo.

Page 2 of 19
(b) Each ship is registered to a state.

Figure 3 shows a partially completed algorithm written in pseudocode.

The completed algorithm must:


• print each state to the display on a new line
• count the number of states
• create a message as a single string (e.g. there are number states)
• print the message to the display.
Complete the algorithm in the space provided in Figure 3. (4)

Page 3 of 19
Page 4 of 19
Cargo ships have maximum weight loads.

Figure 4 shows an algorithm written using pseudocode.

The algorithm should identify the size of cargo ship required for any load. There is an error
on line 9

Ans:

Showing that index goes up to 4 and does not exceed 4 (1)

Showing correspondence between values of index and loadWeight[index] (1)

(i) Trace tables are used to identify errors in algorithms.

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:

WHILE ((NOT found) AND (index < LENGTH (loadWeight))) DO

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.

Figure 4 shows this algorithm written in pseudocode.

(i) Give the output produced by the algorithm.

The algorithm works with a fixed number of flavours.


(iii) Give the number of the line in the algorithm that would need to be amended to
allow for any number of flavours.

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)

(iii) Explain why the variable Temp is needed(2)


Ans:
• You need to swap the contents of array values (1) and without Temp one of the
values would be lost (1)

(b) Figure 4 shows an algorithm Isaac has written using pseudocode.

The algorithm should display the average of the numbers that have been input.

Isaac uses the input 2, 3, 5, 2, −1 to test the algorithm. He discovers an error.

(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)

(b) Figure 3 shows an algorithm.

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)

• helps visualise how the algorithm works (1)

• helps detect (logic) errors (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.

Use each component once.

Do not add any additional components.

Use as many arrows and yes/no labels as you need. (5)

Page 16 of 19
(ii) Identify an alternative method for writing the algorithm.

The only correct answer is C

(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.

(i) Give the letter of the step that initialises a variable.(1)

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.

Reba inputs: red, orange, red, red, orange, –1

The outputs are not as she expects.

(i) Complete the trace table to show the outputs.(4)

Page 18 of 19
(ii) Give the line number of the pseudocode that contains the error.(1)
 23

(iii) Write a replacement line of pseudocode to correct the error.(1)


• Pseudodode that replaces OrangePoints with NumOranges on line 23 (1)
SEND ("Number of oranges: "& NumOranges) TO DISPLAY

Page 19 of 19

You might also like