Structured programming Free University Past papers

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)

  1. Distinguish between the following terms as used in structured programming;

(6 Marks)

  1. Preprocessor directives
  2. Header files
  • Escape sequences
  1. Comments
  1. Write a C program that would output the statements below as they are              (4Marks)
    1. Hello World
    2. Welcome to Structured Programming
    3. I will be your Instructor
  2. Give a justification why c is a structured programming language (4 Marks)
  3. Mention and briefly discuss the basic C data types                 (8 Marks)
  4. A program error can either be syntax, logic or semantic. Classify the errors below

(3 Marks)

  1. An indefinite loop
  2. Misspelling keywords
  • Division by zero error
  1. Using 9.81 as the value for the gravitational constant g , demonstrate how you create symbolic constants                                                                       (2 Marks)
  2. 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)

  1. 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 “,);

)

  1. Write a program that prompts for circle diameter, then calculates and outputs both circle radius and area                                                                  (4 Marks)
  2. 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

  1.  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)

  1. 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)

  1. 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;
    1. The Sum is Sum (3 Marks)
    2. Val 1 + Val 2 = Sum (3 Marks)

QUESTION THREE (20 MARKS) 

  1. Which of the following variable names are good, which are bad, and which are invalid? In each case justify                                                                        (7 Marks)
    1. your answer
    2. Age
  • !ex
  1. R79J
  2. First Name
  3. char
  • TotalIncome
  • __Invalid
  1. Why is the function main() special in a c program?                   (2 Marks)
  2. Discuss the two methods of including comments in your C program (2 Marks)
  3. Define the term operator precedence                                                 (2 Marks)
  4. Determine the result of the expression below

b = 3.0/2 + 5*4.0/2.0                                                                            (4 Marks)

  1. Distinguish between the ‘If ’ and the ‘If ……Else’                                                 (3 Marks)

 

QUESTION FOUR(20 MARKS)

  1. Distinguish between: (8 Marks)
    1. Global variable and Local variable
    2. Float variables and double variables
  • Source code and Object code
  1. Compiling and Linking
  1. With respect to function parameter passing, what is the difference between call-by-value and call-by-reference?                                                                         (4 Marks)
  2. Determine the output of the following programs:
  3. #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)

  1. #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)

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