OCR_Computing_GCSE_Programming Flashcards
A syntax error can occur when writing a program.
State what is meant by a syntax error, giving an example.
State :An error in the rules/grammar of the language
Example
In C++
int x = Fred
x is an integer NOT a string
Missing a semicolon too. Sigh!
Describe tools and facilities available in an integrated development environment (IDE) which can help the programmer to identify and correct syntax errors.
Error messages/translator diagnostics produced when translating/by the compiler or on the fly while writing code. (breakpoints)
Attempts to tell you what the error is and indicate where the error is/line numbers/underlines. (auto completion)
Editor allows you to enter the corrected code.
Huzaifa is writing a program which simulates a dice game played with three ordinary 6-sided dice.
When the player rolls the three dice, the player is given points according to the algorithm expressed in the flow diagram (flow chart) below
State the value of the score if the dice rolled are
3 4 5

0
Huzaifa is writing a program which simulates a dice game played with three ordinary 6-sided dice.
When the player rolls the three dice, the player is given points according to the algorithm expressed in the flow diagram (flow chart) below
State the value of the score if the dice rolled are
4 4 4

12
Huzaifa is writing a program which simulates a dice game played with three ordinary 6-sided dice.
When the player rolls the three dice, the player is given points according to the algorithm expressed in the flow diagram (flow chart) below
State the value of the score if the dice rolled are
5 5 6

4
Huzaifa is writing a program which simulates a dice game played with three ordinary 6-sided dice.
When the player rolls the three dice, the player is given points according to the algorithm expressed in the flow diagram (flow chart) below
State a set of three numbers which can be used to test whether the algorithm produces a negative score when it should, and state the expected output for your test data.

