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
algorithm to prepare mark sheet of a student by inputing name,branchcode,semester,register no,5 marks of students and total mark of student

3 . Write a ‘C’ program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.

Define the Self-Referential Structures? It is occasionally desirable to include within a structure one member that is a pointer to the parent structure type. Generally in terms

Requirements Create a "makefile" that will manage the construction of a program The name of the makefile must be: makefile The make file must produce an executable

Create a user-defined data structure (struct) called Node that represents a node within a linked list where the "data" stored in each node is a pointer to a Car object.    a) Wr


C Program for SORTING OF NUMBERS   main() {           int a[20],i,j,temp,n;           clrscr();           printf("ENTER THE MAXIMUM LIMIT: ");           scan

I would like to get you to collaborate in my project. We want a C programmer to Develop applications for Windows, the first application may be an Instant messenger encrypted in a w

program for singly linked list with out header

Question 1 Explain the concept of constructors and destructors in C++ with programming examples Question 2 Explain the concepts and applications of multiple inheritance and v