pseuocode guide Flashcards
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
How do you declare a pointer variable?
Does not require the caret (^) symbol.
DECLARE <variable> : <pointer type>
Example:
DECLARE MyPointer : TIntPointer
What is a composite data type in pseudocode?
A collection of data that can consist of different data types, grouped under one identifier.
How do you declare a composite data type in pseudocode?
TYPE <identifier> DECLARE <field1> : <data type> DECLARE <field2> : <data type> ... ENDTYPE
Example:
TYPE Student DECLARE LastName : STRING DECLARE FirstName : STRING DECLARE DateOfBirth : DATE DECLARE YearGroup : INTEGER DECLARE FormGroup : CHAR ENDTYPE
How do you use a composite data type to declare a variable?
DECLARE <variable> : <composite type>
Example:
DECLARE Pupil : Student
How do you declare variables using user-defined data types?
DECLARE <identifier> : <user-defined type>
Examples:
DECLARE Pupil1 : Student DECLARE ThisSeason : Season DECLARE MyPointer : TIntPointer
How do you access individual items in a user-defined composite data type?
Using dot notation.
Example:
Pupil1.LastName ← "Johnson" Pupil1.YearGroup ← 6
Can variables of user-defined data types be assigned to each other?
Yes, if they share the same data type.
Example:
Pupil2 ← Pupil1
How are arrays of user-defined data types declared and used?
Example:
DECLARE Form : ARRAY[1:30] OF Student Form[Index].YearGroup ← Form[Index].YearGroup + 1
How do you input values in pseudocode?
INPUT <identifier>
Example:
INPUT Answer
How do you output values in pseudocode?
OUTPUT <value(s)>
Example:
OUTPUT Score OUTPUT "You have ", Lives, " lives left"
What are the standard arithmetic operators in pseudocode and their functions?
+
Addition-
Subtraction*
Multiplication/
Division (result is REAL)DIV
Integer division (quotient)MOD
Modulus (remainder)
What is the precedence of arithmetic operators?
Multiplication and division have higher precedence than addition and subtraction. The order of operations be made explicit by using parentheses:
Result ← (A + B) * C
What are the relational operators used in pseudocode?
>
Greater than<
Less than>=
Greater than or equal to<=
Less than or equal to=
Equal to<>
Not equal to
What data type is the result of a relational operation?
BOOLEAN
How can the order of operations in complex relational expressions be clarified?
By using parentheses
What are the logic operators in pseudocode?
AND
OR
NOT