Pascal case names for subroutines

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

Pascal case names for subroutines

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is a correct Cambridge pseudocode name for a subroutine?
A sum_square
B SumSquare
2. Which procedure name follows the Pascal case rule?
A DefaultLine
B Default Line
3. Which function name is written correctly?
A CalculateTotal
B calculatetotal
4. Which name is NOT allowed because of how it starts?
A DoubleIt2 is not allowed
B 2DoubleIt is not allowed
5. Which character is allowed in a Pascal case subroutine name?
A A digit such as 2 (after the first letter)
B An underscore _

Match the Pairs

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

Left columnRight column
1PROCEDURE DefaultLine() AA valid Pascal case procedure name: capital letter at the start of each word, with letters only
2FUNCTION SumSquare(Num : INTEGER) RETURNS INTEGER BPROCEDURE ShowScore2()
3A descriptive Pascal case name tells the reader what the subroutine does CThe name starts with a digit. A subroutine name must start with a capital letter, for example SumSquare.
4A name may contain digits, but it must start with a capital letter and not a digit DA valid Pascal case function name made of two capitalised words joined together
5PROCEDURE default_line() EThe name uses an underscore and starts with a lowercase letter. Pascal case needs DefaultLine with no underscore.
6FUNCTION 2DSum(A : INTEGER) RETURNS INTEGER FFUNCTION CalculateTotal(Price : REAL) RETURNS REAL

Definitions

CalculateTotal

Fill in the Blanks

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

1.
PROCEDURE ___________() OUTPUT "----------" ENDPROCEDURE
2.
FUNCTION _________() RETURNS INTEGER RETURN 3 * 3 + 4 * 4 ENDFUNCTION
3.
FUNCTION ______________() RETURNS INTEGER RETURN 10 + 20 ENDFUNCTION
4.
PROCEDURE _alculateTotal() OUTPUT 10 + 20 ENDPROCEDURE
5.
FUNCTION Sum_quare() RETURNS INTEGER RETURN 3 * 3 + 4 * 4 ENDFUNCTION

Spot the Error

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

Question 1
A PROCEDURE DefaultLine()
B OUTPUT "----------"
C ENDPROCEDURE
D CALL Default_Line()
Question 2
A Price ← 10
B PROCEDURE calculateTotal()
C OUTPUT Price * 3
D ENDPROCEDURE
Question 3
A // Show the score
B PROCEDURE Show Score(S : REAL)
C OUTPUT S
D ENDPROCEDURE
Question 4
A FUNCTION GetTax() RETURNS REAL
B RETURN 0.2
C ENDFUNCTION
D OUTPUT getTax()
Question 5
A PROCEDURE 2PrintLine()
B OUTPUT "=========="
C ENDPROCEDURE
D CALL PrintLine2()

Answer Key

Pascal case names for subroutines
Section A: Quick Questions
Q1
B — SumSquare
Q2
A — DefaultLine
Q3
A — CalculateTotal
Q4
B — 2DoubleIt is not allowed
Q5
A — A digit such as 2 (after the first letter)
Section B: Match the Pairs
Q1
PROCEDURE DefaultLine() → A valid Pascal case procedure name: capital letter at the start of each word, with letters only
Q2
FUNCTION SumSquare(Num : INTEGER) RETURNS INTEGER → A valid Pascal case function name made of two capitalised words joined together
Q3
A descriptive Pascal case name tells the reader what the subroutine does → FUNCTION CalculateTotal(Price : REAL) RETURNS REAL
Q4
A name may contain digits, but it must start with a capital letter and not a digit → PROCEDURE ShowScore2()
Q5
PROCEDURE default_line() → The name uses an underscore and starts with a lowercase letter. Pascal case needs DefaultLine with no underscore.
Q6
FUNCTION 2DSum(A : INTEGER) RETURNS INTEGER → The name starts with a digit. A subroutine name must start with a capital letter, for example SumSquare.
Section C: Definitions
Q1
CalculateTotal — A Pascal case subroutine name: it starts with a capital letter, each word is capitalised, and it uses only letters and digits, with no spaces, no underscores and no starting digit.
Section D: Fill in the Blanks
Q1
PROCEDURE DefaultLine() OUTPUT "----------" ENDPROCEDURE
Q2
FUNCTION SumSquare() RETURNS INTEGER RETURN 3 * 3 + 4 * 4 ENDFUNCTION
Q3
FUNCTION CalculateTotal() RETURNS INTEGER RETURN 10 + 20 ENDFUNCTION
Q4
PROCEDURE CalculateTotal() OUTPUT 10 + 20 ENDPROCEDURE
Q5
FUNCTION SumSquare() RETURNS INTEGER RETURN 3 * 3 + 4 * 4 ENDFUNCTION
Section E: Spot the Error
Q1
D — The call uses an underscore, but Pascal case names contain only letters and digits. The name should be written as DefaultLine, so the call is CALL DefaultLine().
Q2
B — A Pascal case name must start with a capital letter. calculateTotal starts with a lowercase c. It should be CalculateTotal.
Q3
B — A subroutine name cannot contain spaces. The words must be joined, with each word starting with a capital letter: ShowScore.
Q4
D — The call starts with a lowercase g, which is camelCase and not Pascal case. The function is named GetTax, so it must be called as GetTax().
Q5
A — A subroutine name cannot start with a digit. Digits are allowed inside the name, but the first character must be a capital letter, as in PrintLine2.