Function returning object, C/C++ Programming

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;

}

Posted Date: 9/20/2012 7:58:53 AM | Location : United States







Related Discussions:- Function returning object, Assignment Help, Ask Question on Function returning object, Get Answer, Expert's Help, Function returning object Discussions

Write discussion on Function returning object
Your posts are moderated
Related Questions
Project Description: I am trading binary options and need my signals that are sent to me via email to be sent to my followers via an RSS feed I have no idea how rss feeds imp

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Need help with C network program

I have a program and I want someone to fix it for me by using basic c language program.

What is the difference among a copy constructor and an overloaded assignment operator? Ans) A copy constructor constructs a latest object by using the content of the argument

Problem Implement a class called employee that contains name, employee number and department code. Include a member function getdata() to get data from user and store it in the

Described the ISA and HASA class relationships. How would you apply each in a class design? A: A specialized class "is" specialization of another class and, thus, has the ISA re

program to check whether a given point lies inside a rectangle or not

http://www.expertsmind.com/questions/decodethecode-30110560.aspx