OCR_Computing_GCSE_Programming Flashcards

1
Q

A syntax error can occur when writing a program.

State what is meant by a syntax error, giving an example.

A

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!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe tools and facilities available in an integrated development environment (IDE) which can help the programmer to identify and correct syntax errors.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain why a program written in a high level language needs to be translated before it can be executed.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A compiler and an interpreter are two different types of translator. Describe differences between a compiler and an interpreter.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe what is meant by a variable.

A

A name/symbol which represents a value is a program. The value can change while the program is running.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

ORIGIN
String. Consists of more than one character.

Size
Integer. Consists of whole numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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)

A

50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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)

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

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.

A

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

19
Q

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.

A

The program is written to do something other than what the programmer intended

20
Q

Write an algorithm to calculate the total value of the coins entered in the current sale using the contents of the array Coins.

A

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

21
Q

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.

A

Pi

22
Q

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.

A

WheelSize & Circumference

23
Q

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.

A

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.

24
Q

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.

A

An integer is a whole number. A real number can include decimal fractions

25
Q

A dog that is 5 years old is equivalent to a 42 year old human. Kyle is writing a program which converts the age of a dog to the equivalent age for a human.The program uses the following method:
• The user inputs age of the dog in years.
• If the age is 2 or less, the human equivalent is 12 times the age.
• If the age is more than 2, the human equivalent is 24 for the
first 2 years, plus 6 for every additional year.

Write an algorithm to calculate and output the human equivalent of the age of a dog using the method described.

A

BEGIN
Input RealAge
IF RealAge <= 2
DogYears = RealAge * 12
ELSE
ExtraYears = RealAge – 2
DogYears = 24 + ExtraYears * 6
END IF
END

26
Q

A program includes the following code.

If A > B Then
A = B
B = A
End If

The code uses the variables A and B. Describe what is meant by a variable.

A

A name which is used to identify a memory location used to store a value which can change.

27
Q

A program includes the following code.

If A > B Then
A = B
B = A
End If

State the final values of the variables A and B if the values at the beginning of the code are . A=4, B=9

A

A=4

B=9

28
Q

A program includes the following code.

If A > B Then
A = B
B = A
End If

State the final values of the variables A and B if the values at the beginning of the code are. A=6, B=2

A

A=2

B=2

29
Q

Line 1) If A > B Then
Line 2) A = B
Line 3) B = A
Line 4) End If

The intention of lines 02 and 03 is to swap the contents of the variables A and B. This does not work.

Rewrite the code so that the contents of the variables are swapped correctly.

A

If A > B Then
Temp = A
A = B
B = Temp
End If

30
Q

A display board can show a flashing message of up to 20 characters.A program allows users to input the message to be displayed and the number of times it should flash.

Write an algorithm for the program which:
•Allows the user to input the message and the number of flashes.
•Rejects the message if it is longer than 20 characters and stops.
•Otherwise it repeatedly displays the message and clears the display for the correct number of times.

A
31
Q

A display board can show a flashing message of up to 20 characters.

A program allows users to input the message to be displayed and the number of times it should flash.

State the data type of the input data.

NoOfFlashes:

A

Integer

32
Q

A display board can show a flashing message of up to 20 characters.

A program allows users to input the message to be displayed and the number of times it should flash.

State the data type of the input data.

Message:

A

String

33
Q

Crystal has a program (app) on her mobile phone, which calculates the cost of the calls she has made.
The program uses the following variables.

State the most appropriate data type for each variable.

Network: The name of the mobile phone network. eg Vodafone, 02

A

Network: string/text/alphanumeric

34
Q

Crystal has a program (app) on her mobile phone, which calculates the cost of the calls she has made.
The program uses the following variables.

State the most appropriate data type for each variable.

CallLength: The length of the call made, eg 1.5 for one and a half minutes

A

CallLength: real /float/single/double

35
Q

Crystal has a program (app) on her mobile phone, which calculates the cost of the calls she has made.
The program uses the following variables.

State the most appropriate data type for each variable.

SameNetwork: Whether the call was made to a phone on the same network.

A

SameNetwork: Boolean

36
Q

Crystal has a program (app) on her mobile phone, which calculates the cost of the calls she has made.
The program uses the following variables.

State the most appropriate data type for each variable.

TotalCalls: The toal number of calls made e.g 10

A

TotalCalls: integer

37
Q

Crystal has a program (app) on her mobile phone, which calculates the cost of the calls she has made.
The program uses the following variables.

State the most appropriate data type for each variable.

RunningCost : The calculated cost of calls eg £12.00

A

RunningCost :currency/real

38
Q

The algorithm to update the data when a new text call is made is shown below.

PROCEDURE Update
TotalCalls = TotalCalls + 1
IF SameNetwork = TRUE THEN
RunningCost = RunningCost + 0.01
ELSE
RunningCost = RunningCost + (CallLength * 0.10)
END IF
END PROCEDURE Update

So far TotalCalls = 10 and RunningCost = £12.00
Crystal makes a 3 minute call to a phone on the same network.
State the values of TotalCalls and RunningCost after they have been updated using this algorithm.

A
**TotalCalls = 11
RunningCosts = 12.01**
39
Q

The algorithm to update the data when a new text call is made is shown below.

PROCEDURE Update
TotalCalls = TotalCalls + 1
IF SameNetwork = TRUE THEN
RunningCost = RunningCost + 0.01
ELSE
RunningCost = RunningCost + (CallLength * 0.10)
END IF
END PROCEDURE Update

So far TotalCalls = 11 and RunningCost = £12.01

Crystal now makes a 5 minute call to a phone on a different network. State the values of TotalCalls and RunningCost after they have been updated using this algorithm.

A
**TotalCalls = 12
RunningCosts = 12.51**
40
Q

Josh is writing a program to convert the time from the 24 hour clock to the 12 hour clock.
Here is an extract from his program. This extract contains two errors.

IF (hours > 12) ADN (hours < 24) THEN
hours = hours + 12
END IF

Explain why there is an error in the first line, and state what type of error this is.

A

The keyword AND has been misspelled (ADN). This breaks the rules of the language and is a syntax error.

41
Q

Josh is writing a program to convert the time from the 24 hour clock to the 12 hour clock.
Here is an extract from his program. This extract contains two errors.

IF (hours > 12) ADN (hours < 24) THEN
hours = hours + 12
END IF

Explain why there is an error in the second line, and state what type of error this is.

A

It will produce the wrong result as it is adding instead of subtracting. This is a logic error.

42
Q

Felix is writing a program that uses an array called WordList. This array contains 10 foreign words in alphabetical order. The contents of the array are shown below.

The value of WordList(1) is “akesi”.

State the value of WordList(9)

A

“taso”

43
Q

Felix is writing a program that uses an array called WordList. This array contains 10 foreign words in alphabetical order. The contents of the array are shown below.

The value of WordList(1) is “akesi”.

State the value of WordList(6)

A

“mama”

44
Q

Felix needs to write a routine that:

•allows the user to input a word,
•goes through the items in the array WordList in turn, starting from the WordList(1),
•if it finds the word that the user has input, it outputs “Word
found”.

Write down an algorithm for this routine in pseudocode.

A

INPUT SearchWord
I = 0
REPEAT
I = I + 1
IF WordList(I) = SearchWord THEN
OUTPUT “Word Found”
END IF
UNTIL I = 10

For loop would be accepted