BIT 1304 PROGRAMMING METHODOLOGY KCA Past Paper

UNIVERSITY EXAMINATIONS: 2011/2012
FIRST YEAR EXAMINATION FOR THE BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
BIT 1304 PROGRAMMING METHODOLOGY
DATE:AUGUST, 2012 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE
a) Distinguish between a pseudocode and algorithm. [2 Marks]
b) Distinguish between function parameters and function arguments. [2 Marks]
c) Given the code below,
#include <stdio.h>
main()
{
for(int i=0;i<5;i++)
{
printf(“Hello, World!\n”)
}
return 0;
}
2
i. Identify the line(s) and state the type of error which may result when the
program is compiled and executed.
[1 Mark]
ii. What is the use of #include statement? [1 Mark]
iii. What will be the output of the program if the error is corrected? [2 Marks]
d) Given the following problem involving computing weekly wages: Gross pay depends
on the pay rate and the number of hours worked per week. However, if you work
more than 40 hours, you get paid time-and-a-half for all hours worked over 40.
Pseudo-code the task of computing gross pay given pay rate and hours worked is
given as shown.
get hours worked
get pay rate
if hours worked ≤ 40 then
3.1 gross pay = pay rate times hours worked
else
4.1 gross pay = pay rate times 40 plus 1.5 times pay rate times (hours
worked minus 40)
display gross pay
halt
variables: hours worked, ray rate, gross pay
i. Translate the same to a flow chart [3 Marks]
ii. Write a complete C application for the problem [6 Marks]
e) Explain any FOUR programming domains [4 Marks]
f) How many * does the following program segment print [3 Marks]
for (x=0 ; x <10 ; x++)
for ( y=5; y>0 ; y – -)
printf(“ * “);
a) Distinguish between a while loop and a do-while loop using a flow chart.
[4 Marks]
b) Write a program that prompts for two integer numbers and determines if the
numbers are equal or not equal and finally displays the remainder of the division
between them. [2 Marks]

QUESTION TWO
a) Many programmers plan their programs using a sequence of steps, referred to as
the program development cycle. Explain the step-by-step process which will
enable you to use your time efficiently and help you design error-free programs
that produce the desired output.
[6 Marks]
b) An array is declared with the following statement
char grapes[2] [3];
i. What is the name of the array? [1 Mark]
ii. How many elements does the array have? [1 Mark]
iii. What data type does the array hold? [1 Mark]
iv. Modify the above array to hold three records but with the same number of
elements as the original array. [2 Marks]
c) Write a C program that will be able to produce the following result shown below.
The program should accept only numbers between 1 and 10. [6 Marks]
Output of the program will appear as:
This program prompts you to enter 5 numbers
Each number should be from 1 to 10
Enter number 1 of 5: 3
Enter number 2 of 5: 6
Enter number 3 of 5: 3
Enter number 4 of 5: 9
Enter number 5 of 5: 2
Value 1 is 3
Value 2 is 6
Value 3 is 3
Value 4 is 9
Value 5 is 2
d) The following matrix represents the scores of 3 students (rows) in 5 tests
(columns).
34 45 43 89 34
89 56 98 34 55
67 87 45 43 95
Declare an array called marks to store the above scores. [3 Marks]
QUESTION THREE
a) What is a variable? [2 Mark]
b) What does scope refer to? [1 Mark]
c) State the reason why we should have a scope of variable. [2 Marks]
e) It is a good programming practice to write programs by dividing the problem in to
smaller named units. Explain the significance of the same. [3 Marks]
e) Write a program to read two whole numbers in to two variables of type float, and
then outputs both their sum and the difference when the first number is subtracted
form the second. [6 Marks]
g) Given the following problem description
Problem: Calculate and report the grade-point average for a class.
Discussion: The average grade equals the sum of all grades divided by the
number of students.
We need a loop to read and then add (accumulate) the grades for each student in
the class.
Inside the loop, we also need to total (count) the number of students in the class.
Input: Student grades
Processing: Find the sum of the grades; count the number of students; calculate
average grade
= sum of grades / number of students.
Output: Average grade
i. Write pseudocode for the above problem [3 Marks]
ii. Draw a flow chart for the problem [3 Marks]
QUESTION FOUR
a) Explain any THREE reasons for studying Programming languages [6 Marks]
b) List any TWO loop and TWO decision structures [4 Marks]
c) State three reasons why C is a good programming language [6 Marks]
d) State and explain the difference between TWO types of constants [4 Marks]
QUESTION FIVE
a) What is a recursive function? [2 Marks]
b) How is function recursion different from looping? [2 Marks]
c) Here is a recursive function. Write an iterative version of it. Hint: Be sure you get
the number of copies of “Hip” right. [6 Marks]
void rec_cheers(int n)
{
if(1==n)
printf(“Hurray!\n”);
else
{
printf(“Hip, “);
rec_cheers(n-1);
}
}
d) Explain between call-by- value and call-by-reference mechanisms. [3 Marks]
e) Write a function definition that takes two arguments, all int and returns the
average of the two arguments. [4 Marks]
f) Explain any three reasons why it’s good to use functions while programming
[3 Marks]

(Visited 59 times, 1 visits today)
Share this: