Objects as function arguments, C/C++ Programming

Objects as Function Arguments:

In C program there are several methods to define arguments, and in some case even a

structure can be approved as an argument.  Similarly in C++ in place of structure an object can be defined as an argument.

 

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 "<

}

void 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;

}

void interest::suminterest(interest i1, interest i2)

{i=i1.i+i2.i;

a=i1.a+i2.a;      }

 

int main()

{clrscr();

interest i1,i2,i3; // Created three objects

i1.getdata(  1000,10,2); //Calculates interest and amount for object i1.

i1.putdata();

i2.getdata(10000,8,3); //Calculates interest and amount for object i2.

i2.putdata();

i3.suminterest(i1,i2); ////Total interest and amount from object i1 and i2.

i3.putdata();

return 0;

}

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







Related Discussions:- Objects as function arguments, Assignment Help, Ask Question on Objects as function arguments, Get Answer, Expert's Help, Objects as function arguments Discussions

Write discussion on Objects as function arguments
Your posts are moderated
Related Questions
Using your mountain project source code as a starting point, you are to write a code that randomly chooses one of the triangles on the surface of your mountain, this will be the en

What does it mean to declare a 1.      member function as a virtual A: (a) C++ virtual function is member function of any class, whose functionality may be over- ridden in

A student apears in exam of math, physics, and chemistry. Write a program to find the total marks aa student has aqueired find the average.

What is inheritance? Class, the vehicle, which is used to execute object-oriented concepts in C++, has given a new dimension to this idea of reusability. Many vendors now offer

Task 1 Demonstrate a Java client and server exchanging one text message in each direction. Task 2 Demonstrate a C client and server exchanging one text message in each

c program to implement least cost method

Object Initialization An object of a derived class can be initialized to an object of a base class. If both the classes have similar data members, then no specific constructor

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

I''m having trouble with my C code to red from a Hash table. Not sure what it is I''m doing wrong and stumped. I need to get it figured out by tomorrow at 4:00 p.m. Eastern time. C