KENYA METHODIST UNIVERSITY
END OF 2ND TRIMESTER 2018 (FT) EXAMINATIONS
SCHOOL : SCIENCE AND TECHNOLOGY
DEPARTMENT : COMPUTER SCIENCE
COURSE CODE : BIT 222 /CISY 111
COURSE TITLE : STRUCTURED PROGRAMMING
TIME : 2 HOURS
INSTRUCTIONS:
Answer Question One and any other Two Questions.
Question 1 (One)
a) Explain the following terms as used in programming
i) Function (2 marks)
ii) Variable (2 marks)
iii) Algorithm (2 marks)
b) State any five advantages of structured programming methodology.
(5 marks)
c) Differentiate between syntax and logical errors as used in programming.
(4 marks)
d) Explain the significance of structure charts as used in modular
programming. (3 marks)
e) Explain three control structures used to express program logic in C++
programming.
(6 marks)
f) Write a code segment in C++ that defines a function called Grade of type
Integer and asks a user to enter a student score of an exam and finally
Page 1 of 4/ BIT 222 /CISY 111
outputs either “Pass” or ”Fail” using the following condition.
(5 marks)
Score Output
< 50 Fail
50 and Pass
Above
g) Prototype a function called addition that accepts two variables(a and b) of
type integer and computes their sum whenever called at some point of
the program (4 marks)
Question 2 (Two)
a) Write a C++ program that defines a structure called Student with the
member variables Sname of character data type, Maths, Eng, Kisw all of
integer data type, total and Average both of float data type. Declare a
variable S1 of type Student. Your program should prompt a user to input
the student name, the three subject scores, and compute the total and
average scores using the dot operator (.) to access the structure member
variables. (9 marks)
b) Most programming languages provide while, do while and for loop to
handle looping requirements. Describe each of them using a flow diagram
(6 marks)
Question 3 (Three)
a) Explain a pointer variable as used in programming
(2 marks)
b) Explain each line in the following program segment
(8 marks)
// my first pointer
#include <iostream>
using namespace std;
int main ()
Page 2 of 4/ BIT 222 /CISY 111
{
int value1 = 5, value2 = 15;
int * mypointer;
mypointer = &value1;
*mypointer = 10;
mypointer = &value2;
*mypointer = 20;
cout<< "value1==" << value1 << "/ value2==" << value2;
return 0;
}
c) What are the final values stored in the variables; value 1 and value 2 after
execution of the above code?
(2 marks)
d) Explain the following functions as used in structured programming.
(3 marks)
i) malloc( )
ii) calloc( )
iii) realloc( )
Question 4 (Four)
a) Explain a recursive function as used in program development
(2 marks)
b) Write a C++ recursive function to obtain the factorial of a number (n)
entered by a user
(5 marks)
c) Using relevant examples distinguish between function argument pass by
value and pass by reference
(4 marks)
d) Write a C++ code segment that defines a function called Add that returns
the sum of two integers to the main function. The return type being an
Page 3 of 4/ BIT 222 /CISY 111
integer value (4 marks)
Page 4 of 4/ BIT 222 /CISY 111