questions
questions
Time: <____________>
Duration: <____________>
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
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.
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?
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
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.
14
END OF EXAMINATION PAPER
15