pseuocode guide Flashcards
(41 cards)
What are the basic data types in pseudocode and their descriptions?
INTEGER: A whole number.
REAL: A number capable of containing a fractional part.
CHAR: A single character.
STRING: A sequence of zero or more characters.
BOOLEAN: The logical values TRUE and FALSE.
DATE: A valid calendar date.
How are literals of the basic data types written in pseudocode?
Integer: Written in the denary system, e.g., 5
, -3
.
Real: Written with at least one digit on either side of the decimal point, e.g., 4.7
, 0.3
, -4.0
.
Char: A single character delimited by single quotes, e.g., 'x'
, 'C'
.
String: Delimited by double quotes, e.g., "This is a string"
, ""
(empty string).
Boolean: TRUE
, FALSE
.
Date: Typically written as dd/mm/yyyy
and explicitly declared as DATE with an explanation of the format.
What rules apply to naming identifiers in pseudocode?
- Identifiers must start with a letter (A–Z or a–z).
- Can include letters, digits (0–9), and the underscore (_).
- Must not contain accented letters.
- Should not use keywords as identifiers.
- Case-insensitive (e.g., Counter and counter are treated as the same).
- Use descriptive names or conventional single letters (e.g., i, j for indices).
How should variables be declared in pseudocode?
DECLARE <identifier> : <data type>
Example:
DECLARE Counter : INTEGER DECLARE TotalToPay : REAL DECLARE GameOver : BOOLEAN
Why is it good practice to explicitly declare variables in pseudocode?
- Ensures clarity about the type and purpose of the variable.
- Helps avoid using undeclared or improperly initialised variables.
How are Boolean literals written in pseudocode?
As TRUE
and FALSE
How should date literals be represented in pseudocode?
- Format:
dd/mm/yyyy
- Explicitly state the data type as
DATE
- Explain the format to avoid confusion due to regional differences
Why is it good practice to use constants in pseudocode?
- Constants make pseudocode more readable as identifiers are often more meaningful than literals.
- They simplify updates if the constant’s value changes.
How are constants declared in pseudocode?
CONSTANT <identifier> = <value>
Example:
CONSTANT HourlyRate = 6.50 CONSTANT DefaultText = "N/A"
Only literals can be used as the value of a constant in pseudocode. Variables, other constants, or expressions must not be used.
What is the assignment operator in pseudocode?
←
How are assignments made in pseudocode?
<identifier> ← <value>
Examples:
Counter ← 0 Counter ← Counter + 1 TotalToPay ← NumberOfHours * HourlyRate
How are one-dimensional arrays declared in pseudocode?
DECLARE <identifier>:ARRAY[<lower>:<upper>] OF <data type>
Example:
DECLARE StudentNames : ARRAY[1:30] OF STRING
How are two-dimensional arrays declared in pseudocode?
DECLARE <identifier>:ARRAY[<lower1>:<upper1>,<lower2>:<upper2>] OF <data type>
Example:
DECLARE NoughtsAndCrosses : ARRAY[1:3,1:3] OF CHAR
What is the lower bound of an array, and why should it be explicitly stated?
- The lower bound is the index of the first element in an array.
- It defaults to either 0 or 1 depending on the system, so explicitly stating it ensures clarity. A lower bound of 1 is generally used on pseudocode.
What can be used as array index values in pseudocode?
Array index values can be:
- Literal values (e.g., 1, 2)
- Expressions that evaluate to valid integers (e.g., n+1)
How do you assign a value to an individual element in a one-dimensional array?
ArrayName[Index] ← <value>
Example:
StudentNames[1] ← "Giorno"
How do you assign a value to an individual element in a two-dimensional array?
ArrayName[Index1, Index2] ← <value>
Example:
NoughtsAndCrosses[2,3] ← ꞌXꞌ
Can arrays be assigned to each other in pseudocode?
Arrays can be assigned to each other if:
- They are of the same size.
- They have the same data type.
SavedGame ← NoughtsAndCrosses
Why should a group of array elements not be accessed individually in a statement?
- It is not recommended for clarity and efficiency.
DO NOT:
StudentNames[1 TO 30] ← "" // correct but no marks
- Instead, use a loop to iterate over and process the elements individually.
DO:
FOR Index ← 1 TO 30 StudentNames[Index] ← "" NEXT Index
How can you assign a value to a group of array elements?
Use a loop structure:
FOR Index ← <lower> TO <upper> ArrayName[Index] ← <value> NEXT Index
Example:
FOR Index ← 1 TO 30 StudentNames[Index] ← "" NEXT Index
What is a user-defined non-composite data type with a list of possible values called?
An enumerated data type
How do you declare an enumerated data type in pseudocode?
TYPE <identifier> = (value1, value2, value3, ...)
Example:
TYPE Season = (Spring, Summer, Autumn, Winter)
What is a user-defined non-composite data type that references a memory location called?
A pointer
How do you declare a pointer type in pseudocode?
TYPE <identifier> = ^<data type>
Example:
TYPE TIntPointer = ^INTEGER TYPE TCharPointer = ^CHAR