Give a reason why HMTL is not regarded as a programming language
Differentiate between object code and source code
Define programming
The process of developing computer programs to solve a particular problem
State and briefly describe three program control structures
Sequence:Sequential execution of a program one line after another
Selection: Involve the a decision between two or more options e.g if...then...else
Loops/Repetitions:use for looping i.e a line of code can be made to execute a given number times before terminating.
List three types of errors that are likely to exist in a program (3 marks)
Syntax errors-Incorrect use of programming language
Logical errors- The program do not give the expected output
Runtime errors- Premature end of a program
Computer programs require translation to execute. (a) Compilers and interpreters translate high-level programming languages into machine code. Describe the main differences between a compiler and an interpreter.
One facility of a Software Development Environment is to convert source code to machine code. Name and briefly describe four other facilities commonly found in a Software Development Environment.
6 Programmers write software that controls hardware and interacts with users. Some of this software ensures that networks function properly.
(a) Compilers and interpreters translate source code written in programming languages.
State four other features of a compiler.
A single executable file is produced
The executable program is portable between machines
The program source code is not available
Code can be optimised/made more efficient
Entire source code file is converted at once
No special environment is needed to execute the code
It creates object/machine code
Error report is provided at the end of the compilation
There are many different types of errors that can occur when developing computer programs. (a) State the name of the two different types of programming error described below.
(i) Unexpectedly halts the program. [1] ..............................................................................................
(ii) The program produces the wrong output. [1] ..............................................................................................
(b) Another error can result from incorrectly using the rules or grammar of the programming language.
(i) Name this error. .............................................................................................. [1]
(ii) State when this error is detected.
(i) Unexpectedly halts the program. Run time (execution)
(ii) The program produces the wrong output. Logical
(b) Another error can result from incorrectly using the rules or grammar of the programming language.
(i) Name this error. Syntax
(ii) State when this error is detected.
Syntax error is detected during translation into executable code / attempted to run but fails
Compare the use of a compiler with the use of an interpreter to translate code
Both translate source code written in high level programming languages into machine code.
Compiler: Produces a single executable file that is portable between machines
Interpreter: Source code needs a special environment to run
Compiler: Needs to be compiled for a particular architecture
Interpreter: Can run on any architecture that has the translator/interpreter
Complier: Entire source code file is translated at once
Interpreter: Code is translated line by line
Compiler: Provides error report at the end of the compilation
Interpreter: Errors more obvious in the sequence
Compiler: The program source code is not available (so helps protect IP)
Interpreter: Source code is available
Compiler: Only has to be translated once (affecting the speed of execution)
Interpreter: Has to be translated each time, therefore (affecting the speed of execution)
Compiler: Requires two files to be maintained (one for execution and for editing purposes)
Interpreter: Requires only one file to be maintained
Explain why a developer, who is good at both low-level and high-level programming, would normally use high-level languages when writing programs.
Describe each of the following types of program errors, using an example.
Syntax error
Logical error
Run-time error
Syntax error
Logical error
Run-time error
Describe and give an example of one syntax and one logical programming error.
Syntax
• An error that occurs when a command does not follow the expected syntax of the language, e.g. when a keyword is incorrectly spelt
• Incorrect: IF A ADN B Then
• Correct: IF A AND B Then
Logical
• An error that causes a program to output an incorrect answer (that does not necessarily crash the program)
• An algorithm that calculates a person’s age from their date of birth, but ends up giving negative numbers
Describe the role of the one-dimensional array in programming
Identify two advantages to a programmer of using a high-level language instead of a low-level language.
Suggest one disadvantage to the programmer of using a high-level language instead of a low-level language.
Describe each of the following types of a program errors, giving an example in each case.
(i) Syntax error.
(ii) Logic error.
(iii) Arithmetic error/runtime error
(i) Incorrect use of language, e.g. PLINT instead of PRINT
(ii) A mistake in the structure of the solution, e.g. a jump goes to the wrong line
(iii) Inappropriate arithmetic is used, e.g. division by 0 is attempted
Explain what is meant by a LIFO data structure.
Describe the purpose of the
(i) control unit
(ii) memory unit
(iii) arithmetic logic unit
in a computer.
i) To manage the execution of instructions
By running a clock
To decode instructions
(ii) To store OS
To store those parts of applications programs currently running
To store data currently in use
(iii) Part of the processor where data is processed/manipulated
All I/O must pass through here
A school has 3000 students sitting final examinations.
Each student sits eight examinations.
Write an algorithm, using pseudocode or a flowchart, which:
• inputs the marks for all 8 examinations for each student
• outputs for each student the average mark for their 8 examinations
• outputs the highest mark overall
highest = -1
for student = 1 to 3000
total = 0
for exam = 1 to 8
input mark
total = total + mark
if mark > highest then highest = mark
next
average = total/8
output average
next
output highest
Python code:
highest = -1
for student in range(1, 3001):
total = 0
for exam in range(1, 9):
mark = int(input("Enter mark: "))
total += mark
if mark > highest:
highest = mark
average = total / 8
print("Average:", average)
print("Highest mark:", highest)
VBA Code
Option Explicit
Sub CalculateAverageAndHighest()
Dim highest As Integer
Dim total As Integer
Dim mark As Integer
Dim average As Double
highest = -1
For student = 1 To 3000
total = 0
For exam = 1 To 8
mark = InputBox("Enter mark:")
total = total + mark
If mark > highest Then
highest = mark
End If
Next exam
average = total / 8
MsgBox "Average: " & average
Next student
MsgBox "Highest mark: " & highest
End Sub
Explain why a developer, who is good at both low-level and high-level programming, would normally use high-level languages when writing programs [4 marks]
What is a source code as used in computer programming?
State and explain characteristics of an algorithm
Input : An algorithm can take 0 or more inputs well defined outputs
Finiteness: an algorithm must terminate in finite time and after finite number of steps.
Definiteness : an algorithm must be clear and unambiguous. Each and every step of an algorithm must be clear and precise and it must have only one meaning
Feasibility: should be feasible with the available resources
Output : must produce at least one well defined output
Independent : should have a step-by-step directions which is independent of any programming language
Correctness: should solve the problem it is designed to solve
Efficiency: must take the shortest time possible to run and should require the least memory space. It should use a minimum number of computation steps and memory to produce the desired output. takes little time and memory to run
Generality: should not be limited to a specific case. It should work for all the valid inputs. works for many possible inputs
Effectiveness : should statements that are relevant to the problem. Every step must be basic and essential.