Component parts of a problem: storage

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

Component parts of a problem: storage

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A quiz program keeps the player's score in a variable while the game runs. Is this storage?
A Yes, the data is kept so it can be used again later
B No, only files count as storage
2. Which data is still there after the program has stopped?
A A score kept only in a variable
B A high score saved in a file
3. A school needs to keep the records of 500 students and search them later. Which storage fits best?
A A database
B One single variable
4. A player types their name on the keyboard. What is this part of the problem?
A Storage
B Input
5. The program shows 'Game over' on the screen. What is this part of the problem?
A Output
B Storage

Match the Pairs

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

Left columnRight column
1storage AThis describes input, not storage. Typing a name gets data into the program but does not keep it for later.
2highScore ← 0 BThis describes output, not storage. Displaying a score shows data to the user but does not keep it.
3A high score must still be there next time the game is played, so it is saved in a file CA variable holding data that is kept only while the program is running
4Records, such as a student's name and mark, are kept in a database so they can be used again later DWRITEFILE "scores.txt", highScore
5Storage: the user types in their name ESELECT name, mark FROM results
6Storage: the program shows the final score on the screen FThe data a solution must keep, in a variable, file or database, so it can be used again later

Definitions

storage

Fill in the Blanks

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

1.
_______ HighScore : INTEGER HighScore ← 0
2.
OPENFILE "scores.txt" FOR _____
3.
OPENFILE "scores.txt" FOR WRITE _________ "scores.txt", HighScore CLOSEFILE "scores.txt"
4.
OPENFILE "scores.txt" FOR READ ________ "scores.txt", HighScore CLOSEFILE "scores.txt"
5.
INPUT NewScore HighScore ← ________ OUTPUT HighScore

Spot the Error

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

Question 1
A DECLARE HighScore : INTEGER
B HighScore ← 0
C INPUT Score
D IF Score < HighScore THEN
E HighScore ← Score
F ENDIF
Question 2
A OPENFILE "hs.txt" FOR WRITE
B READFILE "hs.txt", HighScore
C CLOSEFILE "hs.txt"
Question 3
A DECLARE Lives : INTEGER
B Lives = 3
C INPUT Guess
D Lives ← Lives - 1
Question 4
A OPENFILE "hs.txt" FOR READ
B READFILE "hs.txt", OldScore
C INPUT OldScore
D CLOSEFILE "hs.txt"
Question 5
A Total ← 0
B INPUT Sale
C Total ← Sale
D OUTPUT Total

Answer Key

Component parts of a problem: storage
Section A: Quick Questions
Q1
A — Yes, the data is kept so it can be used again later
Q2
B — A high score saved in a file
Q3
A — A database
Q4
B — Input
Q5
A — Output
Section B: Match the Pairs
Q1
storage → The data a solution must keep, in a variable, file or database, so it can be used again later
Q2
highScore ← 0 → A variable holding data that is kept only while the program is running
Q3
A high score must still be there next time the game is played, so it is saved in a file → WRITEFILE "scores.txt", highScore
Q4
Records, such as a student's name and mark, are kept in a database so they can be used again later → SELECT name, mark FROM results
Q5
Storage: the user types in their name → This describes input, not storage. Typing a name gets data into the program but does not keep it for later.
Q6
Storage: the program shows the final score on the screen → This describes output, not storage. Displaying a score shows data to the user but does not keep it.
Section C: Definitions
Q1
storage — Data the solution must keep, in a variable, file or database, so it can be used again later. It is not the same as input or output.
Section D: Fill in the Blanks
Q1
DECLARE HighScore : INTEGER HighScore ← 0
Q2
OPENFILE "scores.txt" FOR WRITE
Q3
OPENFILE "scores.txt" FOR WRITE WRITEFILE "scores.txt", HighScore CLOSEFILE "scores.txt"
Q4
OPENFILE "scores.txt" FOR READ READFILE "scores.txt", HighScore CLOSEFILE "scores.txt"
Q5
INPUT NewScore HighScore ← NewScore OUTPUT HighScore
Section E: Spot the Error
Q1
D — The comparison is the wrong way round. A new score should replace the stored high score only when it is greater, so the line should be IF Score > HighScore THEN.
Q2
B — The program is saving the high score so it is kept after the program stops. It must write to the file with WRITEFILE, not read from it with READFILE. The line should be WRITEFILE "hs.txt", HighScore.
Q3
B — In Cambridge pseudocode, = is used to compare values. Storing a value in a variable needs the assignment arrow, so the line should be Lives ← 3.
Q4
C — OldScore was already read from storage in the file. Showing it to the user is output, so the line should be OUTPUT OldScore. Storage is not the same as input or output.
Q5
C — This overwrites the stored total instead of adding to it, so earlier sales are lost. The line should be Total ← Total + Sale.