Introduction to Algorithm and Programming (CSCT2105)

Computer Science - COS

Semester: First Semester

Level: 200

Year: 2014

Page 1
SCHOOL: H.T.T.T.C DEPARTEMENT: CS LECTURER(S): Dr. DADA Jean-Pierre
COURSE CODE: CSC122 COURSE TITLE: Digital electronics and logic circuits OPTION: FCS100
DATE: July ….. 2016 HALL: ………… TIME: 2:00 NATURE: Exam
Instructions:…… Answer all questions…………..
Exercise 1 (20 marks): A company in charge of water resource in a village wants to build a water
tower. The figure is shown below:
To calculate the volume of water the tower should contain, one suggests the formula:
, where V is the volume of water inside the water tower;
and
are respectively
the radius of circles, H is the height of the water tower (see figure above).
In a village without any calculator, you can use your laptop to calculate the volume of the
water tower. The values of H,
and
are inserted when the program is running.
a) Write an algorithm for this problem (4 marks).
b) Write an appropriate program using C language to solve this problem (10 marks).
c) Display results on the screen as the program is running (You should limit the number of decimals to
be used to display on the screen the results. For simulations, use these values: ;
;
H=1m and
) (6 marks).
Exercise 3 (10 marks): The following program can calculate the surface of a rectangle. The length
and width are assigned when the program is running.
#include <stdio.h>
/* This program calculates the surface of a rectangle */
int main()
{
floatlength,width,surface;
printf("########################################\n");
printf("##### Enter the lenght of your rectangle ######\n");
scanf("%f",&length);
printf("########################################\n");
printf("##### Enter the width of your rectangle ######\n");
REPUBLIC OF CAMEROON
Peace Work Fatherland
***********
THE UNIVERSITY OF BAMENDA
***********
HIGHER TECHNICAL TEACHER TRAINING
COLLEGE (H.T.T.T.C.) BAMBILI
***********
DIRECTORATE OF STUDIES
**********
P.O.BOX 39 BAMBILI
REPUBLIQUE DU CAMEROON
Paix Travail - Patrie
***********
UNIVERSITE DE BAMENDA
***********
ECOLE NORMALE SUPERIEURE D’ENSEIGNEMENT
TECHNIQUE
***********
DIRECTION DES ETUDES
**********
Tél: 33 05 10 69
www.schoolfaqs.net
Page 2
scanf("%f",&width);
printf("########################################\n");
surface=length*width;
printf("The length is:%0.2f\n",length);
printf("The width is:%0.2f\n",width);
printf("His surface is:%0.2f\n",surface);
return 0;
}
Simulate this program with two values: 2.5 and 3.5. Represent the screen as the program is running
(10 marks).
Exercise 4 (20 marks): The program below has at least 10 errors. Rewrite it and correct those errors
on this program
#include <stdio.h>
/* This program calculates the sum of two numbers
int main()
{
floatA,B;C;
printf("########################################\n")
printf("##### Enter on number ######\n");
scanf("%f",A);
printf("########################################\n");
printf("##### Enter another number ######\n")
scanf("%f",&B)
printf("########################################\n");
C=A+b;
printf("A=s:%0.2f\n",A)
printf("B=:%0.2f\n",B);
printf("His sum is:%0.2f,c);
return 0;
Exercise 5 (20 marks): This is the result of a program:
1) Write the program related to this figure (10 marks)
2) As this program is written using C software, what command can we use to compile the program?
(4 marks)
3) What does the computer when compiling a program? (4 marks)
4) As the compiled program is running what can you do to capture (print-screen) the result as shown
below? (2 marks)
www.schoolfaqs.net