Computer-science_A-level_Cie
-
computers-and-components6 主题
-
logic-gates-and-logic-circuits2 主题
-
central-processing-unit-cpu-architecture6 主题
-
assembly-language-4 主题
-
bit-manipulation1 主题
-
operating-systems3 主题
-
language-translators2 主题
-
data-security3 主题
-
data-integrity1 主题
-
ethics-and-ownership3 主题
-
database-concepts3 主题
-
database-management-systems-dbms-1 主题
-
data-definition-language-ddl-and-data-manipulation-language-dml1 主题
-
computational-thinking-skills1 主题
-
algorithms14 主题
-
data-types-and-records2 主题
-
arrays2 主题
-
files1 主题
-
introduction-to-abstract-data-types-adt1 主题
-
programming-basics1 主题
-
constructs2 主题
-
structured-programming1 主题
-
program-development-life-cycle2 主题
-
program-design-2 主题
-
program-testing-and-maintenance3 主题
-
user-defined-data-types1 主题
-
file-organisation-and-access-3 主题
-
floating-point-numbers-representation-and-manipulation3 主题
-
protocols2 主题
-
circuit-switching-packet-switching1 主题
-
processors-parallel-processing-and-virtual-machines5 主题
-
boolean-algebra-and-logic-circuits4 主题
-
purposes-of-an-operating-system-os3 主题
-
translation-software3 主题
-
encryption-encryption-protocols-and-digital-certificates3 主题
-
artificial-intelligence-ai4 主题
-
recursion1 主题
-
programming-paradigms4 主题
-
object-oriented-programming7 主题
-
file-processing-and-exception-handling2 主题
-
data-representation5 主题
-
multimedia3 主题
-
compression2 主题
-
networks-and-the-internet11 主题
pseudocode-basics
Variables & Constants
What is a variable?
-
A variable is an identifier that can change in the lifetime of a program
-
Identifiers should be:
-
In mixed case (Pascal case)
-
Only contain letters (A-Z, a-z)
-
Only contain digits (0-9)
-
Start with a capital letter and not a digit
-
-
A variable can be associated a datatype when it is declared
-
When a variable is declared, memory is allocated based on the data type indicated
|
Pseudocode |
|---|
|
|
-
To declare a variable, use the
DECLAREkeyword followed by the name and data type:
DECLARE Age : INTEGER
DECLARE Name : STRING
DECLARE IsLoggedIn : BOOLEAN
DECLARE Temperature : REAL
DECLARE DOB : DATE
-
You can then assign a value using the assignment operator
←:
Age ← 18
Name ← "Alice"
IsLoggedIn ← TRUE
What is a constant?
-
A constant is an identifier set once in the lifetime of a program
-
Constants are generally named in all uppercase characters
-
Constants aid the readability and maintainability
|
Pseudocode |
|---|
|
|
-
To declare a constant, use the
CONSTANTkeyword:
CONSTANT Pi ← 3.14159
CONSTANT MaxScore ← 100
CONSTANT SchoolName ← "Meridian Academy"
-
Constants are not reassigned during execution – they are fixed values used throughout the algorithm
Example
-
You are writing a program to calculate the area of a circle using the formula:
Area ← π × radius²
-
πis a constant (it never changes) -
radiusandareaare variables (they change depending on the input)
CONSTANT Pi ← 3.14159 DECLARE Radius : REAL
DECLARE Area : REAL OUTPUT "Enter the radius of the circle:"
INPUT Radius Area ← Pi * Radius * Radius OUTPUT "The area of the circle is: ", Area
Variables and constants in different languages
|
Feature |
Python |
VB.NET |
Java |
|---|---|---|---|
|
Declare variable |
Just assign it (no keyword needed) |
|
|
|
Assign variable |
|
|
|
|
Declare constant |
Convention: use UPPERCASE ( |
|
|
|
Reassign constant? |
Yes (not truly constant unless enforced) |
Cannot change once set |
Cannot change once set |
|
Use in calc. |
|
|
|
Arithmetic & logical operators
Arithmetic operators
-
Arithmetic operators are used to perform basic maths operations in a program
-
These include adding, subtracting, multiplying and dividing values
Common arithmetic operators
|
Operator |
Purpose |
Example |
Result |
|---|---|---|---|
|
|
Addition or string concatenation |
|
|
|
|
|
||
|
|
Subtraction |
|
|
|
|
Multiplication |
|
|
|
|
Division |
|
|
|
|
Exponentiation (power of) |
|
|
|
|
Modulus (remainder after division) |
|
|
Operator precedence (BODMAS / BIDMAS)
-
Arithmetic operators follow operator precedence
-
Multiplication and division happen before addition and subtraction unless brackets are used
result ← 2 + 3 * 4 // gives 14
result ← (2 + 3) * 4 // gives 20
Logical operators
-
Logical operators are used to compare values
-
They return either TRUE or FALSE and are commonly used in conditions and loops
Common logical operators
|
Operator |
Purpose |
Example |
Result |
|---|---|---|---|
|
|
Equal to |
|
|
|
|
Not equal to |
|
|
|
|
Greater than |
|
|
|
|
Less than |
|
|
|
|
Greater than or equal to |
|
|
|
|
Less than or equal to |
|
|
Example code
x ← 5
y ← 10 OUTPUT x == y // FALSE
OUTPUT x <> y // TRUE
OUTPUT x < y // TRUE
OUTPUT x > y // FALSE
OUTPUT x <= y // TRUE
OUTPUT x >= y // FALSE
Responses