Sunteți pe pagina 1din 7

UNIVERSITI

TEKNOLOGI
PETRONAS

FINAL EXAMINATION
SEPTEMBER 2012 SEMESTER

COURSE :

DATE
TIME

:
:

TCB1013 STRUCTURED PROGRAMMTNG


2nd JANUARY 2013 (WEDNESDAY)
9.00 AM

- 12.00 NOON (3 HOURS)

INSTRUCTIONS TO CANDIDATES

1.
2.
3.
4.
5.

Answer ALL questions from the euestions Booklet.


Begin EACH answer on a new page in the Answer Booklet.
lndicate clearly answers that are cancelled, if any.
Where applicable, show clearly steps taken in arriving at the solutions and indicate
ALL assumptions.
Do not open this Question Booklet until instructed.

Note '

There are NINE (9) pages in this Question Booklet including the cover page.

Universiti

Teknologi

PETRONAS

TCBl

b.

01 3

write a program that merges two vectors, a and b, by alternating


elements from both vectors. lf one vector is shorter than the-other,
then alternate as long as you can and then append the remaining
elements from the longer vector. For example, if a is

I49T6
and b is

1 4

11

then store the result in a new vector and display as follows.

16

71

[10 marks]

TCBl
c

for(int

j:0;

01 3

j < B; t++){
couL

(j J:

if

1)

cout
el_

cout

endl;

[4 marks]
d

for(int

i:

I; i <:5;

cout
i

.i I

1.
Lf

i++)

TCBI
e.

for(int

01 3

counter : '1 ; counter


switch(counter % 10)
{

case 0: cut ((",


cout

"; break;

cout
cout
cout
cout
cout
cout
de

fault : cQut

cout
[4 marks]

TCBl
4

a.

O1

Define a structure to store the following student data: name,


date of birth (dd:mm:yyyy), gender ('M' for male and 'F' for
female), and address that consists of street name, city, state
and postcode.
[8 marks]

b.

Using the structure defined in part (a), write a code fragment

that creates an array of 10 students. Retrieve name, date of


birth and gender of all students from the user input and
display all students' name that was born in year 1985.
[12 marks]

TCBl

5.

a.

01 3

Trace the program shoun in FIGURE Q5a and show the output.

int
{

main

int num[5] {3,4,6,2,I};


*P
: num,'
int
*q
:
int
num * 2;
int *r : enum[1];
cout
couL
cout
cout

<< num[2] << * (num+2) << endl;


<< *p << " (p+1 << endl,'
<< *q << * (q+1 << endf;
<< *r << * (r+1 << endl;

system("pause");
return 0;
FIGURE QSa
[4 marks]

b.

State the differences

of

pass-by-reference

and

pass-by-value

parameters in function.

[4 marks]

c.

What are the TWO (2) cases of a recursive function?


[2 marks]

d.

FIGURE Q5d shows a linked list with

lsr,

as the head poin|er, X

and y as the pointer pointing to the respective node. Each node


consists of info of type integer and a f ink, to point to the next
address of the node.

FIGURE Q5d

TCBI

01 3

Determine the output of the following statements:

i.

list-)info,.

ii.

X->link->i_nfo,[1 mark]

lt.

Y->inf o;

tv.

list->link->l-ink->info;
[1 mark]

e.

Based on FIGURE Q5d, write the code statement


following:

i.

Make x point to the node containing

ii.

Make v point to the last node in the list.

- END OF PAPER

10

inf

o 38.

to do the

S-ar putea să vă placă și