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
Aim: To implement a program to add two polar coordinates using operator overloading. Code:                       #define PI 3.14 class polar {             double

A: you can exploit by overloading standard operators on a class, the intuition of the users of that class. This allow users program in the language of the problem domain instead of

Within software languages we have the ability to store information in mail boxes i.e. memory slots which are given names to represent the box. The naming rules are governed by the


I have an exercise with 2 problems. One that is partially completed except with read problems with memory overwrite, and the other problem. I have enclosed the instructions documen

application problem of tower of hanoi

You may work in pairs for this assignment. Submit only one project per team; both partners will receive the same grade. Also, you can earn up to 40 points (out of 25) on this assig

progarm in c for area under curve   #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; int numtraps;

Question: (a) A bank has four types of accounts with annual interest rates as follows: Savings 8% Savings with Cheque Book 5% Current 4% Fixed deposits 10% Using

describe how identifiers of different data type are defined using this notaion?