Explain the term proofreading as used in word processing (2mks) [kcse 2017 Paper 1]
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
Give a reason why HMTL is not regarded as a programming language
Differentiate between object code and source code
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: Used for looping i.e a line of code can be made to execute a given number times before terminating.
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]
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
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.
Differentiate between a compiled and an interpreted program
Differentiate between a function parameter and a function argument
A parameter represents additional information that a function requires to perform its task. Each parameter required by a function is specified in the function header
An argument the value supplied in the function call. When the function is called, the argument value is passed into the function parameter so that the function can perform its task
It helps the programmer visualise the steps in a program / find errors/bugs / check the algorithm gives the correct output (1) because they can see the value a variable holds at a given point in an algorithm (1)
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
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.