You are on page 1of 23

UNIVERSITI

TEKNOLOGI

FINAL EXAMINATION
SEPTEMBER 201 4 SEMESTER
COURSE

TCB2O73

STRUCTURED PROGRAMMING AND

DATABASE SYSTEM
DATE

lorH JANUARY 2015 (SATURDAY)

TIME

9.00 AM

12.00 NOON (3 hours)

INSTRUCTIONS TO CANDIDATES

SECTION A

Answer ALL questions in the OMR sheet.

SECTION B

1.

Answer ALL questions in the Answer Booklet.

2.

Begin EACH answer on a new page.

3.

lndicate clearly answers that are cancelled, if


any.

Where applicable show clearly steps taken

arriving

in

at the solutions and indicate ALL

assumptions.
5

Do not open this Question Booklet

until

instructed.

Note

There are TWENTY THREE (23) pages in this euestion Booktet


including the cover page.

Universit.i Teknologi

PETRONAS

TCB2073
SECTION A
[40 Marks]

1.

Computer is an electronic machine that can receive, store or process

data according to a set of instructions and produce information. A


set of instructions is also known as

A.
B.
C.
D.
2.

input
output
program

compiler

ldentify which statement that have the same effect as

in))ca rT ype ))coEmi t t e d)> ki I omet re ;


get line))carType))coEmitted>> ki lometre ;
cin))"\ncarType">)"\ncoEmitted,>>'t\nkilometTe,'
cin))carType;
cin))coEmitted;
cln>>kilometre;
cin))carType<<
c

A.
B.
C.

D.

))coEmitted<<
>>kifometre;

3.

Rearrange the steps of preparing a program for execution

i.
ii.
iii.

Any syntax errors must be edited before recompiled.


Write a program in a compiler.
Object files and additional files will be linked by linker/loader

and ready for execution.

iv.

When the source program is error free, the translated language


is saved as an object program.

A.
B.
C.
D.

i, ii, iii, iv
i, iii, ii, iv
ii, i, iv, iii
ii, i, iii, iv
2

TCB2073

4.

ldentify the TRUE statements.

i.
ii.
iii.
iv.
A.
B.
C.
D.
5.

lnteger data type could be declared for no decimal point value.


Float data type could be used for array of characters.
Double data type could store only two digits.
Symbols could be stored as character data type.

iand

ii

iand

iii

iand iv
All of the above

What is the output for the C++ statements below?

int qmarkcode:, ?, ;
cout<<"ASCII code for ? :,,<(qmarkcode<(endl;
A. ASCII code for ? : ?
B. ASCII code for ? : 62
C. ASCrr code for ? :qmarkcode
D. ASCrI code for ? :qmarkcodeendl

6.

ln Math, range could be written as 0< n <100. rn c++, it shourd be


translated as

A.
B.
C.
D.
7.

0<= n <=100
0<= n ll n<=100
0<= n && n<=100
! (0<= n && n<=100)

what will be the result for calling the predefined function below?
ROUND (235-615);

A.
B.
C.
D.

235
236

23s.1
235.6

TCB2073

8.

What is the output for the following Q++program?

