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

C++ and matlab, ">http://www.ee.nmt.edu/~erives/289_F12/EE289_Takehome_2.p...

">http://www.ee.nmt.edu/~erives/289_F12/EE289_Takehome_2.pdf http://www.ee.nmt.edu/~erives/289_F12/Takehome2_maze.GIF

Command line arguments, i want to check the command line argument is whethe...

i want to check the command line argument is whether an integer or a string

Recursive function, Binomial coefficients are the numeric factors of the pr...

Binomial coefficients are the numeric factors of the products in a power of a binomial such as (x + y)n. For example, (x + y)2 = x2 + 2 x y + y2 has the coefficients 1 2 1. Binomia

Program to find a greatest string: c - program , Program to find a Greatest...

Program to find a Greatest String: C - Program: Write a program find largest string by c program. int main( int argc, char *argv[] ) {     if( argc         {

C program for function of copy one string in other string, C Program for FU...

C Program for FUNCTION OF COPY ONE STRING IN OTHER STRING #include stdio.h> #include conio.h> int copy(char a[],char b[]); void main() {           char a[100],b[

Title, #questionAt a shop of marbles, packs of marbles are prepared. Packet...

#questionAt a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets

How does a union differ from a structure, Problem: (a) (i) What is a...

Problem: (a) (i) What is a structure? (ii) How does a structure differ from an array? (b) Declare a structure, called account, that will contain the following data me

What are the two steps that happen while i say delete p?, A: N delete p is ...

A: N delete p is a two-step procedure: it calls the destructor, and then releases the memory. The code developed for delete p is functionally similar to this (supposing p is of typ

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