Function returning object, C/C++ Programming

Assignment Help:

Function Returning Object:

This program is like to the previous program except the function returns object.  The

main rule to be remembered is the function returning object must be defined as friend function in the class.

class interest

{float i,p,n,r,a;

public:

void getdata(int gp, int gn, int gr);

void putdata(void)

{cout<<"Interest is "<

cout<<"Amount is "<

}

Friend interest suminterest(interest,interest);

};

void interest::getdata(int gp,int gn, int gr)

{p=gp;n=gn;r=gr;

cout<<"Enter Principal: "<<"\n";

cin>>p;

cout<<"Enter Year: "<<"\n";

cin>>n;

cout<<"Enter Rate: "<<"\n";

cin>>r; i=(p*n*r)/100; a=p+i;

}

interest suminterest(interest i1, interest i2)

{interest i3; i3.i=i1.i+i2.i; i3.a=i1.a+i2.a; return i3;

}

 

int main()

{clrscr();

interest i1,i2,i3; i1.getdata(  1000,10,2); i1.putdata(); i2.getdata(10000,8,3); i2.putdata();

i3 = suminterest(i1,i2);

i3.putdata();

return 0;

}


Related Discussions:- Function returning object

Should my constructors employ"assignment"or"initialization, Should my const...

Should my constructors employ "assignment" or "initialization lists"?

Working with files in cpp, Operation Files 2.1. Your program should open an...

Operation Files 2.1. Your program should open and read the file specified by the first command line argument of the program. 2.2. The first line of the file contains an integer

Write a Programme that computes the price of portfolio, write a programme t...

write a programme that computes the price of shares and options. do the options in one-period binomial model.

Area under curve., write a c progrm to find area under the cuve y=f(x)  ...

write a c progrm to find area under the cuve y=f(x)   #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; in

Member dereferencing operators, M em b e r d e r e f e r e n c ...

M em b e r d e r e f e r e n c i ng o p e r a t o r s: T h e s e op e r a t o r s w i l l b e d i s c u s s e d l a t

Create complex number using constructor , Create Complex number using const...

Create Complex number using constructor: class complex                                 {                                                   private:

Functions, differentiate between inbuilt and user defined functions

differentiate between inbuilt and user defined functions

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd