Chapter 3 – Basic operations in programming languages

AQA A level Computer Science
Teaching and Learning Resources
Chapter 3 – Basic operations in programming languages
TASK QUESTIONS (WITH ANSWERS)
1
Write an example of a calculation using each of the arithmetic operators.
Examples of each needed of the type:
Answer = FirstNumber + SecondNumber
2
What is the difference between a division of a real/float and the division of an integer?
Division of a real may result in an answer that is a real. Reals are used to represent fractions.
Division of two integers may result in an answer with a remainder.
3
Most calculations will get their values from variables. Why are variables used in
programming, rather than just typing the raw values?
Variables are much more efficient as they can be defined once (name/datatype/validation)
and then the value can change as the program is being run, based on user input and/or the
results of other calculations.
4
Use examples to explain the difference between truncation and rounding.
Truncation is where the number is represented up to a certain number of digits. For
example, 5.76747654 becomes 5.76 when truncated after two decimal places with the
remainder being ignored.
Rounding allows you to define how you want the last digit to be handled. For example,
5.7674654 would become 5.77 if rounded up to two decimal places.
5
Why might random numbers be used?
To generate test data, to create numbers to put into a model, to select a random sample
from a dataset or to create random events in games and simulations.
6
What is the difference between an OR statement and an XOR statement? Give an example.
OR means one or the other, for example, A or B.
XOR means one and not the other, so the answer can be A, but not B, or the answer can be
B, but not A.
7
How can you create a substring from a string?
Identify the start position and length or find a matching string.
AQA A level Computer Science
© Hodder & Stoughton Limited 2015
AQA A level Computer Science
Teaching and Learning Resources
8
What formats can strings be converted into?
Integer, Float, Date, Boolean
9
Why are random numbers generated in programming languages not entirely random?
Most start from a ‘seed’ number and use an algorithm. Therefore the number is always
going to be a feature of that seed number and the particular algorithm used. Depending on
the sophistication of the algorithm, some numbers are more likely to be generated than
others.
AQA A level Computer Science
© Hodder & Stoughton Limited 2015