Input, process, output in one short program

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

Input, process, output in one short program

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which order is correct for a simple program?
A DECLARE, INPUT, calculate with ←, OUTPUT
B OUTPUT, calculate with ←, INPUT, DECLARE
2. A program finds the area of a rectangle. Which line goes BEFORE Area ← Length * Width?
A INPUT Length and INPUT Width
B OUTPUT Area
3. Which line correctly calculates the total cost?
A TotalCost ← Price * Quantity
B Price * Quantity ← TotalCost
4. The program is partly written. Which line completes it? INPUT Radius ??? OUTPUT Area
A INPUT Area
B Area ← 3.14 * Radius ^ 2
5. Which order gives the user a clear prompt?
A INPUT Length then OUTPUT "Enter the length"
B OUTPUT "Enter the length" then INPUT Length

Match the Pairs

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

Left columnRight column
1INPUT Width AOUTPUT is placed before Area is calculated, so it would display a variable that has no value yet.
2Area ← Width * Height BProcesses the data: it calculates a result from the input values and stores it in the variable Area.
3Show the result to the user as the last step of the program, after it has been calculated CThe calculation comes before the INPUT lines, so Price and Quantity have no values yet when Total is worked out.
4Declare a variable with its data type before the program uses it to store a value DReads a value typed by the user and stores it in the variable Width, so it must come before any calculation that uses Width.
5Total ← Price * Quantity INPUT Price INPUT Quantity OUTPUT Total EOUTPUT "Total cost: ", TotalCost
6INPUT Length INPUT Width OUTPUT Area Area ← Length * Width FDECLARE Price : REAL

Definitions

INPUT, ←, OUTPUT

Fill in the Blanks

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

1.
_______ Price : REAL INPUT Price OUTPUT Price * 3
2.
DECLARE Width : INTEGER _____ Width OUTPUT Width * Width
3.
INPUT Side Area ← Side _ Side OUTPUT Area
4.
INPUT Quantity Total _ Quantity * 2.5 OUTPUT Total
5.
INPUT Price Total ← Price * 3 ______ Total

Spot the Error

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

Question 1
A DECLARE Side : INTEGER
B DECLARE Area INTEGER
C INPUT Side
D Area ← Side * Side
E OUTPUT Area
Question 2
A DECLARE Price : REAL
B DECLARE Total : REAL
C INPUT Total
D Total ← Price * 3
E OUTPUT Total
Question 3
A DECLARE Age : NUMBER
B DECLARE NextAge : INTEGER
C INPUT Age
D NextAge ← Age + 1
E OUTPUT NextAge
Question 4
A DECLARE Radius : REAL
B OUTPUT Enter the radius
C INPUT Radius
D OUTPUT Radius * Radius * 3.14
Question 5
A DECLARE Length : INTEGER
B DECLARE Width : INTEGER
C INPUT Length
D INPUT Height
E OUTPUT Length * Width

Answer Key

Input, process, output in one short program
Section A: Quick Questions
Q1
A — DECLARE, INPUT, calculate with ←, OUTPUT
Q2
A — INPUT Length and INPUT Width
Q3
A — TotalCost ← Price * Quantity
Q4
B — Area ← 3.14 * Radius ^ 2
Q5
B — OUTPUT "Enter the length" then INPUT Length
Section B: Match the Pairs
Q1
INPUT Width → Reads a value typed by the user and stores it in the variable Width, so it must come before any calculation that uses Width.
Q2
Area ← Width * Height → Processes the data: it calculates a result from the input values and stores it in the variable Area.
Q3
Show the result to the user as the last step of the program, after it has been calculated → OUTPUT "Total cost: ", TotalCost
Q4
Declare a variable with its data type before the program uses it to store a value → DECLARE Price : REAL
Q5
Total ← Price * Quantity INPUT Price INPUT Quantity OUTPUT Total → The calculation comes before the INPUT lines, so Price and Quantity have no values yet when Total is worked out.
Q6
INPUT Length INPUT Width OUTPUT Area Area ← Length * Width → OUTPUT is placed before Area is calculated, so it would display a variable that has no value yet.
Section C: Definitions
Q1
INPUT, ←, OUTPUT — A simple program's order: DECLARE variables, INPUT values, calculate with an assignment (←), then OUTPUT the result. Each step must come before the one that uses it.
Section D: Fill in the Blanks
Q1
DECLARE Price : REAL INPUT Price OUTPUT Price * 3
Q2
DECLARE Width : INTEGER INPUT Width OUTPUT Width * Width
Q3
INPUT Side Area ← Side * Side OUTPUT Area
Q4
INPUT Quantity Total ← Quantity * 2.5 OUTPUT Total
Q5
INPUT Price Total ← Price * 3 OUTPUT Total
Section E: Spot the Error
Q1
B — A DECLARE statement needs a colon between the identifier and the data type. It should be DECLARE Area : INTEGER.
Q2
C — The user must enter the price, not the total. Total is calculated from Price on the next line. Price never gets a value this way. It should be INPUT Price.
Q3
A — NUMBER is not a Cambridge pseudocode data type. A whole number age should be declared as INTEGER: DECLARE Age : INTEGER.
Q4
B — The text of a prompt is a string, so it must be in double quotes. It should be OUTPUT "Enter the radius".
Q5
D — Height was never declared, and Width would never get a value for the calculation. The line should be INPUT Width.