THE KENYA NATIONAL EXAMINATIONS COUNCIL
DIPLOMA IN INFORMATION COMMUNICATION TECHNOLOGY
MODULE I
STRUCTURED PROGRAMMING

JULY 2018STRUCTURED PROGRAMMING

 

JULY 2018
TIME: 3 HOURS

INSTRUCTIONS TO CANDIDATES: The paper consists of FOUR questions.
Candidates should answer all questions in the answer booklet provided.
Candidates should answer the questions in English.


1. (a) Outline three advantages of structured programming languages. (3 marks)
ANSWER:

  1. Improves code readability and maintainability.
  2. Allows for easier debugging and testing.
  3. Enhances reusability of code through modularization.

(b) Differentiate between low-level and high-level programming languages. (4 marks)
ANSWER:

  1. Low-level languages are closer to machine language, while high-level languages use more human-readable syntax.
  2. Low-level languages require hardware knowledge, whereas high-level languages abstract hardware details.
  3. Low-level languages are faster but harder to program; high-level languages are easier to program but slower in execution.

2. (a) Explain each of the following statements as used in C programming:
(i) break; (2 marks)

ANSWER:
The break statement exits a loop or switch statement prematurely when a certain condition is met.

(ii) return; (2 marks)
ANSWER:
The return statement exits a function and optionally passes a value back to the calling function.

(iii) goto; (2 marks)
ANSWER:
The goto statement transfers control to a labeled statement within a program. It can lead to disorganized code, which is why it is generally discouraged.


3. (a) Distinguish between records and arrays as applied in C programming language. (4 marks)
ANSWER:
Records (or structures) group variables of different types, while arrays store multiple variables of the same type.

(b) Describe the importance of arrays as used in programming. (4 marks)
ANSWER:
Arrays efficiently store and manipulate large datasets and allow for easier management by enabling operations on collections of variables using loops.


4. (a) Describe two methods of passing arguments to a function in C programming language. (4 marks)
ANSWER:

  1. Pass by value: Copies the argument’s value into the function’s formal parameter, so changes do not affect the original argument.
  2. Pass by reference: Passes the actual memory address of the argument, so changes made within the function affect the original variable.

(b) Write a C program that would accept and print 10 numbers from a user using an array. (5 marks)
#include <stdio.h>

int main() {
int numbers[10];
printf(“Enter 10 numbers:\n”);
for(int i = 0; i < 10; i++) {
scanf(“%d”, &numbers[i]);
}
printf(“The numbers entered are:\n”);
for(int i = 0; i < 10; i++) {
printf(“%d “, numbers[i]);
}
return 0;
}

(c) Explain the function of each of the following C escape characters:
(i) \n; (2 marks)

ANSWER:
The \n escape character moves the cursor to the next line in printed text.

(ii) \t; (2 marks)
ANSWER: