0% found this document useful (0 votes)
5 views

questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Candidate Reg Number

THE UNIVERSITY OF DODOMA


OFFICE OF THE DEPUTY VICE CHANCELLOR
ACADEMIC, RESEARCH AND CONSULTANCY

COLLEGE OF INFORMATICS AND VIRTUAL


EDUCATION
Department of Computer Science and Engineering
End of Semester II University Examination for the 2020/2021
Academic Year

Course Name: Principles of Computer Programming

Paper Code Number: CP 111

Date of Examination :<___________>

Time: <____________>

Duration: <____________>

Venue(s): < ____________>

Sitting Programme(s): BSc. Chem1

1
INSTRUCTIONS TO CANDIDATES
i. This examination paper consists of TWO (2) sections with
SEVEN (7) questions in FOURTEEN (14) printed pages.
ii. Answer all questions in Sections A and THREE (3) questions in
Section B.
iii. The total score for this examination is 60 points. Marks are
allocated at the end of each question.
iv. ALL responses should be written in the answer book provided.
Insert the examination paper into the answer book after the
examination. Students should not take any examination paper(s)
out of the examination room.
v. All regulations guiding the administration of university
examinations apply.

2
SECTION A: (15 MARKS)
1. Read each question carefully and choose the most correct response.
(0.5 Marks Each)
i. If a repetition has to be done until user enters “stop”. What is
the best flow of control to implement this loop?

A. for statement
B. if statement
C. if-else statement
D. while statement
E. switch case statement
ii. If option = true; then what is the proper preparation of variable
option?
A. bol option;
B. bull option;
C. bool option;
D. bul option;
E. boolean option;
iii. If x = 0.75; is a correct assignment statement, then x is:
A. an integer variable
B. a floating point variable
C. a string variable
D. a character variable
E. a boolean variable

3
iv. Which of the following is not among the main parts of iteration
control structure?
A. initialization
B. condition
C. body of loop
D. selection
E. update
v. If xy is a character variable, then which of these assignment
statement is syntactically and logically correct?
A. Store F into xy
B. Store male into xy
C. Store 0.75 into xy
D. Store 10 into xy
E. Store false into xy
vi. For the statement if(pq<10 and pq>=0) to be true, pq is a set of
the following integers
A. 10, 11, 12, 13, ...
B. 0, -1, -2, -3, ...
C. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
D. 1, 2, 3, 4, 5, 6, 7, 8, 9 , 10
E. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
vii. The loop statement should execute at least once. This loop is:
A. if statement

4
B. while loop
C. for loop
D. switch case statement
E. do while loop
viii. It is a multiple selection statement which whose condition can
be formed by characters or integers only. This is:
A. if statement
B. if-else statement
C. if-else-if statement
D. switch case statement
E. iff statement
ix. She wants to print her name ten times. What is the best and
simple flow of control to propose to this lady?
A. if-else statement
B. for loop statement
C. switch case statement
D. if statement
E. while loop statement
x. It combines the object files, generated by compiler/assembler,
and other pieces of codes to originate an executable file.
A. Compiler
B. Linker
C. Loader

5
D. Interpreter
E. Assembler

2. Match the item in Column A with its proper explanation in Column


B. (0.5 Marks Each)

Column A Column B
i. Keyword in programming A. Backspace.
ii. Special character in B. Tells the compiler or
programming interpreter how the
iii. switch programmer intends to use
iv. void the data.
v. Data type C. Translates one language to
vi. Interpreter another (e.g. Kiswahili to
vii. Condition statement Chinese).
viii. Assembler D. Translates assembly language
ix. Identifier; into machine code.
x. Compiler E. Transfers control to one of
the several statements,
depending on the value of a
condition.
F. Mathematical operators.
G. Translates the whole program
into machine code before the
program is run.
H. continue at the end of line
I. Words with special meaning
to the compiler.
J. No values and no operations.
K. Evaluated into either false or
true.
L. Translates source code into

6
machine code instruction by
instruction.
M. Pass by pointer.
N. Declare a local variable
O. Label or name assigned to an
element in a program.

3. Answer the following questions:

a. State any four (4) rules of naming a valid identifier. (2 Marks)


b. Draw a well labelled diagram to illustrate the steps of running a C+
+ program. (3 Marks)

SECTION B: (45 MARKS)


Attempt THREE (3) out of FOUR (4) questions provided.
4.

