DIT 305  PROGRAMMING METHODOLOGY.

UNIVERSITY EXAMINATIONS: 2015/2016
EXAMINATION FOR THE DIPLOMA IN BUSINESS INFORMATION
TECHNOLOGY
DIT 305 PROGRAMMING METHODOLOGY
DATE: AUGUST 2016 TIME: 1½HOURS
INSTRUCTIONS: Answer Any THREE Questions.

QUESTION ONE
a) Explain the following components of a C program and give an example in each case.
[10 Marks]
i) Pre-processor directive
ii) Declaration
iii) Assignment
iv) Statement
v) Function
b) i) Discuss three categories of program errors, stating what causes them. [3 Marks]
ii) Indicate which error category each of the following belongs to
i) An indefinite loop
ii) Misspelling keywords
iii) Division by zero error
iv) Using an undeclared variable [4 Marks]
c) Explain how dry running is useful in ensuring error free programs during program testing.
[3 Marks]
QUESTION TWO
(a) Consider the following declarations and assignments:
int num1=3, num2=2;
float f1=2.4, f2=1.2;
State the type and value of the following expressions. Give a reasons for your answer.
i.) num1/num2
ii.) f1/f2
iii.) f1/num1 [6 Marks]
(b) Given the following examples:
A = B and A = = B
Explain the difference between the two operators (= and = =) [4 Marks]
(c) State TWO reasons for using comments in a program. [2 Marks]
(d) Write a C program that calls a function that calculates the area of a given circle.
Area = PI*R*R [8 Marks]
QUESTION THREE
(a) Rewrite the following code segment using a while statement
int a;
int b=10;
for(a=1; a<b; a++)
{
printf(“%d\n “, a/b);
} [4 Marks]
(b) Explain the effect of the following line of code, stating where you would you would
expect it to appear in a program.
#define PI 3.14158 [4 Marks]
(c) Outline THREE reasons why it is important for a programmer to adopt to a well defined
program layout. [3 Marks]
(d) After a bank customer successfully enters his/her Personal Identification Number (PIN)
on an Automated Teller Machine (ATM), an integer-based menu (1-5) appears from which
the customer makes his/her transaction choice. The ATM screen displays a message
depending on the customer’s selection as follows:
Customer Choice Message
1 Proceed to withdraw
2 Change ATM PIN
3 Pay utility bills
4 Print mini statement
5 Exit System
Using the C switch statement, illustrate how the above can be implemented. [9 Marks]
QUESTION FOUR
(a) Write a C program that asks a user to enter his/her three names and then prints the names
on the screen. [10 Marks]
(b) Explain why C language is said to be case sensitive, stating one challenge posed by this
characteristic. [2 Marks]
(c) Write a single statement for each of the following: [8 Marks]
i. Declare an array for 10 books’ prices
ii. Test if age is above 20
iii. Print the word ” Methodology” below the word “Programming” by using a single
printf() statement
iv. Decrement a variable called step by 1
QUESTION FIVE
(a) Draw a flowchart for a program that works as follows:
i) Reads the selling price of an item
ii) Reads the buying price of the item
iii) If the selling price is less than or equal to the buying price, it prints the message
“No profit made”, Otherwise it calculates the profit. (Selling price – buying price)
iv) If the profit is more than Sh. 10,000, the commission for the salesman is
calculated as 3% of the profit, otherwise the commission is zero.
v) The program prints the profit and the commission.
[10 Marks]
(b) Write a C program to implement the flowchart designed in (a). [10 Marks]

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

Written by