COMP 113
UNIVERSITY EXAMINATIONS
1ST SEMESTER 2022/2023 ACADEMIC YEAR
FIRST YEAR EXAMINATION FOR THE DEGREES OF
BACHELOR OF SCIENCE (COMPUTER
SCIENCE)/BACHELOR OF SCIENCE (ICT)
COMP 113: INTRODUCTION TO PROGRAMMING
STREAM: R TIME: 2 HRS
DAY: WED [8.30AM – 10.30AM] DATE: 14/12/2022
THIS QUESTION PAPER CONSISTS OF SIX (6) PAGES
PLEASE DO NOT OPEN UNTIL THE INVIGILATOR SAYS SO.
Vision : A University for Valued Transformation of Society Page 1 of 6
Mission: To serve students and society through research, education, scholarship, training, innovation, outreach and consultancy
Laikipia University is ISO 9001:2015 and ISO/IEC 27001:2013 Certified
COMP 113
INSTRUCTIONS
Answer ALL questions in section A and any TWO questions in section B
All questions in section B carry equal marks
SECTION A (30 Marks)
QUESTION ONE (30 marks)
a) Define the relationship between variables and data types. (2 Marks)
b) Explain when one would use the do… while loop and not the while loop. (2 Marks)
c) Define the term structure members. (2 Marks)
d) Write down the snippet of code that would create a structure called employee. empname,
empid, emptitle, and empsalary are the members of the structure and books is the
structure variable. (5 Marks)
e) Distinguish between each of the following pairs of terms:
i. Operator and operand (2 Marks)
ii. Source code and object code (4 Marks)
f) Define the term function and illustrate the syntax used to declare a function.
(4 marks)
g) Write a C program to illustrate the use of 3 library string functions. (Include the output to
your program after writing the code.) (6 Marks)
h) What is the output of the following program? (3 Marks)
#include<stdio.h>
main()
{
int pica = 0, delta = 0;
While(pica <= 20)
{
if(pica % 5 == 0)
{
delta += pica;
printf(“\n %d ”, delta);
}
Vision : A University for Valued Transformation of Society Page 2 of 6
Mission: To serve students and society through research, education, scholarship, training, innovation, outreach and consultancy
Laikipia University is ISO 9001:2015 and ISO/IEC 27001:2013 Certified
COMP 113
delta++;
}
}
SECTION B: Each question is worth 20 Marks. Answer any TWO questions in this section
QUESTION TWO (20 marks)
(a) Write a C program using the switch statement that will ask the user to enter a value between
1 and 7 and will print out the day of the week based on the number chosen i.e. as in 1 for
Sunday to 7 for Saturday. (7 Marks)
(b) Briefly describe the difference between each of the following pairs of operators as used in C
language: (8 Marks)
i. /= and +=
ii. = = and !=
iii. && and | |
(c) You have been asked to advice interns at Toyota Kenya the phases of a Software
Development Life Cycle. Describe what happens during problem recognition and problem
definition stages of SDLC. (5 Marks)
QUESTION THREE (20 marks)
(a) Draw a flowchart to illustrate the following program: (5 Marks)
#include<stdio.h>
void main()
int mark;
printf(“\n Enter the mark: \n”);
scanf(“%d”, &mark);
if(mark < 40)
printf(“\n You have failed! \n”);
Vision : A University for Valued Transformation of Society Page 3 of 6
Mission: To serve students and society through research, education, scholarship, training, innovation, outreach and consultancy
Laikipia University is ISO 9001:2015 and ISO/IEC 27001:2013 Certified
COMP 113
else
printf(“\n You have passed!\n”);
a) C Language statements, labels, arrays e.t.c. are separated by special characters known as
delimiters. Enumerate the use of the following delimiters in C language construct.
(4 Marks)
(i) #
(ii) []
(iii) {}
(iv) ;
b) What is the difference between passing arguments to a function by value and passing by
reference? (4 Marks)
c) Write a C program that requests a user to key in the bonga points that they have
accumulated and the displays the reward they have qualified for (use the table below as a
guide) (7 Marks)
Bonga points Reward
0 -199 null
200 - 499 8 free sms’s
500 - 999 5 free minutes
1000 - 4999 Nokia 1100
5000 and above Safaricom modem
QUESTION FOUR (20 marks)
a) Rewrite the following program using the switch construct. (6 Marks)
#include<stdio.h>
main()
char grade;
Vision : A University for Valued Transformation of Society Page 4 of 6
Mission: To serve students and society through research, education, scholarship, training, innovation, outreach and consultancy
Laikipia University is ISO 9001:2015 and ISO/IEC 27001:2013 Certified
COMP 113
printf(“Enter the Grade:”);
scanf(“%c”, &grade);
if(grade == ‘A’)
printf(“Excellent !\n”);
else if(grade == ‘B’)
printf(“Good !\n”);
else if(grade == ‘C’)
printf(“Fair !\n”);
else if(grade == ‘D’)
printf(“Poor !\n”);
else if(grade == ‘E’)
printf(“Very Poor !\n”);
else
printf(“Wrong Entry !, Enter a grade between A – E \n”);
b) Distinguish between the indirection operator (*) and the address operators (&) as used
with pointers. (2 Marks)
c) Discuss about declaring, initializing and accessing a one-dimensional array in C. Use
examples to illustrate each concept. (8 Marks)
d) Write the output of the following program. (4 Marks)
#include <stdio.h>
int main( )
{
int x;
for(x=10; x >=3; x--)
printf("%d ", x);
Vision : A University for Valued Transformation of Society Page 5 of 6
Mission: To serve students and society through research, education, scholarship, training, innovation, outreach and consultancy
Laikipia University is ISO 9001:2015 and ISO/IEC 27001:2013 Certified
COMP 113
return 0;
}
QUESTION FIVE (20 marks)
a) Give the meaning of the following components of a C program. (8 Marks)
i) Preprocessor directive
ii) Declaration
iii) Comment
iv) Header File
b) Write C programs that will accomplish the following
i) Print from 10 to 60 using the while loop (5 Marks)
ii) add numbers 5 through 10 (inclusive) using the for loop (7 Marks)
Vision : A University for Valued Transformation of Society Page 6 of 6
Mission: To serve students and society through research, education, scholarship, training, innovation, outreach and consultancy
Laikipia University is ISO 9001:2015 and ISO/IEC 27001:2013 Certified