Sept14 Tcb2073 Structured Programming and Database System

download Sept14 Tcb2073 Structured Programming and Database System

of 23

Transcript of Sept14 Tcb2073 Structured Programming and Database System

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    1/23

    UNIVERSITI

    TEKNOLOGI

    COURSE

    DATE

    TIME

    TCB2O73

    .

    STRUCTURED

    PROGRAMMING

    AND

    DATABASE

    SYSTEM

    lorH

    JANUARY

    2015

    (SATURDAY)

    9.00 AM

    -

    12.00

    NOON

    (3

    hours)

    INSTRUCTIONS

    TO CANDIDATES

    SECTION

    A

    SECTION

    B

    Answer

    ALL

    questions

    in

    the OMR

    sheet.

    1.

    2.

    3.

    4

    Answer

    ALL

    questions

    in

    the Answer Booklet.

    Begin

    EACH

    answer

    on

    a new

    page.

    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.

    5

    There

    are TWENTY

    THREE

    (23) pages

    in

    this

    euestion

    Booktet

    including

    the cover

    page.

    FINAL

    EXAMINATION

    SEPTEMBER

    201

    4 SEMESTER

    Note

    :

    Universit.i

    Teknologi

    PETRONAS

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    2/23

    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.

    input

    B.

    output

    C.

    program

    D.

    compiler

    2.

    ldentify which statement that

    have

    the same effect

    as

    c in))ca

    rT

    ype ))coEmi

    t

    t

    e d)>

    ki

    I

    omet

    re

    ;

    A.

    get

    line))carType))coEmitted>>

    ki

    lometre

    ;

    B.

    cin))"\ncarType">)"\ncoEmitted,>>'t\nkilometTe,'

    ;

    C.

    cin))carType;

    cin))coEmitted;

    cln>>kilometre;

    D.

    cin))carTypekifometre;

    3. Rearrange

    the

    steps of

    preparing

    a

    program

    for

    execution

    i.

    Any

    syntax

    errors

    must be

    edited

    before

    recompiled.

    ii.

    Write

    a

    program

    in

    a

    compiler.

    iii.

    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.

    i, ii, iii,

    iv

    B.

    i, iii, ii,

    iv

    C.

    ii, i, iv,

    iii

    D.

    ii,

    i, iii, iv

    2

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    3/23

    TCB2073

    4.

    ldentify

    the

    TRUE

    statements.

    i.

    lnteger

    data

    type

    could

    be

    declared

    for

    no decimal

    point

    value.

    ii.

    Float

    data

    type

    could

    be

    used

    for

    array

    of characters.

    iii.

    Double data type could store

    only

    two

    digits.

    iv.

    Symbols

    could

    be

    stored

    as

    character

    data type.

    A.

    iand

    ii

    B.

    iand

    iii

    C.

    iand

    iv

    D.

    All

    of

    the

    above

    5.

    What

    is

    the output

    for

    the

    C++

    statements

    below?

    int qmarkcode:,

    ?,

    ;

    cout

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    4/23

    TCB2073

    8.

    What is

    the output

    for

    the following

    Q++program?

    int

    main

    (

    )

    {

    cout

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    5/23

    9.

    TCB2O73

    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

    Which

    of

    the following

    is

    a

    VALID C++

    assignment

    statement?

    A.

    j+j:25;

    B. k:

    sum

    +

    5;

    C.

    amount

    :

    $10++;

    D.

    p+p+p:total;

    Which

    of

    the following

    is

    a VALID

    C++

    compound

    assignment

    statement?

    A.

    j+):25;

    B.

    k: k+26i;

    C.

    amount

    +:

    10;

    D. 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.

    Only i, ii

    and

    iii

    are

    valid.

    B.

    Only

    i,

    iii

    and iv

    are valid.

    C. Only

    iii,

    iv

    and

    v

    are

    valid.

    D.

    Only

    i, i,

    iv

    and v

    are

    valid.

    10.

    11.

    12.

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    6/23

    TCB2073

    Question

    '13,14

    and 15

    refer

    to the following

    problem

    in

    FIGURE

    Q13.

    3.

    ln solving

    the

    problem,

    what

    could

    be the input

    and output of

    the

    program?

    A. lnput:

    Hours;

    Output:

    Salary

    B. lnput:

    Weekly

    salary;

    Output:

    Salary

    C. lnput:

    Hourly

    rate;

    Output:

    Weekly

    salary

    D.

    lnput:

    Weekly

    working

    hours; Output:

    Weekly

    salary

    4.

    Which statements

    are

    the

    valid

    steps

    to

    process

    the

    input

    and output

    (in

    sequence)?

    A.

    Get

    weekly

    hours,

    calculate

    weekly

    salary

    B.

    Get

    hourly rate,

    calculate

    weekly

    salary,

    display weekly

    salary

    C.

    Get

    weekly

    hours,

    calculate

    weekly

    salary,

    display weekly salary

    D.

    Display

    weekly salary,

    get

    weekly

    working

    hours, calculate weekly

    salary

    '15.

    What

    are

    the combination

    of

    conditions

    needed

    to

    solve

    the

    problem?

    A. Input

    :

    40,

    fnput

    I

    40,

    Input

    >40

    B. Input

    :

    40,

    Input

    1

    40, Input >60

    C. Input

    l: 40,

    Rate

    5.50

    D. Input 40

    &&

    Input:60

    6

    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

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    7/23

    TCB2073

    Question

    16,17

    and 18 refer

    to

    the following

    C++ statements

    in

    FIGURE

    Q16.

    int

    exampleRecursion

    (int

    n)

    {

    if

    (n::0

    )

    return

    0;

    el- se

    return

    exampleRecursion

    (n-1

    )

    +n*n*n;

    Ì

    FIGURE

    Q16

    16.

    What

    will function

    exampteRecursion

    do?

    A. returns

    the cube

    of

    the number

    n

    B.

    returns

    three

    times

    the

    number

    n

    C. returns

    the

    next

    number

    in

    a Fibonacci

    sequence

    D. returns

    the

    sum of

    the

    cubes

    of

    the numbers,

    0

    to

    n

    17.

    what is

    the output

    of

    doing

    a

    call

    function

    exampteRecursion

    (3)

    ;

    ?

    A.

    25

    B.

    32

    c.

    36

    D.

    42

    18.

    which

    of

    the following

    is an

    INVALID

    call

    to

    exampreRecurslon?

    A.

    exampleRecursion

    (-1)

    ;

    B.

    exampleRecursion(O)

    ;

    C.

    exampleRecursion (1)

    ;

    D.

    exampleRecursion

    (999);

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    8/23

    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

    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

    Which

    of

    the

    following

    would

    be an INVALID

    statementz

    A. function print

    are

    overloaded

    functions

    B.

    function

    print

    are out of

    bound functions

    C.

    we

    could add

    one more

    function

    named

    print

    to display string

    D.

    function print

    could

    be

    declared for

    many

    times with the

    same

    name

    but different

    data

    type as

    parameter

    19.

    20.

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    9/23

    21.

    TCB2073

    ldentify

    the INVALID

    C++

    statement

    from

    the

    program

    segment

    below.

    void

    multiply

    (double

    &data[],

    int

    size,double

    factor

    )

    {

    for

    (int

    i:0;i

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    10/23

    TCB2O73

    23.

    Given

    the following

    C++

    program,

    determine

    the CORREGT output.

    void

    swap

    (int

    px,

    int

    py)

    {

    int

    temp;

    temp:px;

    px:py;

    py:temp;

    nt

    main

    (

    )

    int

    a: I0,b--20;

    sv/ap

    (a,b)

    ;

    cout((a(("

    "((b((endl;

    return

    0;

    Ì

    A.

    10 20

    B.

    10 10

    C.

    20 10

    D.

    20

    20

    24.

    What

    is

    the data type for

    variable

    data

    in

    the

    C++

    statements

    below?

    for

    (

    int

    i:0

    ;

    i

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    11/23

    TCB2073

    26.',

    What is

    the difference

    between

    vector

    and

    array?

    A.

    Vector

    have

    bigger

    data

    storage

    size

    than

    affay.

    B.

    Vector

    could

    be

    passed

    as reference

    but

    not

    array.

    C.

    Array could

    be

    passed as reference

    but not vector.

    D.

    Only

    anay could

    be

    used

    to

    store

    character,

    not vector.

    27.

    The expression

    totaf:

    grade

    In

    +50]

    *100;

    '

    A.

    is

    vatíd.

    B.

    is

    invalid,

    C.

    will

    result

    in a

    compiler

    warning.

    D.

    will result

    in out

    of bounds

    condition.

    28.

    Given

    the following

    c++

    program,

    determine

    the coRREcr

    output.

    int

    main

    (

    )

    11

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    12/23

    TCB2O73

    29.

    An

    entire

    array can be

    passed

    as an argument

    to a function

    A.

    if

    the

    function

    is not

    overloaded.

    B.

    by

    passing

    the name

    of

    the

    array.

    C.

    by

    passing

    the

    name

    of

    the aïay

    and the

    total

    numbers of

    elements.

    D.

    by

    passing

    the name

    of

    the

    arcay

    with

    symbol

    "&"

    at the

    beginning

    of it

    and

    the total numbers

    of

    elements.

    Question

    30, 31

    and 32

    refer

    to

    the following

    C++ statements in FIGURE

    Q30.

    int

    main

    (

    )

    {

    int

    t,)

    i

    int

    va1

    [3 ] t4

    I

    :{

    B,

    16, 9,

    52, 3, 15, 2'/,

    6, 14,

    25, 2,

    I0}

    ;

    for

    (

    i:0

    ;

    i

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    13/23

    31_

    TCB2O73

    0,

    which C++

    statements

    will

    total

    A.

    B.

    D.

    Assuming

    that int

    total is intialize

    to

    up all

    elements in

    array

    va1?

    13

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    14/23

    TCB2073

    32.

    Which C++

    statements

    will display

    B

    ,3,

    r4?

    A.

    for

    (

    i:0; i

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    15/23

    TCB2073

    33.

    Given

    the followíng

    c++

    program,

    identify

    the INVALID

    statement.

    int main

    (

    )

    {

    double

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

    6.'7

    } ;

    show

    (double

    []

    )

    ;

    show

    (rate)

    ;

    return

    0;

    Ì

    void

    show

    (double

    vafs

    []

    )

    {

    int i:0;

    while

    (i

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    16/23

    TCB2O73

    35. Which

    of

    the following

    C++ statements

    will read

    a

    character

    from

    a

    file

    readily

    connected

    with fstream

    object

    called readme?

    36.

    Tuple is

    (are)

    A. a

    set

    of relations.

    B.

    row(s)

    of

    a

    relation.

    C. a

    named

    column

    of a relation.

    D.

    the

    number

    of

    attributes

    in

    a relation.

    A.

    B.

    C.

    D.

    Data

    Definition

    EXCEPT

    A.

    CREATE

    B.

    ALTER

    C.

    DELETE

    D.

    TRUNCATE

    ch:readme;

    readme.get (ch);

    cin((readme((ch

    ;

    cin.

    get

    (readme)

    ;

    37.

    Language(DDL)

    includes

    all

    commands

    below

    38.

    Data

    Manipulation Language(DML)

    includes

    all

    commands

    below

    EXCEPT

    A.

    DROP

    B. INSERT

    C.

    SELECT

    D.

    UPDATE

    16

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    17/23

    TCB2073

    Question

    39

    and

    40

    refer

    to TABLE

    Q39.

    TABLE

    Q39

    39.

    TRUNCATE

    TABLE

    Engineer

    will

    A,

    delete

    table

    engineer

    B.

    create

    a

    copy

    of

    table

    engineer

    C.

    remove

    all

    data from

    table

    engineer

    D. remove

    all

    columns

    with

    word

    'engineer'

    as its

    header

    40.

    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

    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

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    18/23

    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

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    19/23

    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.

    b.

    Declare

    a 2D

    aïay

    to

    store

    hostel for

    Semester

    1,

    2

    and

    [18

    marks]

    number

    of students'

    data in

    each

    3.

    19

    HosteI

    Hame

    HLrmher-

    of Students

    UILLÈGE

    1

    2øT

    UIILÊGE

    2

    3øB

    UIILÊGE 3

    2øB

    UILLAGE

    4

    4EO

    UILIÊGE 5

    JEø

    UIILÊGE

    6

    158

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

    in

    arr

    rrcrsters

    is

    1550

    Tite auer.age

    nunher.

    of students

    in a

    hosteI

    is 258

    U I

    LtÊGE

    4 h¡s tlre

    Ìiiqhest

    nunhel of

    studenrs

    r1468)

    FIGURE

    Q1

    [2

    marks]

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    20/23

    2.

    TC82073

    A

    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.

    FIGURE

    Q2b

    [20

    marks]

    Product

    Unit Annual

    Production

    Petrofeum

    Natural

    Gas

    Coal

    thousand

    billion

    miffion

    barrels per

    day

    cubic

    feet

    short tons

    696.2r

    2I19.00

    3.27

    20

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    21/23

    TCB2O73

    3.

    TABLE

    Q3a,

    Q3b

    and

    Q3c

    show

    the tables

    in

    a

    database,

    VehicleDB.

    TABLE

    Q3a:

    Customer

    Table

    TABLE

    Q3b:

    Vehicle

    Table

    a.

    What is

    the

    primary

    key for

    Customer,

    Vehicle ând

    Order

    tables?

    [3

    marks]

    CustomerlD

    Name

    Address

    Phone Number

    1

    101

    Simon Cowell

    3

    Jalan

    Mentimun

    054568974

    1102

    Katijah

    Ahmad

    6 Meru

    Height 058974569

    1

    103

    Lee

    Cheng

    Ee 9 Taman

    Sentosa

    041235698

    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

    2

    41234

    VM2 1101

    1

    80987

    SA2

    1102 1

    c9834

    SA1

    1 103 4

    21

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    22/23

    b.

    TCB2O73

    Write

    the

    SQL

    query

    that will insert

    new

    customer

    with

    the following

    information

    into

    the Customer

    table.

    c.

    d.

    Write

    the SQL

    manual feature,

    query

    that

    will

    manufactured

    in

    [4

    marks]

    look

    for

    vehicle

    with

    year

    2013 and 2012.

    [3

    marks]

    order

    details

    of

    TransactionlD,

    [2

    marks]

    Write

    the SQL

    query

    that will

    display

    the

    Simon

    Cowell.

    The

    order

    details

    include

    ModellD,

    Buyer

    and

    Quantity.

    e.

    Write

    the SQL

    query

    that

    will

    change

    the

    order

    Table

    as

    below:

    [4

    marks]

    Show

    the result for

    the

    following

    SQL

    query:

    SELECT

    PhoneNumber,

    Buyer,

    CustomerlD

    FROM

    Customer,

    Order

    WHERE

    Buyer:CustomerID

    GustomerlD

    Name

    Address

    Phone

    Number

    1104

    Rajukumar

    12

    Jalan

    Selesa

    047894563

    TransactionlD

    ModellD

    Buyer

    Quantity

    41234

    vA2

    1101

    2

    41234

    VM2

    1101

    1

    80987

    SA2

    1102

    2

    c9834

    SA1

    1103

    2

    22

    [2

    marks]

  • 8/18/2019 Sept14 Tcb2073 Structured Programming and Database System

    23/23

    TCB2O73

    g.

    Write C++

    statements

    that

    will connect

    a

    program

    to

    VehicleDB

    database.

    [2

    marks]

    .END

    OF

    PAPER.