assignment of programming

Upload: rabiya-saleem

Post on 03-Mar-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/26/2019 Assignment of Programming

    1/4

    The University of Faisalabad

    Submitted to : Maam Sania Nayab

    Submitted by : Group members

    Reg# bscs_fa15- : 01 Rabiya Sa!eem

    : 1 Seerat "ba!

    : 1$0 %yes&a 'utt

    Sub(ect : )b(ect oriented *rogramming

    +ate : ,-0-1$

    .opic : +estructor/ ob(ect parameters/ returning ob(ect

  • 7/26/2019 Assignment of Programming

    2/4

    Destructor:

    A destructor is a special member function that is called when the lifetime of an object ends. The

    purpose of the destructor is to free the resources that the object may have acquired during itslifetime.Designate a function as a class's destructor by preceding the class name with a tilde ( .

    !ynta":

    The synta" of declaring destructor is as follows:

    name2

    3

    +estructor body

    4

    name2 #t indicates the name of the destructor. The name must be same as the name of the

    class in which the constructor is declared.

    Ru!es of destructor:

    Do not accept arguments.

    $annot specify any return type (including void.

    $annot return a value using the return statement.

    $annot be declared as const% volatile% or static. &owever% they can be invoed for the

    destruction of objects declared as const% volatile% or static.

    bject as function parameters:

    bject can also be passed as parameters to member functions. The method of passing objects to

    functions as parameters is same as passing other variables.

    bjects can be passed to function in similar way as variables and structures .

    *rocedure and synta:

  • 7/26/2019 Assignment of Programming

    3/4

    )eturning bjects from *ember +unction:

    The method of returning an object from member function is same as returning a simple variable.

    #f a member function returns an object% its return type should be the same as the type of object tobe returned. Thesynta" and procedure to return object is similar to that of returning

    structure from function.

    Synta and procedure:

    ,rogram:

    The woring of below program is% The add2function in below program accepts a parameter

    object of type Mar6s. #t adds the contents of parameter and calling object and stores the result in

    a temporary object. The function then returns the whole object bac to main( function that is

    stored in r7The program finally displays the result using r7s&o82 statement.

    +ollowing program containing Destructor% bject as function parameters and returning object

    from member functions.

  • 7/26/2019 Assignment of Programming

    4/4