2.5 Programming Languages and IDE + Answers
2.5 Programming Languages and IDE + Answers
INSTRUCTIONS TO CANDIDATES
• Write your name, centre number and candidate number in the boxes above. Please write clearly and in capital letters.
• Use black ink. HB pencil may be used for graphs and diagrams only.
• Answer all the questions, unless your teacher tells you otherwise.
• Read each question carefully. Make sure you know what you have to do before starting your answer.
• Where space is provided below the question, please write your answer there.
• You may use additional paper, or a specific Answer sheet if one is provided, but you must clearly show your candidate
number, centre number and question number(s).
[2]
State why the computer needs to translate the code before it is executed.
[1]
Describe two differences between how a compiler and an interpreter would translate the code.
[4]
[4]
(b) A translator is a common tool found in an Integrated Development Environment (IDE).
Describe two other common tools or facilities that an IDE can provide.
[4]
A program is written to allow a user to enter the radius of a circle as a whole number between 1 and 30, then
calculate and output the area of the circle.
01 radius = 0
02 area = 0.0
03 radius = input("Enter radius")
04 if radius < 1 OR radius > 30 then
05 print("Sorry, that radius is invalid")
06 else
07 area = 3.142 * (radius ^ 2)
08 print (area)
09 endif
An Integrated Development Environment (IDE) is used to write the program.
Identify two features of an IDE that might be used when writing the program.
1
[2]
Describe two methods of translating high level code into machine code.
[4]
01 a = input(“Enter an acronym”)
02 if a == “LAN” then
03 print(“Local Area Network”)
04 elseif a == “WAN” then
05 print(“Wide Area Network”)
06 ……………………………………………………………………………………………
07 ……………………………………………………………………………………………
08 endif
(i) Complete the code above to print out an “unknown” message if any other acronym is entered by the user. [2]
[2]
[4]
Each page has an average of 300 words. Each chapter starts with a chapter title page.
The number of pages is estimated by;
Joseph uses the algorithm below to estimate the number of pages, but his algorithm does not give the correct
result.
01 INPUT numberOfWords
02 INPUT numberOfChapters
03 CONST wordsPerPage = 300
04 numberOfPages = RoundDown(numberOfWords / wordsPerPage)
05 numberOfPages = numberOfWords + numberOfChapters
06 OUTPUT numberOfPages
Joseph has used a RoundDown function to remove the decimal part of the division, e.g. RoundDown(6.2)
would return 6, RoundDown(7.8) would return 7.
Describe two additional tools in an IDE that Joseph could use to help him produce his program.
Tool 1 name:
Tool 1 description:
Tool 2 name:
Tool 2 description:
[4]
Describe how Joseph could make use of a compiler and an interpreter when producing his program.
Compiler:
Interpreter:
[4]
The table below shows some CPU instructions and what they mean.
Using examples from the instructions above, state what is meant by:
[2]
(Part of the instruction which) supplies
the data / address / value needed for
(ii) an operand an operation
e.g. the number to be added /
subtracted from the timer / numerical
example from the table (00010100 or
00000001) [2]
The time displayed on the microwave oven is represented as two 8-bit binary numbers, one for the minutes
and one for the seconds.
For example;
“8:20” is stored as 00001000 00010100
“15:45” is stored as 00001111 00101101
(b) Show how the time 5:30 will be stored.
[2]
(c) 00001000 00010100 can represent either the instruction for “Add 20 to the timer” or the data for the time “8:20”.
Explain how the CPU can determine whether it represents an instruction or data.
[1]
Finn has written a program to allow a user to enter the radius of a circle as a whole number, between 1 and 30,
and output the area of the circle.
Finn uses an IDE (Integrated Development Environment) to write his programs. Identify two features of an IDE
that Finn might use.
[2]
10(a) Harry is planning to create a computer game using a high-level programming language.
State why the computer needs to translate the code before it is executed.
[1]
Describe two differences between how a compiler and an interpreter would translate Harry's computer game.
[4]
11 Jim is writing a program to calculate the wages of workers in a teddy bear factory.
Describe two tools in an IDE that can help Jim when creating the program.
[4]
Machine code
[1]
Total 2
b Compiler translates all the code in one 4 1 mark to be awarded for the correct
go… (AO1 1b) identification and one for a valid description
…whereas an interpreter translates up to a maximum of 4 marks.
one line at a time No more than 2 marks for answers relating
Compiler creates an executable… only to interpreters and no more than 2
…whereas an interpreter does marks for answers only relating to
not/executes one line at a time compilers.
Compiler reports errors at the end…
…whereas an interpreter stops when it
finds an error
Total 5
b 1 mark per bullet, max 4 4 Allow other tools available in an IDE with
suitable expansion (e.g. breakpoints, watch
e.g. window, stepping, pretty printing, etc)
Editor
…to enable program code to be
entered / edited
Error diagnostics / debugger
…to display information about errors /
location of errors / suggest solutions
Run-time environment
…to enable program to be run / to
check for runtime errors / test the
program
Total 8
Total 2
5 1 mark per bullet to max 4, 2 mark max per 4 Mark first method only in each section
method AO1 1b
(4) Examiner’s Comments
Compiler
…translates code in one go / all at This question was answered well by large
once numbers of candidates who were able to
…produces an executable file // does list the two translators listed in the
not need to be compiled again specification, compilers and interpreters.
Total 4
6 a 1 mark per bullet, max 2. 2 Accept logically correct equivalents for else
(e.g. elseif a!=“LAN“ and/or a
!=“WAN“). Do not allow elseif on its
else own
print (“unknown”)
Accept other keywords for print (e.g.
“output”) as long as the intention is clear.
Examiner’s Comments
Misconception
To compare the contents of a variable
against two possible values, it is incorrect
to use :
• if a!=‘WAN’ or ‘LAN’
In the example above, the comparison of a
against ‘WAN’ is logically correct, but it is
unclear what ‘LAN’ is being compared
against.
A logically correct way to achieve the same
thing would be :
• if a!=‘WAN’ and a!=‘LAN’
aimed at humans//understandable by
humans / programmers Do not award marks for naming languages
English like structure / syntax such as Java , Python, etc.
Must be
translated/compiled/interpreted (before
it can be run) Do not award marks for stating what a high
Allows programmer to deal with the level language isn’t (i.e. describing what
problem instead of considering the low level code is).
underlying hardware // an abstraction
from the hardware // hardware Do not allow “easy to use”
independent // portable
Do not allow ‘has to be converted’ without
into what i.e machine code etc.
Examiner’s Comments
b 1 mark per bullet, max 4. 4 One mark for identifying, one mark for
describing. Accept description of a tool
e.g. without (or with incorrect) naming of the
tool.
Editor
…to enable program code to be Allow sensible descriptions which go
entered/edited across pairs or name other tools sensibly
(e.g. editor / highlighting syntax)
Error diagnostics / debugging
…to display information about errors Allow any sensible tool that an IDE
(syntax / run-time) / location of errors provides (e.g. auto documentation, help
… suggest solutions tools, pretty printing etc.)
Run-time environment
…to enable to the program to be run
… check for run time errors / test the
program
Total 8
b Max 2 for compiler, 2 for interpreter 4 The uses must be different for compiler
Compiler and interpreter
Total 8
8 a i (Part of the instruction which) specifies 2 The answer must refer specifically to the
the operation to be carried out operation to be carried out and not the
e.g. 00001000 = add to timer / instruction as a whole.
00000100 = subtract from timer
ii (Part of the instruction which) supplies 2 For data, accept number / integer.
the data / address / value needed for
an operation
e.g. the number to be added /
subtracted from the timer / numerical
example from the table (00010100 or
00000001)
Total 7
Total 2
b Compiler translates all the code in one 4 1 mark to be awarded for the correct
go… identification and one for a valid description
… whereas an interpreter translates up to a maximum of 4 marks. No more
one line at a time than 2 marks for answers relating only to
Compiler creates an executable… interpreters and no more than 2 marks for
…whereas an interpreter does not / answers only relating to compilers.
executes one line at a time
Compiler reports all errors at the end…
… whereas an interpreter stops when it
finds an error
Total 5
Examiner's Comments
Total 4
Machine code:
ii To translate the high level code into 1 Translate to object code is acceptable
machine code Accept “errors” on its own, but do not
To pick up (syntax) errors accept answers referring specifically to
logic or runtime errors.
Total 5