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;


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)


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


cout<<"Enter Year: "<<"\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()


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

i3 = suminterest(i1,i2);


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
solve mesh and nodal analysis through c/c++?

Compiler Design - Limit In The Method Instructions

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

who to write max if statements in a program

Compiler Design - Limit In The Method Instructions

Multiple Inheritance Multiple inheritance , as the name suggests , is  deriving a class from more than one class . The derived class inherits all the properties of all its base c

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

program that generate university statistical bar graph using 3d function

Write a C program to input five numbers and print them out on a new line Write a C program to input three real numbers and print them out as follows:   The first variable is