adv prog cr e1 answers

Upload: raul-toledano

Post on 27-Feb-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Adv Prog Cr e1 Answers

    1/2

    METROPOLIAJanne Mntykoski Advanved programming

    Class room exercise 1: answers

    1. a) What is the difference beteen c!ass and ob"ect#A: Class is the type of the object. Object is the actual realization

    of the class variable!type variable!name".

    b) When and for hat is c!ass constr$ctor $sed#A: #t$s called when object is created. %ou can initialize classvariables.

    c) When and for hat is c!ass destr$ctor $sed#A: #t$s called when class is destroyed. %ou can free dynamicallyreserved memory.

    d) What %eans &$b!ic in c!ass dec!aration#A: &hey are visible and accessible from the outside of the

    object.

    e) What %eans &ri'ate in c!ass dec!aration#A: &hey are not visible or accessible from the outside of theobject

    f) What %eans &rotected in c!ass dec!aration#A: &he same as private except they can be inherited

    (. a) or hat is !ibrary iostrea% needed#A: 'unctions cin and cout are in it

    b) Why is needed !ine$sin* na%es&ace std+A: &o call cout without std::cout. &he same for cin

    c) What is the na%e of the c!ass#c!ass hehe , -+A: hehe

    d) What is %#co$t ob".%+

    A: #t is a variable of the object obj

    e) Is this f$nction dec!aration or definition#/ariab!e0) , 'ariab!e' 2 3+-+A: (efinition

    f) Is this the defa$!t constr$ctor#/ariab!e0int defa$!t'a!$e)+A: )o. #t has a parameter.

    *) What is this#4/ariab!e0) ,-+A: Class destructor of class variable

    h) Is this f$nction dec!aration or definition#

    boo! set/ariab!e0int ne'a!$e)+A: (eclaration

  • 7/25/2019 Adv Prog Cr e1 Answers

    2/2

    METROPOLIAJanne Mntykoski Advanved programming

    i) What is the ty&e of f$nction ret$rn 'a!$e and &ara%eter#boo! set/ariab!e0int ne'a!$e)+A: *eturn value is boolean false+ true". ,arameter is new!valuewith type int

    ") What is the c!ass na%e# $nction na%e#boo! 5ehe66set/ariab!e0int ne'a!$e) , -A: Class name is -ehe and function name is setariable

    k) What is the na%e of the c!ass# 7a%e of the ob"ect#/ariab!e ob"10(83)+A: Class name is ariable and object name is obj1

    !) Is defa$!t or &ara%eteri9ed constr$ctor $sed#/ariab!e ob"10(83)+A: ,arameterized constructor

    %) Is defa$!t or &ara%eteri9ed constr$ctor $sed#

    /ariab!e ob"(+A: (efault constructor

    n) What does this do#co$t :The initia! 'a!$e of ob"1 is : ob"1.*et/a!$e0) end!+A: #t calls the getalue function of object obj1 and prints it

    return valueo) What does this do#

    cin.*et0)+A: /ill wait for 0)&0*