Attempt Question 1 (Compulsory - 30 Marks) and Any Other TWO Questions (15 Marks Each)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY

University Examination 2014/2015

STAGE II EXAMINATION FOR THE DIPLOMA IN INFORMATION


TECHNOLOGY

DIT 0202: INTRODUCTION TO PROGRAMMING AND ALGORITHMS

DATE: 22ND JULY 2014 TIME: 10.00AM-11.30AM

INSTRUCTIONS:

Attempt Question 1 (compulsory - 30 marks) and any other TWO Questions (15 marks each).

QUESTION ONE (30 Marks):

(a) Explain the meaning of the following terms as used in programming (6 marks)

(i) Source program

(ii) Object program

(iii) Function

(iv) Keyword

(v) Program

(vi) Programming language

(b) Outline three rules used in naming variables in C programming (3 marks)

(c) Discuss three main data types used in C programming (3 marks)

(d) Briefly explain any three characteristics of a good programming language (3 marks)
(e) Using examples, discuss three errors encountered in programming (4 marks)

(f) Tusaidiane Saving Society (TSS) pays 5% interest on shares exceeding sh.100, 000 and 3% on
shares that don’t meet this target. However, no interest is paid on deposits in the members’ TSS
bank account. Design a structured algorithm that would;

(i) Prompt the user for shares and deposits of a particular member. (2 marks)

Page 1 of 3
(ii) Calculate the interest and total savings for a particular member of the society (2 marks)

(iii) Draw a diagrammatic representation of the above (3 marks)

(g) Write a C program that allows the user to enter an integer number between 0 and 9. The integer
number is stored in a variable named n. Using the CASE statement identify the number entered. If
0, the program prints the message “you typed zero”, if 3, 5 or 7, the program prints the message
“n is prime number”, if 2, 4, 6 or 8, the program prints the message “n is an even number”, if 1 or
9, the program prints the message “n is a perfect square”, if none of the above, the program prints
the message "Only single-digit numbers are allowed”. (4 marks)

QUESTION TWO (15 mks):

(a) Explain the term flowchart (1 marks)

(b) Discuss any four symbols used in a flowchart (4 marks)

(c) In an Olympic event , medals are only awarded to the first three athletes as follows

Position1: Gold medal

Position2: Silver medal

Position3: Bronze medal

(i) Using the Nested If structure, write a pseudo code to demonstrate the above. (4 marks)

(ii) Convert the above pseudo code to a flowchart (3 marks)

(d) Write a C program that prompts the user to enter three numbers. The program should then check
the largest number among the three and then print the given numbers along with the largest
number. (3 marks)

QUESTION THREE (15 mks):

(a) Discuss any three advantages of C programming language (3 marks)

(b) Explain the term program control structure and discuss three main control structures (4 marks)

(c) With the aid of a pseudo code and a flowchart, design an algorithm that:

(i) Prompt the user to enter two numbers x and y (2 marks)

(ii) Divide x by y, however if the value of y =0, then the program should display an error
division by zero (3 marks)

(d) John’s basic salary is input through the keyboard. His medical allowance is 40% of basic salary
and house rent allowance is 20% of basic salary. Write a C program to calculate his gross
salary (3 marks)

Page 2 of 3
QUESTION FOUR (15 mks):

(a) Explain why computer programs written in assembly languages or machine languages are
generally more efficient than those written in high level languages (3 marks)

(b) Using program statements, illustrate two types of consonants (4 marks)

(c) The distance between two cities (in km) is input through the keyboard. Write a C program to
convert and print this distance in meters, feet, inches and centimeters. (3 marks)

(d) Differentiate between user\programmer defined functions and inbuilt functions (2 marks)

(e) Write a C program that finds whether a number entered by the user is negative or positive.

(3 marks)

QUESTION FIVE (15 mks):

(a) Briefly discuss any four advantages of modularity in programming (2 marks)

(b) Using examples in each case state, discuss the five classes of C operators (5 marks)

(c) Write a C program that calculates the absolute value of an integer entered by the user. Use the if
structure. (3 marks)

(d) A program is required to process and award students grades according to the following table
summary

MARKS GRADE

80-100 A

70-79 B

60-69 C

50-59 D

Below 50 E

(i) Write an algorithm that prompts the user to enter marks obtained by each student and then assign
and prints out the grade. Use the CASE structure (5 marks)

Page 3 of 3

You might also like