AQA A-Level Computer Science 7517
Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation
Fundamentals of Data Representation
Fundamentals of Computer Systems
Fundamentals of Computer Organisation and Architecture
Fundamentals of Communication and Networking
Consequences of Uses of Computing
Systematic Approach to Problem Solving
Fundamentals of Databases
Big Data
Fundamentals of Programming
Relational Operations, Constants and Variables
- 4 things to know
- Paper 1
Overview
Recall questions on the six relational operations and their symbols, the result they yield, and the distinction between assignment and comparison.
What you need to know
Answer each one before you reveal it.
A is True and B is False. Evaluate NOT A, A AND B, A OR B and A XOR B.
Explain the difference between a variable and a constant.
Give an example of a constant and of a variable, and say why naming a limit helps.
Questions from this subtopic
Each one with the model answer underneath.
- 1
Name the six relational operations and give a symbol commonly used for each.
Model answer
Equal to (= or ==), not equal to (!= or <>), less than (<), greater than (>), less than or equal to (<=), and greater than or equal to (>=).
- 2
What is the result of a relational operation, and what is it used for?
Model answer
A Boolean value, True or False. That Boolean result is what a selection statement or the condition of a loop tests, and it can also be stored in a Boolean variable or combined with other conditions using Boolean operators.
- 3
Why do many languages use = for one purpose and == for another?
Model answer
Because assigning and comparing are different operations. In C#, Java and Python a single = assigns a value to a variable while a double == tests two values for equality; VB.Net uses = for both and works out which is meant from the context. Writing = where == is meant is a common error that either fails to compile or silently changes a variable.
- 4
How do you test that a mark is at least 40 but no more than 69?
Model answer
mark >= 40 AND mark <= 69. 'At least' maps to greater than or equal to, and 'no more than' maps to less than or equal to; using the strict < and > operators here would wrongly exclude the boundary values 40 and 69.
- 5
How are two strings compared by the relational operators, and is 'Zoo' less than 'apple'?
Model answer
They are compared character by character from the left using the character codes, and the first position where they differ decides the outcome; if one string runs out first it is the smaller. In ASCII the capitals occupy codes 65 to 90 and the lower-case letters 97 to 122, so 'Z' (90) is less than 'a' (97) and therefore 'Zoo' is less than 'apple'. This is why a case-sensitive sort puts all capitalised words before lower-case ones.
- 6
Why is testing two real numbers for exact equality unreliable, and what should you do instead?
Model answer
Because reals are stored as an approximation, so a value that should be 0.3 may be held as very slightly more or less and a test for exact equality then fails. Instead test that the difference is smaller than a small tolerance, for example abs(a - b) < 0.000001. Integers are stored exactly, so testing them for equality is perfectly safe.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Fundamentals of Programming, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.