Reading a problem to plan an algorithm

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Reading a problem to plan an algorithm

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A problem says: 'Read a student's test mark and output PASS if it is 50 or more.' What is the INPUT?
A The word PASS
B The test mark
2. Which is the better first step before writing an algorithm?
A Read the problem and list the inputs, processes and outputs
B Start typing pseudocode straight away and fix it later
3. A problem says: 'Calculate the total cost of 5 items and output the total.' Which part is the PROCESS?
A Showing the total on the screen
B Adding the 5 prices to find the total
4. When underlining a problem, what should you underline as outputs?
A What the algorithm must display or give back, such as the average
B What the user must type in, such as each mark
5. A problem says: 'Input 30 marks and output the highest.' Which words show a REPEAT is needed?
A Input 30 marks
B output the highest

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1INPUT Mark ATotal will hold a calculated sum of marks, so it needs a numeric data type such as INTEGER, not STRING.
2OUTPUT Average BAn output found by underlining what the problem says must be displayed to the user
3The problem says 'enter 30 marks', so it needs a repeat. Plan a loop that runs 30 times. CAn input found by underlining what the user enters, such as a mark in the problem
4The problem says 'if the mark is 50 or more, pass', so it needs a decision. Plan a selection. DFOR Count ← 1 TO 30
5DECLARE Total : STRING EIF Mark >= 50 THEN
6OUTPUT Average Average ← Total / Count INPUT Total FThe order is wrong: the plan is input, then process, then output. The output comes first and the input comes last.

Definitions

Input, Process, Output

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_____ Mark1 INPUT Mark2 OUTPUT (Mark1 + Mark2) / 2
2.
// Price of one item in dollars and cents DECLARE Price : ____
3.
Total ← Price * Quantity OUTPUT _____
4.
FOR Count ← 1 __ 10 INPUT Mark NEXT Count
5.
IF Mark __ 50 THEN OUTPUT "Pass" ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Average : REAL
B DECLARE Average : INTEGER
C INPUT Mark2
D Average ← (Mark1 + Mark2) / 2
E OUTPUT Average
Question 2
A Total ← 0
B FOR Item ← 1 TO 3
C INPUT Price
D Total ← Total + Item
E NEXT Item
F OUTPUT Total
Question 3
A DECLARE Name : STRING
B DECLARE Price : REAL
C DECLARE Quantity : STRING
D INPUT Quantity
Question 4
A // Read marks of 10 students
B FOR Student ← 1 TO 9
C INPUT Mark
D OUTPUT Mark
E NEXT Student
Question 5
A INPUT Number
B WHILE Number <> 0 DO
C OUTPUT Number * 2
D Number ← Number * 2
E ENDWHILE

Answer Key

Reading a problem to plan an algorithm
Section A: Quick Questions
Q1
B — The test mark
Q2
A — Read the problem and list the inputs, processes and outputs
Q3
B — Adding the 5 prices to find the total
Q4
A — What the algorithm must display or give back, such as the average
Q5
A — Input 30 marks
Section B: Match the Pairs
Q1
INPUT Mark → An input found by underlining what the user enters, such as a mark in the problem
Q2
OUTPUT Average → An output found by underlining what the problem says must be displayed to the user
Q3
The problem says 'enter 30 marks', so it needs a repeat. Plan a loop that runs 30 times. → FOR Count ← 1 TO 30
Q4
The problem says 'if the mark is 50 or more, pass', so it needs a decision. Plan a selection. → IF Mark >= 50 THEN
Q5
DECLARE Total : STRING → Total will hold a calculated sum of marks, so it needs a numeric data type such as INTEGER, not STRING.
Q6
OUTPUT Average Average ← Total / Count INPUT Total → The order is wrong: the plan is input, then process, then output. The output comes first and the input comes last.
Section C: Definitions
Q1
Input, Process, Output — Plan before coding: read the problem, list what is input, what must be calculated or decided, and what is output. Then pick variables and spot repeats and decisions.
Section D: Fill in the Blanks
Q1
INPUT Mark1 INPUT Mark2 OUTPUT (Mark1 + Mark2) / 2
Q2
// Price of one item in dollars and cents DECLARE Price : REAL
Q3
Total ← Price * Quantity OUTPUT Total
Q4
FOR Count ← 1 TO 10 INPUT Mark NEXT Count
Q5
IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Section E: Spot the Error
Q1
B — An average can have decimal places, so the variable that stores the result must be REAL, not INTEGER. It should be DECLARE Average : REAL.
Q2
D — The process is to add up the prices that were input. Item is only the loop counter. The line should be Total ← Total + Price.
Q3
C — A quantity is a whole number that will be used in calculations, so it should be INTEGER, not STRING. It should be DECLARE Quantity : INTEGER.
Q4
B — The repeat is known to be 10 students, so the loop must run 10 times. TO 9 gives only 9 repeats. It should be FOR Student ← 1 TO 10.
Q5
D — The number of repeats is unknown and ends when 0 is entered, so a new value must be input inside the loop. Changing Number by calculation never reaches 0, so the loop never ends. It should be INPUT Number.