# BBIT 105 PROGRAMMING METHODOLOGY- DISTANCE LEANING KCA Past Paper

UNIVERSITY EXAMINATIONS: 2014/2015
ORDINARY EXAMINATION FOR THE BACHELOR OF BUSINESS
INFORMATION TECHNOLOGY
BBIT 105 PROGRAMMING METHODOLOGY- DISTANCE
LEANING
DATE: DECEMBER, 2014 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE [30 MARKS]
a) State the values of the control variable x to be printed by each of the following statements in c.
i) for(x=2;x<=13;x+=2);
[2 Marks]
ii) for (x=12;x>=2;x-=3) [2 Marks]
b) A recursive function can be defined as a function which either calls itself or is in a
potential cycle of function calls. Write a program in c that uses a recursive function to
calculate a factorial of a number. [6 Marks]
c) Design a program using pseudo code to calculate and display sum of even numbers
between 2 and 30. [4 Marks]
d) Write a program in c to implement the design in [c]. [4 Marks]
e) Differentiate between IF and SWITCH selection structures in a c program. [4 Marks]
f) A variable is an identifier that denotes a storage location used to store a data value.
Outline three important rules for naming variables in c. [4 Marks]
g) Describe imperative programming, and in particular highlight its distinctive features.
[4 Marks]
QUESTION TWO [20 MARKS]
a) Design a program using arrays to calculate and display the total weight in kilograms of forty
six (46) passengers. [6 Marks]
b) Write a program in c to implement the design in [a]. [8 Marks]
c) The following statements were used to declare arrays. State the amount of memory allocated
for each at compile time.
i) int nums[4][6][6];
[3 Marks]
ii) double nums[4][6][6]; [3 Marks]
QUESTION THREE [20 Marks]
a) Discuss the term indirection as used in pointers. [4 Marks]
b) State whether the following statements are true or false. If the answer is false, explain why.
i) The default case is required in the switch selection statement. [2 Marks]
ii) An expression containing the ||operator is true if either or both of its operands is true
[2 Marks]
iii) The break statement is required in the default case of a switch selection statement.
[2 Marks]
iv) The expression (x>y&&a<b) is true if either x>y or a<b is true. [2 Marks]
c) You are required to write a program that uses structure called product whose members are
price and quantity. There are two objects (instances) of this structure namely soap and salt.
Assume price is of type float while quantity is of type integer. [8 Marks]
QUESTION FOUR [20 Marks]
a) Define a string, hence state and explain the uses of any four functions used in string manipulations. [9 Marks]
b) Explain the output of the following program. Assume the user has entered “Kenya”
and “Uganda” for the first and second string respectively.
#include<stdio.h>
#include<string.h>
int main()
{
char strg1[100];
char strg2[100];
printf(“\nEnter the first string : “);
gets(strg1);
printf(“\nEnter the second string : “);
gets(strg2);
strcpy(strg2, strg1);
strcpy(strg1, strg2);
printf(“\nThe value of first string is : %s\n”, strg1);
printf(“\nThe value of the second string : %s\n”, strg2);
return (0);
}
[6 Marks]
c) Write a program to calculate the amount a at the end of t years if the principle value
p earns a compound interest at the rate r, using library function math.h. The amount
is calculated using the formula n
a = p(1+r) . [5 Marks]
QUESTION FIVE [20 MARKS]
(a) Explain the difference between fatal and non fatal error in a program. Give an example in
each case. [ 6 marks]
(b) Identify and explain the errors in the following code snippets.
i) int x = 5;
while( x > 0 );
x–;
[2 Marks]
ii) int x = 5;
if ( x = 6 )
printf(“x equals 6\n”); [2 Marks]
(c) Explain the differences and similarities between DO loop and WHILE loop. Present the general syntax for each structure. [6 marks]
(d) Explain the output of the following code in c.
#include <stdio.h>
int main()
{
int i = 13;
while(i>=1)
{
int k = i % 2;
printf(“%d\n”, k);
i–;
}
return 0;
}
[4 Marks]

(Visited 84 times, 1 visits today)