lOMoARcPSD|60583662
BIT 1102 Introduction TO Programming AND Algorithms
REG. SUPP
Introduction to programming languague (Mount Kenya University)
Scan to open on Studocu
Studocu is not sponsored or endorsed by any college or university
Downloaded by Mwangi Jeffrey (mwangijeffrey24@[Link])
lOMoARcPSD|60583662
UNIVERSITY EXAMINATION 2013/2014
SCHOOL OF PURE AND APPLIED SCIENCES
DEPARTMENT OF INFORMATION TECHNOLOGY
BACHELOR OF INFORMATION TECHNOLOGY AND BACHELOR OF BUSINESS INFORMATION
TECHNOLOGY
REGULAR
UNIT CODE: BIT1102 UNIT TITLE: INTRODUCTION TO
PROGRAMMING
DATE: AUGUST 2014 SPECIAL/SUPPLEMENTARY TIME: 2 HOURS
INSTRUCTIONS:
Answer question one and any other two questions.
QUESTION ONE (30 MARKS)
a) Explain one advantage of compiling a program rather than interpreting it.
(2 Marks)
b)
i. What is a keyword as used in programming?
(1 Mark)
ii. State four examples of keywords in C programming language.
(2 Marks)
c) Given the following C program:
Downloaded by Mwangi Jeffrey (mwangijeffrey24@[Link])
lOMoARcPSD|60583662
#include<stdio.h>
#define SIZE 22; main()
{
int index=1;
while(index=SIZE)
{
printf(“I like C \n”,index++);
}
return 0;
}
Rewrite the same program using for loop.
(3 Marks)
d) Discuss the unary operator with a sample C program.
(4 Marks)
e) Explain steps used to execute a
C program.
(4 Marks)
f) Identify errors in the program shown below and rewrite the same programwithout the errors.
(4 Marks)
main()
{
int i;
printf(“enter a number”)
scanf ” “,&i); if(i<=50)
printf(“\n entered number is <50)
g) Explain two characteristics of each of the following categories of programminglanguages:
(4 Marks)
i. Low level languages;
ii. High level languages.
h) Explain three advantages of using functions in programming.
(6 Marks)
QUESTION TWO (20 MARKS)
a) Explain the use of continue and break statements with in programming.(2 Marks)
Downloaded by Mwangi Jeffrey (mwangijeffrey24@[Link])
lOMoARcPSD|60583662
b) Briefly explain the purpose of each of the following programming elements:
(2 Marks)
i. Comments; ii.
Variables.
c) Draw a program flow chart to represent a program that would calculate the rootof quadratic
equations of the form ax2 + bx +c =0. The roots of such quadratic equation are given by the equation:
(4 Marks)
d) Write a C program to find sum, average of any three numbers which are enteredby the user through
the key board.
(4 Marks)
e) An electric power distribution company charges its domestic consumers asfollows:
Consumption units rate of charge
(Kshs)
0-200 0.50 per unit
201 -400 100 per unit
401 – 600 230 per unit
601 and above 390 per unit
Write a C program that reads customer number and power consumed and prints out the amount to be
paid by the customer.
(8 Marks)
QUESTION THREE (20 MARKS)
a) Define the following terms as used
in programming:
(2 Marks)
i. An identifier
ii. Variable scope
b) Describe the following types of programming errors. For each, identify one possible cause:
Downloaded by Mwangi Jeffrey (mwangijeffrey24@[Link])
lOMoARcPSD|60583662
(4 Marks)
i. Syntax
ii. Semantic
c) Write a program that calculates and displays the result of the volume of a cylinder. The variables
must be input on runtime.
(6 Marks)
d) A bicycle shop hires out bicycles at different rates per day for the different seasons of years, as
illustrated in the following table:
Season Charge per day(Kshs)
Spring 150
Summer 225
Autumn 125
Winter 95
Upon hiring a bicycle, the client is required to pay a deposit of 40% of the total hire cost before taking
the bicycle.
You are required to design a pseudocode that will input the season and the number of days, computes
the hire charge and the deposit, and print out results.
(8 Marks)
QUESTION FOUR (20 MARKS)
a) Distinguish between the following terms as used in C:
(4 Marks)
i. The use of ( ) and { } brackets
ii. Source code and object code
b) Explain the term algorithm and give two properties of a good algorithm. (3 Marks)
c) What is a data type? Explain three basic data types in C.
(4 Marks)
d) Rehema Ltd requires a program to compute Income tax and Net Salary for its employees. The company
offers tax relief of Kshs. 650 for single employees and Kshs. 1,100 for married employees. The relief will be
deducted from the Gross salary, to give the taxable income. This will be computed at the following rates:
Taxable Income Rate (%)
<5000 0
5000-19999 6
Downloaded by Mwangi Jeffrey (mwangijeffrey24@[Link])
lOMoARcPSD|60583662
20000-36999 9
37000 and above 16
The tax charged is then deducted from the Taxable income to give the Net salary.
Design a program flowchart for a program that will input the employee name, number, marital
status and gross income. The program will compute the tax and net salary, and then print out
the employee pay slip.
(9 Marks)
QUESTION FIVE (20 MARKS)
a) Write a C program to create an integer with the following four elements: 4, 6,
32, and 19. The array should display the results.
(4 Marks)
b) Briefly describe activities undertaken in program development process.(10 Marks)
ii) State reasons why one would use an unsized array in C
(2 Marks)
a) i) Algorithms fall under two broad categories. Briefly discuss these categories. (4 Marks)
QUESTION FIVE (20 MARKS)]
a) What is an array?
(2 Marks)
b) State the function of each of the following special character sequences used in C
i) \n (2 Marks) ii)%.2f (2 Marks) iii) && (2 Marks)
c) A retail shop offers discounts on its merchandise to its customers as indicated inthe table below;
Purchase amount Discount (%)
>10,000 10
Downloaded by Mwangi Jeffrey (mwangijeffrey24@[Link])
lOMoARcPSD|60583662
< = 10,000 and > 5
7,000 3
< = 7,000 and >
5,000 0
<= 5,000
i) Write an appropriate algorithm to represent this problem (3
Marks) ii. Write a program to calculate and display the amount payable by a customer. (5 Marks)
d) Explain the output of the following
C program.
(4 Marks)
#include<stdio.h> main()
{ int a=6, b=10; printf(“a=
%d\n,a++);
printf(“b=%d\n,++b);
}
Downloaded by Mwangi Jeffrey (mwangijeffrey24@[Link])