BIT 1303A PROGRAMMING METHODOLOGY KCA Past Paper

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

QUESTION ONE
a) Preprocessor are commands that are executed before any other statement in your
program. Describe any two such preprocessors command used in C programming
(4 Marks)
b) What will be the output of the following program?
#include <stdio.h>
int *p, x;
int a[5]={100,200,300,400,500};
int *p2;
int main()
{
p=NULL;
x=500;
p=&x;
printf(“1) %d %d \n”,x,*p,p,&x,&p);
p2=a;
*(p2+1)=*p;
*p= *p2 + *(p2+2);
printf(“2) %d %d \n”,x,*p,*p2);
// p4=&y; error to change the value of p4 as it is a
constant pointer
// array is a constant pointer too
return 0;
}
(3 Marks)
c) Rewrite Write a C Program that declares 3 arrays of size 4 by 3 and type integer.
Your program should read the values of the first two arrays, add the two arrays values
and store the results in a third array. Declare function to read the array values, use the
function twice. Declare another function to add two arrays and store the result in a
third one. (3 Marks)
d) Write a C function that computes that total sum of a 2D array of size 6 by 5.
(4 Marks)
e) Determine the value of the following expressions.
i) toupper(‘b’)
ii) tolower(‘C’);
iii) pow(3.0,3.0);
iv) sqrt(81.0);
v) fabs(-1.23);
vi) floor(22.46);
vii)ceil(33.3);
(8 Marks)
f) Using the functions in the math library, write the following mathematical formulas as
C expressions.
i) 3.02.4
ii) (x – y)1/2 Note: the ½ power is the square root
iii) |y – 42.3|
iv) ( -b + (b2
– 4ac)1/2) / 2a (8 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) Create a structure person with members’ id, age, height and weight. Write a
program that shows how this structure is implemented in main. In main, the
programs also compute the Body Mass Index (BMI) given as weight (kg)/height2
(m2
). The data is input by the user through program prompting and re-echo the
same on the screen in an appropriate format. (11 Marks)
d) Give FOUR characteristics of object oriented programming languages
(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)
c) Write a program that displays an invoice of several items. It should contain the
item name, quantity, price, and total cost on each line for the quantity and item
cost. It also contains functions to get and set item name, quantity, and price.
Stucture objects are created in main and invoices printed.
(8 Marks)
QUESTION FOUR
a) Write a program that calculates and displays the weekly salary for an employee who
earns $25 an hour, works 40 regular hours, 13 overtime hours, and earns time and
one-half (wage * 1.5) for overtime hours worked. Create a separate function to do the
calculation and return the result to be displayed. Your program contain a structure
that holds the employee details indicated as well as separate functions to do the
computation
(8 Marks)
b) Define the following
i). function
ii). Function overloading
iii). Inline functions (6 Marks)
c) Differentiate between the following as applied to programming
i). Science and Technology
ii). Identifiers and keywords
iii). Variable and constant
(6 Marks)
QUESTION FIVE
a) Define the following giving example with regard to programming
i). Operator
ii). Operand
iii). Add assignment
iv). Ternary operator
v). Programming
vi). Function call
(12 Marks)
b) Describe three types of constants in C programming
(3 Marks)
c) Describe 3 feature of C programming
(3 Marks)
d) List 2 methods that are used for modular programming. (2 Marks)

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

Written by