You are on page 1of 11

U

S1TI
TEKNOLOG I
PEI''.

NI.
ni/iNYw'wi. vMl'WUMwMFYMw'n'nXA.

'MYXYwn; M

IrMNwY1NN'Iwww.

1Y/IMy7,

MII

COURSE

TB81073 STRUCTURED PROGRAMMING


AND DATABASE / TABIOI3 STRUCTURED
PROGRAMMING

DATE

24 NOVEMBER 2010 (WEDNESDAY)

TIME

2.30 PM - 5.30 PM (3 HOURS)

INSTRUCTIONS TO CANDIDATES
from the Questions Booklet,
Answer ALL rMuestlons
Begin EACH answer on a new page n the Answer Booklet
lrcateclearly answers that are cancelSecifany.

Where applicable, show clearly steps taken n arrvng at the solutions and
indicate ALL assumptions.
A

Note

Do not open this Question Booklet until instructed.


T

are

the
(11) pages w
this Question Book'et iidg

r page

i.
,

I.,
.,

t :.

'r'

:k. "l"9():

1
L()g ..

1073/TAB 1013

I.

A senior manager at StoneWatcber wants to develop i&on support


b'end
ingredients
based
have
the
to
to
petrol
ability
on client's
system
R0N95
There
two
types
are
of clients' requests which are
and
request
R0N97. To make product such as R0N95 two "ingredients must be blended
TABLE
in
QI Only I 50 litres is used for each ingrethent to
together as shown
.
be blended and each ingredient initial vafue is 2000 litres.

3.

Draw

flow chart to show the decision that can be made from TABLE

QI based on current stavailable n TABLE Q2 if the client request


for R0N95.
TABLE QI
_

RON

A+B
AAB+C
A+BC
.
......
....
.
.
.
..
.
A+B+D
A+B+D

.
....
.
.
_.
wA+D
'A+D
C+CI
C+D

B+D
B+D

... .,. .. ..... ,...


R01195
..

..w..W.
w...,.,. ...

R0N97
R0N97
R0N95
R0N95

R0N95

.. .

TABLE Q2

[8 marks]
b.

Write a complete C++ program based on the foilowings.


Dspay quantities tor R0N95 that cart be produced based on
e
"RON.
txt"
Q2
text
TABLE
n
as
current stock as
and use a
input and
Print warning message it each ingredient in the stock is tess
initial
than or equa' 30'%
and
values,
of

Display the output as shown

Qt

I 073/TAB i013

tu*Pent

stock

S$I
BON9S

it
is

s
critical

195 Quar
2. S D
is critical

it
0N95 Quant it ics
any

to

for

A+ are 4 Units

for

for

B*

are

3 Units

are
are

3 Urits
3 tIn its

nue

FIGURE QI

[12 marks]

T073iTA8 1013

in a robotic competition,you are required to determine the speed of a


buttons
based
the
as
colour of the controHer
robot movement
on
f'h/'flowsw

Green increase the current speed by 2

- decrease the current speed by 2 if the current speed is


not zero
Red - stop the robot

i.

a complete flowchart to solve the prob'em.


[5 masks]

ii.

Write a C++ coce using if.. else statement.


M
[5 marks]

wiii

Rewrite + code in part (ii) using switch statement.


[5 marks]

b.

Trace and write the output for the C++ program n FIGUREQ2. Show
hand
the
trace
all
steps.

TBB 1073/TAB 1013

#include

<ic strearn>
pacE'

std;

.
naill

using

i. nt : ma in t' :
t
:

start

t
.

iopVar1.

fcar

lopvar2

lva r3;

4
r
"
--

space

char

3;
.
.,,,

end
,

( iri ., " start

loopy 'a1.

<.

end,

ioopVari

+)

for
oo"

a
i '
,
,
aaM"'.
"''

_.
",
end
rl
;
r
.
opV,
ar2+
-
,
,
.
,.
. C,,,

cout

space;

I
..

''1..,
x'.
. y'
""a

for

ti

(:LooVx3

couT+'

start;
..

Loopvar:

i <= iVarix. IooVr3"-


)

