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
write a cprogram to calculate fraction through recursion

A: Memory that has no pointer pointing to it and there is no method to delete or reuse this memory(object), it causes Memory leak. { Base *b = new base(); } Out of this

Here is a short program. It prints out the value of a variable "x". Ernie and Bert disagree about what will be printed: Ernie says, the value gets changed in "changeX" so it will p

At 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 with thes

Program is to search for a given character in a string: Program is to search for a given character in a string and print point of match char *stsearch(char *string, char sea

Within software engineering, software is very rarely written by a single software engineer. Usually a team of engineers write a program; therefore a formal structural design approa

Write a program that predicts users’ age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/she is younger or older than G (an initial gues

Project Description: I want a simple program that will spoof my hardware id. I should be able to prepare the id to spoof to in the program and press "random" button to spoof to

I am an online tutor who can teach computer science and programming language. Is there any requirement for this?

I. COURSE DESCRIPTION Develops a working knowledge of object-oriented concepts in areas of classes, inheritance, data structures, error handling, templates and file processing.