### operator *= function

This program Should write by friend operator *= function .unfortunately It only answers triangle area.where are mistakes?plz correct this program and don't give another program.
Question:
Declare a class for Rectangle and Declare a class for Triangle.So compute area of this two and Declare a operator *= function that it multiplies area of triangle and rectangle and place value in triangle object.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465`` ``````#include #include using namespace std; class triangle; class rect { int a,b; public: int s1; void input(); int calc(); friend triangle operator *=(triangle,rect ); }; void rect :: input() { cin>>a>>b; } int rect:: calc() { return s1=a*b; } class rect; class triangle { int c,h,s2; public: void input(); int calc(); friend triangle operator *=(triangle,rect ); void show(); }; void triangle::input() { cin>>c>>h; } int triangle ::calc() { return s2=(c*h)/2; } void triangle::show() { cout<
If you intend to modify a parameter, pass it by reference http://cplusplus.com/doc/tutorial/functions2/

> Declare a operator *= function that it multiplies area of triangle and rectangle and place value in triangle object.
that's simply obfuscated.
You are killing the invariant too (the area depends on the base and height)
This program does the following:
area triangle =s1
area rectangle=s2
s1=s1*s2
In the following code Why Should We use &n (send by ref)
`triangle operator *=(triangle& n,rect m)`
If we send by value what happen in friend function?
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465`` ``````#include #include using namespace std; class triangle; class rect { int a,b; public: int s1; void input(); int calc(); friend triangle operator *=(triangle&,rect ); }; void rect :: input() { cin>>a>>b; } int rect:: calc() { return s1=a*b; } class rect; class triangle { int c,h,s2; public: void input(); int calc(); friend triangle operator *=(triangle&,rect ); void show(); }; void triangle::input() { cin>>c>>h; } int triangle ::calc() { return s2=(c*h)/2; } void triangle::show() { cout<
I want answer this my question for tomorrow.plz help me.
tanx
I seem to remember this question:
http://cplusplus.com/forum/beginner/86787/
Topic archived. No new replies allowed.