a. What will be printed on the screen? (2 Marks Each)


i.
Start
Prepare variables firstname, surname,
gender, myage, f_age, d_age.
Capture and store your firstname into
firstname
Input your surname into surname
Record your gender into gender
Record your age into myage
Record your father’s age into f_age
d_age = f_age – myage
Print firstname, myage, f_age, d_age
End

7
ii.
Start
Prepare variable num
Initialize variable sum with zero (0)
for i from 1 to 10
num = i + 1
sum = sum + num
update i by 1
end of for
print sum
End

iii.
Start
Prepare variables myname, myage,
yourname, yourage
Capture and store your first name
into myname
Capture and store your friend’s name
into yourname
myage = 20
yourage = 19
if(myage < yourage)
display message “Oooh! Yes!”
display myage
else if (myage > yourage)
display message “Oooh! No!”
print yourname
else
display message “Waaow!”
print myname, yourname
end if
End

8
b. Study the flowcharts below and respond to the related questions.
(3 Marks
Each)
i. What will be printed out?

Figure 1: Flow chart


ii. Given that
cond.1 is: marks>=0 AND marks<=40, cond.2 is: marks>=16,
cond.3 is: marks<0, statement A: print message “Passed!”,
statement B: print message “Carryover!”, statement C: print
message “No negative Marks!”, statement D: print message
“Above coursework limit!”, statement X: print message “This

9
is UDOM!”. Suppose that John scored a total marks of 28 in
CP 111, what will be the output?

Figure 2: Flowchart

10
iii.Re-draw the flowchart in Figure 1 by using do-while loop.
(3
Marks)
5. Analyse the following Pseudocode and the draw the corresponding
flowchart. (15 Marks)

Start
Print out appropriate heading and make it
pretty
While not EOF do:
Scan over blanks and white space
until a char is found
(get first character on the line)
set can't-be-ascending-flag to 0
set consec cntr to 1
set ascending cntr to 1
putchar first char of string to
screen
set read character to hold character
While next character read != blanks
and white space
putchar out on screen
if new char = hold char + 1

11
add 1 to consec cntr
set hold char = new char
continue
endif
if new char >= hold char
if consec cntr < 3
set consec cntr to 1
endif
set hold char = new char
continue
endif
if new char < hold char
if consec cntr < 3
set consec cntr to 1
endif
set hold char = new char
set can't be ascending
flag to 1
continue
endif
end while
if consec cntr >= 3
printf (Appropriate message 1
and skip a line)
add 1 to consec total
endif
if can't-be-ascending-flag = 0
printf (Appropriate message 2
and skip a line)
add 1 to ascending total
else
printf (Sorry message and skip
a line)
add 1 to sorry total
endif

12
end While
Print out totals: Number of consecs,
ascendings, and sorries.
Stop

6. Mr. Rutashubanyuma is class teacher at Ukombozi Secondary


school at Ulanga district. He is used to have monthly examination
on 28th of every month. In this digital era, he wants a simple
computer program that will be able to store permanently and
display the report of his students. In this report the student grade is
calculate by the school grading system with grade ranges as:
0 – 20 F
21 – 40 D
41 – 60 C
61 – 80 B
81 – 100 A
The program should be able to:
- Record the number of students in a class and number of
examinations to be done,
- Accept scores of all students and store them into array
named scoredmark.
- Calculate sum and average, and find the grade from average
marks.
- Store all scores, total scores, average score, and gpa into an
array named report.

13
- Export data from array report to a file name report.txt.
- Display a report with the following information: all scores,
total scores, average score, and gpa.

Analyse this scenario using:


a. DDIV chart (8 Marks)
b. IPO chart (7 Marks)

7. A standard I class teacher at Mugumu Primary School wants a


program to calculate the sum and average marks of a student for
the monthly exam. A student may sit for any number of exam,
since the school by-laws allows student to postpone any exam if
he/she is not healthy. The program will accept marks of all
subjects. Marks below 0 and above 100 will be rejected and an
error message “Invalid Marks” will be displayed on screen. The
program will continue to run until the user enters a Sentineal after
the last score. The program will then print the sum, average of
marks, and the grade of marks. For grading system consider the
ranges shown in question 6. Design this program by using:
a. Flowchart (8 Marks)
b. Pseudocode (7 Marks)

14
END OF EXAMINATION PAPER

15

You might also like