INFORMATION TECHNOLOGY / BACHELOR OF BUSINESS INFORMATION TECHNOLOGY
BIT 1201/BBIT 113: STRUCTURED PROGRAMMING/INTRODUCTION TO PROGRAMMING & ALGORITHM
DATE: DECEMBER 2017 TIMES: 2 HOURS
INSTRUCTIONS: Answer QUESTION ONE and ANY OTHER TWO.
QUESTION ONE (30 MARKS)
- Distinguish between the following terms as used in structured programming;
(6 Marks)
- Preprocessor directives
- Header files
- Escape sequences
- Comments
- Write a C program that would output the statements below as they are (4Marks)
- Hello World
- Welcome to Structured Programming
- I will be your Instructor
- Give a justification why c is a structured programming language (4 Marks)
- Mention and briefly discuss the basic C data types (8 Marks)
- A program error can either be syntax, logic or semantic. Classify the errors below
(3 Marks)
- An indefinite loop
- Misspelling keywords
- Division by zero error
- Using 9.81 as the value for the gravitational constant g , demonstrate how you create symbolic constants (2 Marks)
- Provide a C statements to declare an int array and initialize its’ elements to 10 , 20 , 30, 40 and 50 respectively (3 Marks)
QUESTION TWO (20 MARKS)
- Debug the program sample below (4 Marks)
# include (stdio.h)
main{} / Program execution begins here /
(
float things[3],i;
print (“How many things are there?/n);
scanf (“%d”, things);
for(i=0;i<3;i+)
things[5] = i;
print (“These are the things %f %f %f “,);
)
- Write a program that prompts for circle diameter, then calculates and outputs both circle radius and area (4 Marks)
- The simple interest, si earned on investing a principal amount p, at an annual percentage rate r of 5% for a number of years, y is given as:
si = princ * r* y
- Write a program that requires the user to enter the principal amount, rate and number of years, then calculates and displays the interest on the screen in the form:
The interest earned in (duration) years is Ksh. (si) (4 Marks)
- Modify your program so that it starts by asking the user to input their first name. After the calculations, the output should now be of the form;
(Firstname), the interest earned in (duration) years is Ksh. (si) (2 Marks)
- Create a program that prompts the user to enter two values separately (Val1, Val2), gets their sum (sum) then displays the output in the format;
- The Sum is Sum (3 Marks)
- Val 1 + Val 2 = Sum (3 Marks)
QUESTION THREE (20 MARKS)
- Which of the following variable names are good, which are bad, and which are invalid? In each case justify (7 Marks)
- your answer
- Age
- !ex
- R79J
- First Name
- char
- TotalIncome
- __Invalid
- Why is the function main() special in a c program? (2 Marks)
- Discuss the two methods of including comments in your C program (2 Marks)
- Define the term operator precedence (2 Marks)
- Determine the result of the expression below
b = 3.0/2 + 5*4.0/2.0 (4 Marks)
- Distinguish between the ‘If ’ and the ‘If ……Else’ (3 Marks)
QUESTION FOUR(20 MARKS)
- Distinguish between: (8 Marks)
- Global variable and Local variable
- Float variables and double variables
- Source code and Object code
- Compiling and Linking
- With respect to function parameter passing, what is the difference between call-by-value and call-by-reference? (4 Marks)
- Determine the output of the following programs:
- #include<stdio.h>
main()
{
int i=4,j,num=10;
j=i%3;
j=(j<i?0:num*num);
printf(“j=%d”,j);
} (2 Marks)
- #include<stdio.h>
main()
{
int count = 10,X,*int_pointer;
int_pointer = &count;
X = *int_pointer;
Printf(“ count = %d , X= %d\n”,count,X)
} (2 Marks)
- #include<stdio.h>
void main()
{
int x ,y , z, i= 0;
x=1;
y = 10;
while(i<3)
{
x+=1;
y-=2;
z +=x+y;
i++;
printf(“X = %d,Y=%d, x, y);
}
printf(“Z=%d”,z);
} (4 Marks)