y`.
MJIrFJiM
ii..

'

FIGURE Q2

[5 marks)

TBBI 073/iABiO13

a.

ia
r

mt

number[}

{2,8,11,
=

,)I

the owng
The dec'ared size of the array.
(1 marlcj
w
r

The range of values an index accessing this array irr

have.
[1 mark]

bY

Trace and write the output of the following C++ code fragment:
int,

for

j,

i,

Y.

_,.

'emp[8J

5";

>':..


<

i--)
:

0;
[i]

6;

""

for

(i

0;

6;
""w,

or(j

rout

if2)

.i

riurn . push,,.
r

3*1.

temp [ 1] );

0,
j<.

'
ms: x,zeQ;
.
terrr [i]

cout

i;
e,nd.

.,

j<
+ rnf:

[5 marks)
ck

if
is
the
integer
7
function that accepts an array of
vaiue
values.
function
This
it
be
to
shou'd return
a prime number, will
added a vector.
of prime numbers.
t3 marks]

In the Eureka engineeringproject competitionorganized by UTP, seven


judges award a score between 0 and 10, where each score may be a
floatingpoMntvaluewThe highest and the owest are thrown out and the
The
is
by
the
then
together
mutphed
remaining scores are added
sum
degree of difficulty for that project. The degree of difficu'ty ranges from

TBB1O73ITAB1 013

to 5.5 points. The total is then muItMplied by O6 to determine


w0

project's score.
Write a C++ program that retrieves inputs from seven judges, score and
The
degree
difficulty.
the
is
for
the
of
output
of
a
program
overa$ score
a project.
[10 marks)

4.

O13

a.

State ONE (1) reason why Functions are used in computer programs.
[2 marks]

h.

Exp4ainthe following function pre declaration.


onabc(vogd)
void
[2 marks]
ii

float Function_c Qntb, float h)


[2 marks]

03)
(mt
unctionabc
costfi

iL

[2 marks]
What is the difference between g)obal var and 1
vare?

c.

[2 marksj
Ana'yze the C++ code segment in Q4a to determine
Var2
Van
final
the
and
respectiveIy ,
value of

IL

0,

(void)
void gtal_Icaca1

{
ar2=

1;

G(obaIrVarabe "' Van,

cout

LocaN'

r2

Var1+1n

Var2+2,;
t

maEn()

It

iy

lor(i=O;

" ++)

g1();

geth;
return 0;

FIGURE Q4a
8

IB1 073/iAB'1I OI 3

[3 marks]

You are required to write ++ program to


from
integers
three
user,
accept

display
integers,
the
these
average
and
of
ate
function
aargest
integer
determine
the
to
caHa
accepted,

find the difference between the largest integer and the


dIspIay
then
the
caIculated,
and
average
'difference on

screen.
You may use the function n FIGURE Q4b n your programw

float duff;
N = nlw

if (n2

> maxN)

= ri2;
if (n3 > maxN)

ii3;

ff (float) rnaxN avg;


dff,
return

FIGURE

4b

[7 marks]

TBBI 073/TAB1013

5.

Give an example for each of following re(ationships.


I.

Many-to-One

[1 markj
ii.

One-toOne
[1 mark

idL

OnetoMany

[1 mark]
iv.

y4oMany
[1 mark]

b.

Give SQL statement which STUDENT table consisting of


foiaowing fieldsM
L
ii
iii,

Name
Class
Marks
Rank

CHAR(40)
CHAR(6)
NUMBER(4)
CHAR(8)
[4 macs]

c.

You are required to create a conceptual data mod& for Computer


Information System department in Unlversitl Tekn+logi Petrorias that
specializes

in IT project consultatlonw

The department has 40

technologlst
handle
of
consultants comprised
certified
and can
up to
I 50 ciients per year. Each client can request for consuItaton on either
five
IT
Each
types
be
the
handled
the
of
project.
of
projects will
one of
by a consuftatlon team of four to five technologists. Each technologist
four
is assigned to a maximum of
consultation teamsw

ent.
the
to
Identify the main entities possible
[4 marks]
IL

Identify the main relationship types and specify the cardinatity


for each ronship.

(4 marks
"10

TBB1 073ITAB1 01 3

iii.

Using your answers in part (a}(i) and part (a)(ii), draw a single
Entity Relationship (ER) diagram to represent the data
for
Chen
the
Use
Model notation.
requirements
company.

[4 marksj

OF
PAPER-END

'1

You might also like