You are on page 1of 2

DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY

SCHOOL OF ENGINEERING
DEPARTMENT OF CIVIL ENGINEERING

CCS 1203 INTRODUCTION TO COMPUTER PROGRAMMING


CONTINUOUS ASSESSMENT TEST
Date: Dec 2021 Time: 1Hr 45 Minutes
Instructions: attempt all questions
Question 1 (10 Marks):
a) Explain the following terms as used in Computer programming [1 mark]
i. Integrated Development Environment
ii. Software product
b) Differentiate between an interpreter and a compiler [2 marks]
c) Describe two ways of representing algorithms [2 marks]
d) Write a program that reads the radius of circle, calculates and displays its area.
[5 marks]
Question 2 (10 Marks):
a) Differentiate between key words and reserved words [2 marks]
b) State the purpose of each of the escape sequence characters shown below: [2 marks]
i. \a
ii. \t
iii. \n
iv. \r
c) Outline the errors in the program below. [6 marks]
#include <<stdio.h>>
int main ()
{
integer my_age;
Printf(“Enter your age\t”)
Scanf(“%d”, &age);
printf(“my age”, &my_age);
return 0;
}
Question 3 (15 Marks):
a) Explain the following terms as used in C programming [3 marks]
i. Operands
ii. Delimiters
b) For each of the operators listed below, indicate its class, that is, whether its arithmetic,
relational or logical and explain its purpose [5 marks]
i. ++
ii. &&
iii. !
iv. ==
v. ^
c) Write a program that finds the roots of a quadratic equation of the form ax2+bx2+c=0.
The values a, b and c should be entered by the user. [7 marks]

-Assume that the discriminant, i.e., b2-4ac>0 and a>0


-Hint: Root1=-b+ (b2-4ac)
2a
Root2=-b- (b2-4ac)
2a
1
Question 4 (15 Marks):
a) List four decision making constructs [2 marks]
b) Rewrite the following C statement using if…..else [3 marks]
a>b? (x= =y? x=5: y=15):a=10;
c) Write a C program that reads the score and displays pass or fail based on the criteria
below. The program should also indicate “invalid input” if the score input by the user
is not valid. [4 marks]
Score is greater than or equal to 40 pass
Score is less than 40 fail

d) A humanoid robot requires an upgrade that will enable it to cross the road guided by
the traffic lights in much the same way humans do. Write a program in C which
would demonstrate this function. Assume input and output is from the keyboard and
to the screen respectively. The keyboard only allows input in lowercase. [6 marks]

Question 5 (15 Marks):

a) Indicate the most appropriate loop to use under each of the conditions stated below:
[2 marks]
i. When the number of iterations is not known
ii. When the number of iterations is known
b) Write a program that uses a while loop to print all odd numbers between 10 and 100
[4 marks]
c) Using nested for loops, write a C program that generates and displays the
multiplication table in the pattern shown below; [9 marks]
* 1 2 3 4
1 1 2 3 4
2 2 4 6 8
3 3 6 9 12
4 4 8 12 16

You might also like