Pseudocode Foundations & Conventions: Data Types Used In AS Level Pseudocode (Copy)
Data Types Used In AS Level Pseudocode
Purpose Of Data Types In Pseudocode
- Data types define:
- What kind of data a variable can store
- How that data is processed
- Examiner checks:
- Correct data type choice
- Correct usage in operations
- Wrong data type selection leads to:
- Logic errors
- Loss of method marks
Core AS Level Data Types (Must Know)
| Data Type | Description | Example Values |
|---|---|---|
| INTEGER | Whole numbers | 0, 5, -12 |
| REAL | Decimal numbers | 3.5, 12.75 |
| STRING | Text (multiple characters) | “Ali”, “Grade A” |
| CHAR | Single character | ‘A’, ‘Y’ |
| BOOLEAN | True/False values | TRUE, FALSE |
INTEGER Data Type
| Used For | Examples |
|---|---|
| Counters | Count, i |
| Whole values | Age, Quantity |
| Indexing arrays | Marks[i] |
INTEGER Declaration And Use
DECLARE Age : INTEGER
DECLARE Count : INTEGER
Age ← 18
Count ← Count + 1
- INTEGER cannot store decimal values
- Used heavily in loops and array indexing
REAL Data Type
| Used For | Examples |
|---|---|
| Averages | AverageMark |
| Measurements | Height, Weight |
| Division results | Total / Count |
REAL Declaration And Use
DECLARE Average : REAL
Average ← Total / Count
- Use REAL whenever division may produce decimals
- Using INTEGER for averages causes truncation
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
STRING Data Type
| Feature | Rule |
|---|---|
| Stores | Text |
| Enclosed in | Double quotes |
| Can store | Words, sentences |
STRING Declaration And Use
DECLARE Name : STRING
Name ← "Ali"
STRING In Output
OUTPUT "Student Name = ", Name
- STRING values must be enclosed in quotation marks
- Used for names, messages, labels
CHAR Data Type
| Feature | Rule |
|---|---|
| Stores | Single character |
| Enclosed in | Single quotes |
| Length | Exactly one character |
CHAR Declaration And Use
DECLARE Grade : CHAR
Grade ← 'A'
| CHAR vs STRING | Difference |
|---|---|
| CHAR | One character |
| STRING | Multiple characters |
- Do not store full words in CHAR
- Commonly used for grades and codes
BOOLEAN Data Type
| Possible Values | Meaning |
|---|---|
| TRUE | Condition met |
| FALSE | Condition not met |
BOOLEAN Declaration And Use
DECLARE Found : BOOLEAN
Found ← FALSE
BOOLEAN In Conditions
IF Found = TRUE THEN
OUTPUT "Value found"
ENDIF
- BOOLEAN variables are called flags
- Must always be initialised
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
ARRAY Data Type (Structured Data)
| Feature | Description |
|---|---|
| Purpose | Store multiple values of same type |
| Index | INTEGER |
| Type consistency | All elements same data type |
ARRAY Declaration
DECLARE Marks : ARRAY[1:10] OF INTEGER
ARRAY Usage
FOR i ← 1 TO 10
OUTPUT Marks[i]
ENDFOR
- Index must match declared bounds
- ARRAY elements inherit the declared data type
RECORD Data Type (Composite Data)
| Feature | Description |
|---|---|
| Purpose | Store related data of different types |
| Structure | Named fields |
| Access | Dot notation |
RECORD Declaration
RECORD StudentType
Name : STRING
Age : INTEGER
Grade : CHAR
ENDRECORD
RECORD Variable And Use
DECLARE Student : StudentType
Student.Name ← "Ali"
Student.Age ← 18
Student.Grade ← 'A'
- RECORD fields can be different data types
- Improves data organisation
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
FILE Data Type (AS Level Scope)
| Feature | Description |
|---|---|
| Purpose | Permanent data storage |
| Common use | Text files |
| Access | Line-by-line |
FILE Usage Example
OPENFILE DataFile FOR READ
WHILE NOT EOF(DataFile) DO
READFILE DataFile, Line
OUTPUT Line
ENDWHILE
CLOSEFILE DataFile
- FILE is treated as a data structure
- Data read from file usually stored in STRING variables
Choosing The Correct Data Type (Examiner Focus)
| Scenario | Correct Data Type |
|---|---|
| Counting students | INTEGER |
| Calculating average | REAL |
| Storing name | STRING |
| Storing grade | CHAR |
| Tracking found/not found | BOOLEAN |
Common Data Type Mistakes And Fixes
| Mistake | Why Wrong | Correct Fix |
|---|---|---|
| Using INTEGER for average | Loses decimals | Use REAL |
| Using STRING for grade | Overkill | Use CHAR |
| Using INTEGER as flag | Unclear logic | Use BOOLEAN |
| Mixing array types | Invalid structure | Single type only |
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Data Types In Expressions
Average ← Total / Count
| Variable | Data Type |
|---|---|
| Total | INTEGER |
| Count | INTEGER |
| Average | REAL |
- Result of division stored in REAL
- Examiner expects correct type promotion
Data Types With Conditions
IF Grade = 'A' THEN
OUTPUT "Excellent"
ENDIF
| Element | Data Type |
|---|---|
| Grade | CHAR |
| Condition result | BOOLEAN |
Examiner-Safe Data Type Checklist
| Check | Status |
|---|---|
| Correct type declared | ✓ |
| Correct initialisation | ✓ |
| Correct use in expressions | ✓ |
| No type misuse | ✓ |
| Clear logic flow | ✓ |