int
{

main

cout<<"Heffo

Wor_Id"<<end1 ;

cout(("Hello

",'

cout(("!Vorl-d"

cout ((

"Vor

Id"((endl

cout{(

"He

l-o";

l-

coutd<"Hell-o World"{(endl

A. Hello

World

HeIfo Vorldorl_d
HelfoHelIo forld

B. Heffo worl-d
HeIlo worldworl-d
Hellohelo world
C. Hello world
Hel-l-o Vorl-d

lVorld
Heffo

Hello

Worfd

D. Heflo world
Hello
V'lorld

World

Helfo
Hefl-o

Vrlord

TCB2O73
9.

Choose the GORREGT formula from the following expression, which will
produce 27.0 asthe end result.

A. 10+5.2-612
B. (10 + 5).2-612
C. (10+5*2-6)12
D. ((10+5).2-6)t2
10.

Which of the following is a VALID C++ assignment statement?

A.
B.
C.
D.
11.

j+j:25;
k: sum + 5;
amount : $10++;
p+p+p:total;

Which of the following is a VALID C++ compound assignment


statement?

A.
B.
C.
D.
12.

j+):25;
k: k+26i;
amount +: 10;
p+p+:total;

consider the following variable names and choose the GORREGT one.

i. variabl-e 3
ii. sum of g
iii. _addressEmployee
iv. 2rtne score
V. discountGstore

A.
B.
C.
D.

Only i, ii and iii are valid.


Only i, iii and iv are valid.
Only iii, iv and v are valid.
Only i, i, iv and v are valid.

TCB2073

Question '13,14 and 15 refer to the following problem in FIGURE Q13.


A company requests a program to calculate and display their workers'
weekly salary with consideration of overtime. Overtime need to be considered
when a worker worked more than 40 hours per week. Meanwhile, the salary is
based on how many hours a worker worked multiply with the hourly rate. The

first 40 hours pay rate is RM5.00.The pay rate after the first 40 hours is
RMs.50. The maximum working hours is only 60 hours. when the working
hours is more than 60 hours, the program will display appropriate message
and will not calculate the weekly salary.
FIGURE Q13

3.

ln solving the problem, what could be the input and output of the program?

A.
B.
C.
D.
4.

lnput: Hours; Output: Salary


lnput: Weekly salary; Output: Salary
lnput: Hourly rate; Output: Weekly salary
lnput: Weekly working hours; Output: Weekly salary

Which statements are the valid steps to process the input and output (in
sequence)?

A.
B.
C.
D.

Get weekly hours, calculate weekly salary

Get hourly rate, calculate weekly salary, display weekly salary


Get weekly hours, calculate weekly salary, display weekly salary
Display weekly salary, get weekly working hours, calculate weekly

salary

'15.

What are the combination of conditions needed to solve the problem?

A.
B.
C.
D.

Input
Input
Input
Input

: 40, fnput I 40, Input >40


: 40, Input 1 40, Input >60
l: 40, Rate <5.00, Rate >5.50
<: 40, Input >40 && Input<:59, Input>:60

TCB2073

Question 16,17 and 18 refer to the following C++ statements in FIGURE Q16.

int
{

exampleRecursion

if (n::0
return

(int

n)

0;

el- se

return

exampleRecursion (n-1 ) +n*n*n;

FIGURE Q16

16.

What will function exampteRecursion do?

A.
B.
C.
D.
17.

returns three times the number

returns the next number in a Fibonacci sequence

returns the sum of the cubes of the numbers, 0 to n

what is the output of doing a call function exampteRecursion (3)

A.
B.

c.
D.
18.

returns the cube of the number

25
32
36
42

which of the following is an INVALID call to exampreRecurslon?

A.
B.
C.
D.

exampleRecursion (-1)
exampleRecursion(O)

exampleRecursion (1)

exampleRecursion (999);

TCB2O73

Question 19 and 20 refer to the following c++ statements in FIGURE e1g.

#include (iostream)
using namespace std;

vold print (int i)


i

cout

void print (double f)


{

cout
)

int main (
{

print(10);
print ( 10 . 10 ) ,' return

0;

FIGURE Q19

19.

What is the output from the program?

A.

Here is int 10
Here is int 10.10

B.

Here is float 10

Here is float 10.10

C.

Here is int 10
Here is float 10.10

D.

Here is float 10
Here is int 10.10

20.

Which of the following would be an INVALID statementz

A.
B.
C.
D.

print are overloaded functions


function print are out of bound functions
we could add one more function named print
function

function

print

to display string

could be declared for many times with the

same name but different data type as parameter

TCB2073
21.

ldentify the INVALID C++ statement from the program segment


below.

void multiply (double &data[], int size,double


factor

for (int i:0;i<size;i++)


data Ii]:data Ii] *factor;

A.
B.

c.

for (int i:0;i<size;i++


data Ii]:data Ii] *factor;
void multiply (double &data[], int size,double
factor

D.

22.

None ofthe above

Given the following C++program, determine the GORRECT output.

void swap (int px, int


{

epy)

1nt temp;
temp:px,'

px:py;
py:temp;
)

lnt
{

main

int a: I0,b:20;

swap (a,b);

cout((a((" "((b((endf
return 0;

A.
B.

C.
D.

TCB2O73

23.

Given the following C++ program, determine the CORREGT output.

void swap (int px, int


{

int

py)

temp;

temp:px;
px:py;
py:temp;

i nt

main

int a: I0,b--20;
sv/ap (a,b) ;
cout((a((" "((b((endl;
return 0;

A.
B.
C.
D.
24.

10 20
10 10
20 10
20 20

What is the data type for variable data in the C++ statements below?

for int i:0 ; i<data . si ze O ; i++


(

data

25.

til:0;

A.

int

B.

aay

c.

vector

D.

double

When an array is initialized within a declaration statement, the initializing


statements

A.
B.
C.
D.

must be enclosed in curly braces.


must be surrounded by a parentheses.

must be individually enclosed in square braces.


must represent every element contained in the array.

10

TCB2073

26.',

What is the difference between vector and array?

A.
B.
C.
D.
27.
'

Vector could be passed as reference but not array.


Array could be passed as reference but not vector.
Only anay could be used to store character, not vector.

The expression

A.
B.
C.
D.
28.

Vector have bigger data storage size than affay.

totaf: grade In +50] *100;

is vatd.
is invalid,

will result in a compiler warning.


will result in out of bounds condition.

Given the following c++ program, determine the

int main ( )

11

coRREcr

output.

TCB2O73

29.

An entire array can be passed as an argument to a function

A.
B.
C.

if the function is not overloaded.

by passing the name of the array.

by passing the name of


elements.

D.

the aay and the total numbers of

by passing the name of the

arcay with symbol "&"


beginning of it and the total numbers of elements.

at

the

Question 30, 31 and 32 refer to the following C++ statements in FIGURE Q30.

int

main

int t,)
int
va1 [3

t4 I :{ B, 16, 9, 52, 3, 15,

for ( i:0 ; i<3 ; i++


for(j:O;j<2;1++1
ccut{(val tiI tj)<<" ";return

2'/, 6, 14, 25, 2, I0}

0;

FIGURE Q3O

30.

Given the c++ program in FIGURE e30, determine the GoRREcr


output.

A.
B.
c.
D.

816315r425
B,16,g,52,3,15,2'l,6,14,25,2,rO
B 16 9 52 3 1s 21 6 14 25 2 10
0x22ff00 0x22ff00 0x22ff10 Ox22ff10 0x22ff2o
0x22ff20

12

TCB2O73
31_

Assuming that int total is intialize to 0, which C++ statements will total
up all elements in array va1?

A.

B.

D.

13

TCB2073

32.

Which C++ statements will display

A.

,3, r4?

for ( i:0; i<3; i++

for(j:0;1<4;j++
cout((vaf Ir] tj I <<"
i+:3;
B.

",.

for ( 1:0; i<3; i++


for(j-0;j<4;1++

cout((vaf tiI t)l<<" ";

+:3;

C.

for ( i:O; i<3; i++

for(j:0;j<4;1++1
cout((val tiI ij I <<" ";
j +:3;

D.

for ( i:Q; i<3; i++


;

+:3;

for(j:0;j<4;)r+1
{

cout((val liI tj I <<" *;


)

14

TCB2073

33.

Given the followng c++ program, identify the INVALID statement.

int main (

double rate t l:{ 4.2,3. 4,5.6,


show (double [] ) ;
show (rate) ;
return 0;

6.'7 } ;

void

show

(double vafs []

int i:0;
while (i<4)
{

cout((rate Ii]
i++;

A.
B.
C.
D.

34.

show (rate);
show (double []

void

show

);

(double vals []

double ratet l:{4.2,3.4,5.6,6.1};

Which of the following C++ statements will conneot an external file


name exam. dat to the intemal program file stream object named

in file?
A.

in_f ile . open ( *exam. dat " ) ;

B.

in_file.

C.

Open "exam.dat"

as in_file.open;

D.

Open "exam.dat"

for input as in file.openi

open="exam.

dat";

15

TCB2O73

35.

36.

Which of the following C++ statements will read a character from a file
readily connected with fstream object called readme?
A.

ch:readme;

B.

readme.get (ch);

C.

cin((readme((ch

D.

cin. get (readme)

Tuple is (are)

A.
B.
C.
D.
37.

38.

a set of relations.
row(s) of a relation.
a named column of a relation.

the number of attributes in a relation.

Data

Definition
EXCEPT

A.

CREATE

B.

ALTER

C.

DELETE

D.

TRUNCATE

Language(DDL) includes

all

commands below

Data Manipulation Language(DML) includes all commands below


EXCEPT
A.

DROP

B.

INSERT

C.

SELECT

D.

UPDATE

16

TCB2073

Question 39 and 40 refer to TABLE Q39.


TABLE Q39
ENGINEER-NAME

ENGINEER-ID

AGE

SAIARY

DEPT NAME

Faheem

223368

24

3 000

Mechanical

Rahmanov

13771,4

30

4 350

Chemical

Mphatabalo

717945

30

4580

Petroleum

39.

TRUNCATE TABLE

A,
B.
C.
D.

40.

delete table

Engineer

will

engineer

create a copy of table

engineer

remove all data from table

engineer

remove all columns with word 'engineer' as its header

Which SQL statement will create a table as in TABLE e39?

A.

CREATE TABLE

Engineer
(

char Engineer Name (50),


int Engineer_Id, floatSalary,
intAge, char Dept Name (5)
)

B.

CREATE TABLE

Engineer
(

Engineer_Name char (50) ,


Engi_neer_Id int, Salary float,
Age int,Dept Name char(5)

17

TCB2073

C.

CREATE TABLE

Engineer
{

Engineer Name char(50),


Engineer_Id int, Salary float,
Age int,Dept Name char(5)

D,

CREATE TABLE

Engineer
(

char Engineer Name [50],


int Engineer_Id, ffoat Salary,
int Age, char Dept Name t5l

1B

TCB2O73

SECTION B

[60 Marks]
There are THREE questions in this section. Answer ALL questions.

1.

AgodaUni provides six hostels for its student's accommodation. The


university's hostel management unit have to keep track of the hostels'
capacity and they need your help.

a.

Write a program that will accept the number of students


registered for each hostel from the user. Array StudentNum will
store the number of students in each hostel. Each hostel could
only accommodate 400 students in one semester, lf user key-in
more than 400 students for one hostel, your program will show

an error message. The program will call a function that will


calculates and displays the total number of students in all
hostels, compute the average number

of students in each

hostel and find the hostel with the highest number of students.
A sample of output is shown in FIGURE Q1. Analyze the output
screen, then write a complete C++ program.

Hame
UILLGE 1
UIILGE 2
UIILGE 3
UILLAGE 4
UILIGE 5
UIILGE 6

HosteI

HLrmher-

of Students

2T
3B
2B
4EO

JE

158
-il;-;ili-ffi;;-;;;;,,,

in arr rrcrsters is 1550


of students in a hosteI is 258
I LtGE 4 hs tlre iiqhest nunhel of studenrs r1468)

Tite auer.age nunher.


U

FIGURE Q1
[18 marks]
b.

Declare a 2D aay to store number of students' data in each


hostel for Semester 1, 2 and 3.

[2 marks]
19

TC82073
2.

production. dat file contains

a list of data for Company PetrUnos

yearly production. The content of the file is

as shown

in

FIGURE

Q2a:

Petroleum

thousand barrels per day


696.21

FIGURE Q2a

Write a program that will read the data from production.dat and
produce the output as in FIGURE Q2b into a file named

record.dat. Do include input and output stream error detection in


your program.

Product

Unit

Petrofeum

thousand

Natural

billion cubic feet

2I19.00

miffion short tons

3.27

Coal

Gas

Annual Production

barrels per day

696.2r

FIGURE Q2b

[20 marks]

20

TCB2O73

3.

TABLE Q3a, Q3b and Q3c show the tables in a database, VehicleDB.
TABLE Q3a: Customer Table
CustomerlD

Name

Address

Phone Number

101

Simon Cowell

3 Jalan Mentimun

054568974

1102

Katijah Ahmad

6 Meru Height

058974569

103

Lee Cheng Ee

9 Taman Sentosa

041235698

TABLE Q3b: Vehicle Table


YearOfManufacture

GolorlD

Feature

vA2

2013

B1

Automatic

VM2

2013

R1

Manual

SA2

2013

W1

Automatic

SA1

2012

B1

Manual

TABLE Q3c: Order Table

TransactionlD

ModellD

Buyer

Quantity

41234

vA2

1101

41234

VM2

1101

80987

SA2

1102

c9834

SA1

103

a.

What is the primary key for


Order tables?

Customer, Vehicle

nd

[3 marks]

21

TCB2O73
b.

Write the SQL query that will insert new customer with
the following information into the Customer table.

GustomerlD

Address

Name

Phone

Number
1104

Rajukumar 12 Jalan

047894563

Selesa

[4 marks]
c.

Write the SQL query that will look for vehicle with
manual feature, manufactured in year 2013 and 2012.
[3 marks]

d.

Write the SQL query that will display the order details of

Simon Cowell. The order details include TransactionlD,

ModellD, Buyer and Quantity.


[2 marks]
e.

Write the SQL query that will change the

order

Table

as below:

TransactionlD

ModellD

Buyer

Quantity

41234

vA2

1101

41234

VM2

1101

80987

SA2

1102

c9834

SA1

1103

[4 marks]
Show the result for the following SQL query:
SELECT PhoneNumber,

Customer, Order

Buyer, CustomerlD

WHERE

FROM

Buyer:CustomerID
[2 marks]

22

TCB2O73

g.

Write C++ statements that will connect a program to


VehicleDB database.
[2 marks]

.END OF PAPER.

23