Set of test data: 1 1 3 / 1 1 4 / 1 1 5 / 1 1 6 / 2 2 5 / 2 2 6
Expected output: -1 -2 -3 -4 -1 -2
Explain why a program written in a high level language needs to be translated before it can be executed.
High level languages (HLL) are understood by humans. Computers/the CPU can only understand/execute machine code (1 and 0’s) instructions. The translator converts a program in the HLL to an equivalent program in machine code.
A compiler and an interpreter are two different types of translator. Describe differences between a compiler and an interpreter.
A compiler translates the entire program before execution C++
An interpreter translates one line, executes that line and then translates the next line. Python/Javascript
A compiler creates a list of errors after compilation. C++
An interpreter stops after the first error.Python/Javascript
A compiler produces an independent executable file.C++
Interpreted program needs the interpreter each time it is run.
Python/Javascript
A compiled program is translated once..C++
An interpreted program is translated each time it is run.Python/Javascript
When dice are rolled, the results are stored in an array called DiceResult.
For example, if the first dice shows a 5 then the value of DiceResult(1) becomes 5.
Describe what is meant by an array.
A data structure/collection of several variables under one name. Each individual variable is given an index by which it is referred within the array.
The routine for rolling the dice is written as a sequence below.
BEGIN RollTheDice
DiceResult(1) = Random Number between 1 and 6
DiceResult(2) = Random Number between 1 and 6
DiceResult(3) = Random Number between 1 and 6
END
Rewrite this routine so that it uses iteration.
You must use a diagram.
Will also accept similar with FOR-NEXT loop
BEGIN RollTheDice
i = 1
WHILE i <= 3
DiceRoll(i) = Random No
i = i + 1 **END WHILE** END
A mail-order company buys dresses from America and France to sell in the UK. The company uses the following algorithm to convert sizes before printing them in its catalogue. Half sizes are not possible (e.g. size 12.5).
INPUT Size
INPUT Origin
IF Origin = “America” THEN
Size = Size + 2
ELSE
IF Origin = “France” THEN
Size = Size – 26
END IF
END IF
State the size which will be printed in the catalogue using the algorithm given for dress Origin : France Size : 40
14
A mail-order company buys dresses from America and France to sell in the UK. The company uses the following algorithm to convert sizes before printing them in its catalogue. Half sizes are not possible (e.g. size 12.5).
INPUT Size
INPUT Origin
IF Origin = “America” THEN
Size = Size + 2
ELSE
IF Origin = “France” THEN
Size = Size – 26
END IF
END IF
State the size which will be printed in the catalogue using the algorithm given for dress Origin : America Size : 8
10
A mail-order company buys dresses from America and France to sell in the UK. The company uses the following algorithm to convert sizes before printing them in its catalogue. Half sizes are not possible (e.g. size 12.5).
INPUT Size
INPUT Origin
IF Origin = “America” THEN
Size = Size + 2
ELSE
IF Origin = “France” THEN
Size = Size – 26
END IF
END IF
State the size which will be printed in the catalogue using the algorithm given for dress Origin : UK Size : 12
12
Describe what is meant by a variable.
A name/symbol which represents a value is a program. The value can change while the program is running.
A mail-order company buys dresses from America and France to sell in the UK. The company uses an algorithm to convert sizes before printing them in its catalogue.
State the most appropriate data types for the variables Origin and Size, giving a reason for your choice.
ORIGIN
String. Consists of more than one character.
Size
Integer. Consists of whole numbers.
The program in a vending machine uses an array called Coins to store the value in pence of all the coins that have been entered in the current sale.
A maximum of 10 coins can be entered in each sale.
After each sale, the array is reset so that all values are 0.In the example velow, the value of Coins(1) is 10.
[10] [100] [20] [50] [5] [0] [0] [0] [0] [0]
State the value of Coins(4)
50
The program in a vending machine uses an array called Coins to store the value in pence of all the coins that have been entered in the current sale.
A maximum of 10 coins can be entered in each sale.
After each sale, the array is reset so that all values are 0.In the example below, the value of Coins(1) is 10.
[10] [100] [20] [50] [5] [0] [0] [0] [0] [0]
State the value of Coins(10)
0
An algorithm to reset the contents of the array Coins after each sale is shown below. This algorithm contains a logic error.
i = 1
REPEAT
Coins(i) = 0
i = i + 1
UNTIL i = 10
Explain why the algorithm above contains a logic error.
It will only reset the first 9 elements / will not reset the 10th element. After setting Coins(9) = 0, i will become10 and the loop will stop. It should be UNTIL i > 10 / or other working correction
An algorithm to reset the contents of the array Coins after each sale is shown below. This algorithm contains a logic error.
i = 1
REPEAT
Coins(i) = 0
i = i + 1
UNTIL i = 10
State what is meant by a logic error.
The program is written to do something other than what the programmer intended
Write an algorithm to calculate the total value of the coins entered in the current sale using the contents of the array Coins.
i = 1
total = 0
REPEAT
total = total + Coins(i)
i = i + 1
UNTIL i>10 or Coins(i)=0
OR:
total = 0
FOR i = 1 to 10
total = total + Coins(i)
NEXT i
A program contains the following code to calculate the circumference of a bicycle wheel, using the wheel size (diameter).
BEGIN
CONSTANT Pi = 3.14
INPUT WheelSize
Circumference = Pi * WheelSize
OUTPUT Circumference
END
The code uses one constant and two variables.
State the name of the constant.
Pi
A program contains the following code to calculate the circumference of a bicycle wheel, using the wheel size (diameter).
BEGIN
CONSTANT Pi = 3.14
INPUT WheelSize
Circumference = Pi * WheelSize
OUTPUT Circumference
END
The code uses one constant and two variables.
State the names of the two variables.
WheelSize & Circumference
A program contains the following code to calculate the circumference of a bicycle wheel, using the wheel size (diameter).
BEGIN
CONSTANT Pi = 3.14
INPUT WheelSize
Circumference = Pi * WheelSize
OUTPUT Circumference
END
Explain one difference between a constant and a variable.
The value of a constant cannot be changed once the program is running (can only be set at design time). The value of a variable can change as the programming is running and has no value at design time.
A program contains the following code to calculate the circumference of a bicycle wheel, using the wheel size (diameter).
BEGIN
CONSTANT Pi = 3.14
INPUT WheelSize
Circumference = Pi * WheelSize
OUTPUT Circumference
END
The data type of WheelSize is integer and the data type of Circumference is real number.
Explain the difference between an integer and a real number.
An integer is a whole number. A real number can include decimal fractions



