BIT 1303A1304 PROGRAMMING METHODOLOGYa KCA Past Paper

UNIVERSITY EXAMINATIONS: 2014/2015
ORDINARY EXAMINATION FOR THE BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY
BIT 1303A1304 PROGRAMMING METHODOLOGY
DATE: APRIL, 2015 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE
a) Indicate whether the following are true or false. Give a reason for your answer
i) Any valid data type can be a member of a structure.
ii) When a structure of a particular type is actually allocated, C doesn’t
necessarily store the member definitions contiguously in the order that
they were defined.
iii) Given the C code segment below, answer questions that follow
struct employee_rec
{
char name[30];
int dependents;
float pay_rate;
} full_time, part_time;
iv) The above could also be accomplished using 2 separate statements.
v) The last semi-colon is optional.
vi) The brackets { } could be omitted from the above code segment, and the
definition would still be syntactically correct?
vii) Employee record could be omitted from the above code segment, and the
definition would still be syntactically correct?
viii) The names full-time and part-timer could be omitted from the above code
segment, and the definition would still be syntactically correct?
ix) As a result of the above code segment, no memory will be allocated for any
variables. (18 marks)
b) Study the program below and answer the question that follow
#include <stdio.h>
int fault ( int, int);
int main()
{
int x;
int y;

printf(“Please input two numbers integers: “;
scanf(“%d %d”,&x,&y);
printf(“The result of the two numbers is %d\n”, fault(x,y));
}
int fault ( int x, int y )
{
return x * y/(x-y);
}
i). Describe the sections in bold (4 marks)
ii). What is the output of the program if
a. X=2, y=1 (3 marks)
b. X=8, y=3 (1 marks)
c) Write the statements that will compute the square root of the double-precision
variable x if x is positive and print an error message if x is negative. (4 marks)
QUESTION TWO
a) Give the functional difference between if and switch control construct (2 marks)
b) Define what a pointer is and describe two operators associated with it operation
(3 marks)
c) Evaluate the following arithmetic expressions and indicate the value and the data type
of the result:
int x=4, y=5;
float q=2.0f;
double p=1.0, z=3.0;
i.) x + y
ii.) p * q / z
iii.) q + x / y % x
(6 marks)
d) Convert the switch statement into the corresponding if-else block:
switch (q) {
case 3:
p = q * 4; case 4:
p = q + 1; break;
default: p = q;
}
(5 marks)
e) Explain the difference between iteration and recursion.
(4 marks
QUESTION THREE
a) Predict the output of the following program
#include <stdio.h>
struct vector
{
double x;
double y;
}
double surface(struct vector v)
{
double s;
s = v.x * v.y;
if (s < 0) s = -s;
return s;
}
int main()
{
struct vector a;
a.x = 3;
a.y = 4;
printf(“The surface of a: %.2f\n”,surface(a));
return 0;
}
(4 marks)
b) Describe the following terms as used in structured programming
i). Static memory
ii). Dynamic memory
iii). Big O notation
iv). Pointer (8 marks)
a) Write a recursive function for computing the factorial of a number.
(8 marks)
QUESTION FOUR
a) Define the following
i). function
ii). Function overloading
iii). Inline functions (6 marks)
b) Differentiate between the following as applied to programming
i). Science and Technology
ii). Identifiers and keywords
iii). Variable and constant (6 marks)
c) Write a C program that computes and prints the squares of integers from 1 to 10.
(4 marks)
d) Write a C program that simulates 100 coin tosses and prints the frequencies of the
“heads” and “tails”. (4 marks)
QUESTION FIVE
a) Describe three types of constants in C programming (3 marks)
b) Describe 3 feature of C programming. (3 marks)
c) List 2 methods that are used for modular programming (2 marks)
d) Using reference variables as arguments, write a C function that swaps two variables
of type int. (6 marks)
e) Using pointers as arguments, write a C function that swaps two variables of type int.
(6 marks)

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

Written by