Overloading binary operators using friend function, C/C++ Programming

Overloading Binary Operators Using Friend Function

class SI

{float i,p,n,r,a;

public:

SI(){};

SI(int gp,int gn, int gr);

void putdata(void);

friend SI operator+(SI,SI);

};

SI operator+(SI i1,SI i2)

{SI i3; i3.p=i1.p+i2.p; i3.i=i1.i+i2.i; i3.a=i1.a+i2.a; return i3;

}

void SI::putdata(void)

{cout<<"Principle is: "<

}

 

SI::SI(int gp,int gn, int gr)

{p=gp;n=gn;r=gr; i=(p*n*r)/100; a=p+i;

}

int main()

{           SI i1,i2,i3;

i1=SI(1000,2,10); i1.putdata(); cout<

return 0;

}

Posted Date: 9/20/2012 8:19:25 AM | Location : United States







Related Discussions:- Overloading binary operators using friend function, Assignment Help, Ask Question on Overloading binary operators using friend function, Get Answer, Expert's Help, Overloading binary operators using friend function Discussions

Write discussion on Overloading binary operators using friend function
Your posts are moderated
Related Questions

Write a program to determine V c for a given value of time (t)   #include stdio.h #include math.h void main() {      char prompt;   float vs,cr,t,vc;   /* input time */

Differentiate between a template class and class template in C++? Ans) Template class: A generic definition or a parameterized class not instantiated until the client gives the

program to find if a no . is prime or not

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Aim: To implement a program to swap two numbers using reference arguments. Code: void swap(int *a, int *b) {             int temp;             temp=*a;

Is always the default constructor for Fred Fred::Fred()?

What are the debugging methods you employ while came across a problem? A: Debugging with tools such as: 1.      DBG, GDB ,Forte, Visual Studio. 2.      Using tusc to trace

Presently we are using several spreadsheets to give weekly activity and income reports. Much of the information is being frequently re-keyed into several spreadsheets - we are look

Compiler Design - Limit In The Method Instructions