Upload
vinot-esan
View
13
Download
4
Embed Size (px)
Citation preview
UNTVERSITI
P ETRONAS
FINAL EXAMINATIONSEPTEMBER 2013 SEMESTER
COURSE : TCB1013/T881073/TC82073 STRUCTURED
PROGRAMMING / STRUCTURED PROGRAMMING
AND DATABASE
DATE : 22"d DECEMBER 2O1g (SUNDAY)
TIME : 9:00 AM - 12:00 NOON (3 HOURS)
INSTRUCTIONS TO CANDIDATES
1. SECTION A - Answer ALL questions in this section on the OMR sheet given.
SECTION B - Answer ALL questions in this section on the Answer Booklet given.
2. Begín EACH answer on a new page in the Answer booklet given.
3. lndicate clearly answers that are cancelled, if any.
4. Where applicable, show clearly steps taken in arriving at the solutions and indicate
ALL assumptions.
5. Do not open this Question Booklet until instructed.
Note : There are SEVENTEEN (f 7) pages in this Question Booklet including the
cover page.
Universiti Teknologi PETRONAS
TCB 1 0 1 3/TB B 1 07 3fi CB.207 3
SECTION B - Subjective Questions (60 Marks)
There are THREE (3) questions in this section. Answer all questions in the answer
booklet provided.
1. a. The price of a plane ticket is $1000 by default, but discounts are
applied to it basedon different criteria. The following rules determine
the discount, and hence the final price:
. Students get 20% discount.
. People who purchase 30 days ín advance get20% discount.
Discount can aggregate, for example a student purchases3O days in
advance gets a 40% discount. The program wold ask the user for input
on whether the user is a student or not. Design a flowchart of your
algorithm that solves the following problem and calculates the final
pnce.
[10 marks]
b. Generate a function named sum_from_tothat takes two integer
arguments, call them first and l-ast, and returns as its value the
sum of all the integers between first and last inclusive. Thus, for
example,
cout((sum from Lo(4,1) <<endf;
// will print 22 becauss {+$+$+7 = 22
cout((sum f rom to (-3, 1 ) ((endl ,'
// will print -5 'cause (-3)+(-2)+(-1)+0+1 - -5cout((sum from Lo(1 ,4) <<endl,'
// will print 22 because f +$+$+Q = 12
cout((sum from to(9,9) <<endl-;
// will print 9
[10 marks]
14
a.2
TCB 1 0 1 3/TBB 1 07 3tT CB.207 3
State the output when the following code fragment is executed.
l -r -.f 1l L ll /
float x: 3.8;n: int(x);cout<< 'rtì - tr << n <<end1;
b Translate the following flowchart to pseudo code.
[10 marks]
c Dev gram that will calcu ate the fo ow ng
ifx>0Y- +10 íf x-0
ifx<0
15
TCB 1 0 1 3/TBB 1 07 3tT CB.207 3
3. a. Generate SQL commands to create EMpLoyEE and DEpARTMENT
tables based on the table structure below.
EMPLOYEE (Emp_lDEmp_Name, Emp_Add, Emp_phone,
Dept_Code)
DEPARTMENT (Dept_Code,Dept_Name, Dept_Loc)
[10 marks]
b. construct sQL query to insert data into EMpr,oyEEtable using the
sample data below:
EmployeeName
ID Phone DepartmentGode
Address
111667 03-27739001 MKT No 5, JalanPermaisuri 3
[3 marks]
c. The company you work for wants to digitize their time cards. You have
been asked to design the database for submitting and approving time
cards. Design the database ER diagram with the following information:
. A timecard should have hours worked and date submitted
. Each timecard is associated with exacily one employee
. Each timecard should have a unique id
. Each timecard has a status: it is either approved, not approved,
or pending
o Each employee has a unique id
. Each employee has a name and address.
. Each employee submits a time card every pay period. i.e. ln 1
year, they will submit multiple time cards
. Each employee either has direct deposit or physical check as
their method of payment
. Each employee is associated with exacily one manager
16