admin@kcseforecast.com

Q&A-KCSE Computer Studies Paper 1

Explain the term proofreading as used in word processing (2mks) [kcse 2017 Paper 1]

  • It is the use of proofing tools like spelling and grammar checkers and autocorrects to check whether a document has typographical or grammatical errors

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

  •  It does not have declaration part
  • It does not  have control structures

Differentiate between object code and source code

  • Object code refers to a program in machine language while source code to a program in a high level language that must be translated to object code for it to be machine readable

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: 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]

  • High-level languages have built-in functions;
  • High-level languages have built-in libraries;
  •  High-level languages have more support/help;
  • High-level languages have structures (such as selection and iteration);
  • High-level languages can be less machine-dependent/more portable;
  • It (usually) requires fewer lines of code to be written;
  • It is (usually) quicker to develop code in high-level languages;
  • It is easier to find mistakes in code;
  • The code is easier to maintain//understand;
  • • It is easier to structure code in high-level languages;

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?

  • It is a program written in a high level langauage

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

  • A compiled program will only execute on a processor of specific type/family/with same instruction set
  • A program run using an interpreter can execute on a computer with any type of processor

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

Programmers use trace tables with algorithms. Explain the purpose of a trace table.

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.

  • High-level languages have built-in functions;
  • High-level languages have built-in libraries;
  • High-level languages have more support/help;
  • High-level languages have structures (such as selection and iteration);
  • High-level languages can be less machine-dependent/more portable;
  • It (usually) requires fewer lines of code to be written;
  • It is (usually) quicker to develop code in high-level languages;
  • It is easier to find mistakes in code;
  • The code is easier to maintain//understand;
  • It is easier to structure code in high-level languages;

Describe each of the following types of program errors, using an example.

Syntax error

Logical error

Run-time error

Syntax error

  • An error in the source code of a program like pront("Hello, " + name) instead of print
  • These are errors that emanate from improper use of language rules such as spelling mistakes,improper use of variables and misuse of reserved words

Logical error

  • A mistake in a program's source code that results in incorrect or unexpected behaviour like if age == 65: print("Eligible for a discount.") instead of using if age >= 65: print("Eligible for a discount.")
  • These are errors that occur due to imperfect comparisons

Run-time error

  • An error which occurs when a program is asked to do something that it cannot, resulting in a ' crash'9. For example, asking a number to be divided by 0 such as 72/0.
  • An error that results in a sudden halt of an executing program

 

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

  • holds an indexed sequence of variables of the same data type
  • Arrays can be used to store values of the same data type and the array is then used as a singular variable to increase efficiency

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.

  • A compiler translates the whole program in one go whereas An interpreter translates each line of code (often an intermediate code) at run time
  • A compiler produces an executable file that will run on the target hardware machine without the compiler being installed  A run time interpreter will be required at run time
  • Compilers tend to be large complex programs Interpreters are smaller simpler programs
  • Interpreted programs can be amended and run without translating whole program Compiled programs have to be re-compiled after a change
  • Compilers compile programs that will usually only run on the target platform (hardware/operating system)  Interpreters will interpret same program (or intermediate code) on different (some virtual) platforms