Type check

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

Type check

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A user types 'abc' into an age field that must be a whole number. Which check should reject it?
A Type check
B Presence check
2. Which statement describes a type check correctly?
A It checks the input is the expected data type, such as INTEGER
B It checks the input is typed in twice and matches
3. A program expects the age 15. Which input would a type check for INTEGER reject?
A 15
B fifteen
4. Which data type should an age field be checked against?
A STRING
B INTEGER
5. A type check on an age field accepts 200. Is this statement true or false?
A True, a type check only tests the data type, and 200 is a whole number
B False, a type check always rejects numbers that are too big

Match the Pairs

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

Left columnRight column
1Age must be an INTEGER AA type check: the input must be a number that can have a decimal part, so text is rejected
2Price must be a REAL number BA type check: the input must be a whole number, so letters like "ten" are rejected
3A type check rejects letters when a whole number is expected, such as an age CThe input must be of type INTEGER
4In the exam, a type check is described in words, linked to a data type DA STRING can hold letters, so it will not enforce whole numbers. The type check should require an INTEGER.
5Type check: Age must be between 0 and 120 EThis describes a range check, not a type check. A type check tests the data type, for example that Age is an INTEGER.
6Age is stored as STRING so a type check will make sure it is a whole number FIF Age is not an INTEGER THEN OUTPUT "Enter a whole number"

Definitions

type check

Fill in the Blanks

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

1.
// Type check: expects a whole number DECLARE Age : _______
2.
DECLARE Age : INTEGER DECLARE Name : ______
3.
_______ Age : INTEGER INPUT Age
4.
DECLARE Age : INTEGER OUTPUT "Enter your age" _____ Age
5.
// Type check: Age must be INTEGER DECLARE ___ : INTEGER

Spot the Error

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

Question 1
A DECLARE Age : INTEGER
B OUTPUT "Enter your age"
C OUTPUT Age
D OUTPUT "Age accepted"
Question 2
A DECLARE Age : STRING
B INPUT Age
C OUTPUT Age + 1
Question 3
A // Type check: Age must be STRING
B DECLARE Age : INTEGER
C INPUT Age
Question 4
A DECLARE Age : INTEGER
B DECLARE Name : STRING
C INPUT Name
D INPUT Age : INTEGER
Question 5
A DECLARE Age : INTEGER
B INPUT "Age"
C OUTPUT "Valid age: ", Age

Answer Key

Type check
Section A: Quick Questions
Q1
A — Type check
Q2
A — It checks the input is the expected data type, such as INTEGER
Q3
B — fifteen
Q4
B — INTEGER
Q5
A — True, a type check only tests the data type, and 200 is a whole number
Section B: Match the Pairs
Q1
Age must be an INTEGER → A type check: the input must be a whole number, so letters like "ten" are rejected
Q2
Price must be a REAL number → A type check: the input must be a number that can have a decimal part, so text is rejected
Q3
A type check rejects letters when a whole number is expected, such as an age → IF Age is not an INTEGER THEN OUTPUT "Enter a whole number"
Q4
In the exam, a type check is described in words, linked to a data type → The input must be of type INTEGER
Q5
Type check: Age must be between 0 and 120 → This describes a range check, not a type check. A type check tests the data type, for example that Age is an INTEGER.
Q6
Age is stored as STRING so a type check will make sure it is a whole number → A STRING can hold letters, so it will not enforce whole numbers. The type check should require an INTEGER.
Section C: Definitions
Q1
type check — A validation check that tests an input is the expected data type, such as a whole number (INTEGER) for an age, and rejects letters or other wrong types.
Section D: Fill in the Blanks
Q1
// Type check: expects a whole number DECLARE Age : INTEGER
Q2
DECLARE Age : INTEGER DECLARE Name : STRING
Q3
DECLARE Age : INTEGER INPUT Age
Q4
DECLARE Age : INTEGER OUTPUT "Enter your age" INPUT Age
Q5
// Type check: Age must be INTEGER DECLARE Age : INTEGER
Section E: Spot the Error
Q1
C — The program must read the age with INPUT Age so the value can be checked as an INTEGER. OUTPUT only displays a value and does not read one.
Q2
A — An age is a whole number, so the type check expects INTEGER. Declaring Age as STRING would accept letters and break the arithmetic. It should be DECLARE Age : INTEGER.
Q3
A — A type check on an age tests that the input is a whole number (INTEGER). It does not expect STRING, so the comment should say INTEGER.
Q4
D — The data type is set in the DECLARE statement, not in INPUT. The line should be just INPUT Age. The type check then compares the input with the declared INTEGER type.
Q5
B — Quotes make Age a piece of text, so the input would not be stored in the INTEGER variable. It should be INPUT Age with no quotes.