July 2019 Structured Marking Scheme
July 2019 Structured Marking Scheme
ANSWERS
1(a) (i)
• much easier to learn compared to machine language
• Coding took less time than coding using machine language
• Error correction was less cumbersome
(ii) Procedural languages
They require the programmer to specify step by step how the computer will accomplish a
specific task. Program execution follows the exact sequence laid down by the programmer
during coding
Non procedural
They allow the programmer to specify the desired result without having to specify the detailed
procedure needed to achieve the result
1(b)
The main problem is identified first and its outline developed. This enables the programmer to
work from thee known to unknown.
The management has specific goals that must be met by the programmer when the problem to be
solved is known in advance
1(c)
Step 1-sqr (a)=sqr(4)=16
Step 2-b*c=6*10=60
Step 3-6/d=6/3=2
Step 4-b*c mod 4/d=60/20=0
Step 5-sqr (a) + ((b*c) mod (6/d) =16+0=16
2: (a) (i)
A user-defined data type (UTD) is a data type that derived from an existing data type
(ii) record/struct
Type
Patient=record
Patient_ no, age: integer
Patient_ name, gender: string;
End.
C:
#include<stdio.h>;
#include<stdlib.h>;
Int main();
{
Int points
Printf(“enter the points obtained by a student”);
Scanf(“%d”,,&points);
Switch (points);
{
Case 1:printf(“distinction”)
Break;
Case 2: printf(“credit”)
Break;
Case 3: printf (“pass”)
Break;
Default: printf(“fail”);
Break
}
3(.c)
Program gets sum (input, output);
Var num, sum value: integer;
Begin
Sum: =0;
Writeln (‘enter a positive integer);
Readln (num);
For value: =0 to num do
Begin
Sum: =sum +value;
End;
Writeln (‘the sum of the integer is ‘, sum );
End.
4) (a). Assembler
This is a program that translate a source program written in assembly language into its equivalent
machine code (object code)
Q4B(ii)
Line 1-calls an header file stdio.h
Line 2-creates a main function that returns an integer value
Line 3-opening braces indicating the start of the main function
Line 4-declares an array named Myarray of size 4 and initializes the array elements
Line 5-declares two variables I and j of the type integer
Line 6-creates a for loop and initializes it from 3 down to 0
Line 7-opening brace indicating the beginning of the for loop
Line 8-outputs the elements in the array in the format element[j]=j
Line 9-closing brace indicating the end of the for loop
Line 10-return specifier
Line 11-closing brace indicating the end of the main function
Q4C) (i) A comment is a programmer –readable explanation or annotation in the source code of
a computer program. They are added with a purpose of making the source code easier for
humans to understand, and are generally ignored by compilers and interpreters.
5b)
procedure bubble sort(list: array of items
loop=list.count;
for i=0to loop-1 do:
swapped=false
for j=0 to loop-1do:
/*compare the adjacent elements*/
If list[j]>list[j+1]then
5d)#include <stdio.h>
#include<stdlib.h>
Int main()
{
Int I,j;
For(i=4;I<=6;i++)
{
For(j=4;j<=I;j++)
Printf(“%d\t”,j);
Printf(“\n”);
}
Return 0;
}
6 (a)To improve the speed of execution
To improve memory utilization
To reduce the lines of code
Tom
George
Joan Wayne
Beatrice Ray
6d)program password;
var code,x:interger;
begin
for x:=1 to 3 do
begin
writeln(‘enter your code’);
readln(code);
if code=1234 then
writeln(‘welcome’);
break;
else
writeln(‘ the code is incorrect’);
end;
end.
b) the realloc () function is used to allocate memory and has the following prototype
The free() function is used to release memory that had previously allocated using the malloc().
d) program mrarray;
var
a:array [0..3,0..3] of integer;
I,j:integer
Begin
For i:=0 to 3 do
For j:=0 to 3 do
A[I, j] :i* j;
For i:= 0 to 3 do
Begin
For j:= 0 to 3 do
Write (a[I, j]: 2,);
Writeln;
End;
End.
C(i) Stack underflow happens when we try to pop (remove) an item from the stack, when
nothing is actually there to remove. This will raise an alarm of sorts in the computer because we
told it to do something that cannot be done.
Stack overflow happens when we try to push one more item onto our stack than it can actually
hold. You see, the stack usually can hold only so much stuff. Typically, we allocate (set aside)
where the stack is going to be in memory and how big it can get. So, when we stick too much
stuff there or try to remove nothing, we will generate a stack overflow condition or stack
underflow condition, respectively.
o strerror(): returns a pointer to the textual representation of the current errno value.
Syntax:
o char *strerror (int errnum)
errnum: is the error number (errno).
Q8 d
Program One;
Var status:string;
Begin
Writeln(‘Enter the status=’);
Readln(status)
If (status=’orphan’) then
Writeln(‘Amount Allocated is Ksh 15,000’)
elseIf (status=’needy’) then
Writeln(‘Amount Allocated is Ksh 13,000’)
elseIf (status=’Affirmative Action’) then
Writeln(‘Amount Allocated is Ksh 13,000’)
Else
Writeln(‘Amount Allocated is Ksh 0’).
Readln;
End.