Escolar Documentos
Profissional Documentos
Cultura Documentos
and Computing
FACULTY:
Eugineertng
SCHOOL:
Computing &
Information
Technology
Module Name:
Programming
Module Code:
CMPI024
Date:
April,20l2
Theory/ Practical:
Theory
Groups:
Duration:
2 hours
INSTHUCTIONS
1. Answer all questions in Section [ and any two (2) from Section II of this test
a. Answer Sections I and )[ in the Answer Booklet provided
2. The total marks for each Section is stated in brackets at the start of that Section
3. All working must be clearly shown.
4. Silent electronic calculators may be used [Of this test.
5. This paper is marked out of a total of 75 ilt:t r ks.
no NOT
Page
1 of 4
t '
COMl'liLSOHY
QlmSTlONS
ITOTAL = 25 marks]
Justrncriuns:
1.
Answer
all questions
A) Using nested
Booklet
marks.
list cd below: -
for loops.write the pseudocode segment that will display the following:
~.
-J.:
**
B) A C program contains
the following
dcclarntious:
x,
y,
z:
EA.CH
accept user-input
that will:
increase mo by a quarter of
iii.
IV.
1110
rpcrlltqr
10 assign y to x if mo is positive;
but assign z to x if
II +1+ I +2f/1lJr~sJ
C) By tracing, show the state of each varialx., lX, Y IJfU( z) in every line for the following
pseudocode-segment
(NOTE: Each line affects the variable's value/or the next line) : l.
2.
3.
4.
5.
6.
DECLARE
LET Z ~
LET x ~
LET Y
LET z ~
LET x ,_.
x, y, Z AS WHOLE
24 / 5
Z
% ( Z + 3)
0 + x / 3 -t- z
x / y / z
(z - x) / 4
Z -I-
[5 l1I(lr{(s)
J)) It is suggested that you can tell someone's personality based on the first letter in their
first names. What follows is a table that have some of the first letters: -
",H
'N
Athletic
'E'
Elegant
'F'
Foxy
Others
Philosophical
[)esigl~th~-~-cgnle~;t ~f tr;efl;;W-ch"rt(Y;~~-d;~(~i71al'c
to write the ell/ire program
design) that will display a message indicating a PEl{SONALlTV
based on a
character value thai represents the FIRST LETTER of the FIRST NAME using:
i.
The LINEAR/SEQUENTIAL
IF design.
[6 !ll1I"k~'1
II.
The CASE design.
Page2of4
ESSAY ITEMS
ItOtAL
= 50 marks]
Sectiollll-
Ailswer ANY
lnstructlons:
2.
rwo
(2) questions.
--~~--------------------------------------
Bonklet
provided
for a total of
[C code Analysis]
Consider
the following
program solution
written in C.
ftinclude <stdio.h>
void main(void)
{
int year;
int popl;
const int curryear
= 2012;
printf
("Please enter the current
population:");
scanf
("%d", &popl);
printf
("YEAR
POPULATION\n=======================\n\n")
for (year = 5; year>
0; year -= 1)
printf
("%4d
popl += popl
%06d\n",
(curryear
- year),
popl);
% year;
by the
Iis marks]
that performs
r 10 1II(O'I<s]
3.
[Decision
"Employees
Tables]
at Greggs Ltd work a set number of hours related to the following:
workers work for 5 hours a day as long as their salaries are below $ 15,000.00.
work for 5 hours a clay. Anyone with salaries above $60,000.00
All female
All male workers
All
Any
of 7
and $60,000.00
(inclusive)
hours overtime."
A) Construct
a decision
above program's
table, simplifying
the conditions
and outcomes
to be used in the
design.
(22 matksl
within the
Justify the reason for the formula used for your answer.
1.1 Illm1'5]
I'age 301" 4
4.
[Pscudocoi\cl
NOTE; The company wants the program to calculate and output the 101;11
numhcr
of compatihle
matches
of records
to be processed.
gender, agc
and hcight.
,
errnr
message
The system must validate the age to make sure that it falls within the range ofln
to 60 (inclusivev. If the age is not valid then an ,lpprnprio,lc er'rnr mcssagc
be printed, assign 60 to the variable ami then continue
"
gender,
must
is compatihle
an appropriate
message
or incomputihle
Customers
are compatible
are within
l' (one foot) of each other; and their ages are the same.
HEQIJIHE));
Write the pseudocode
5.
corresponding
by SOM8.
[Fluwchart]
A) Design the flowchart
between
vnriubles
of
a variable
P 5 marks]
fill'
a system
that prompts
for a positive
and prints out the slim or all squares from I to (and including)
allY
(Declare
r 10 marks I
Page 4 of -l