0

Guys where is the problem?help plz

Here's the code #include<iostream> using namespace std; class complex { public: complex(); complex(double, double); complex add(complex); complex sub(complex); void print(); private: double realpart; double imaginarypart; }; int main() { complex m(1,2),c(3.2,5); complex a=m.add(c); complex b=m.sub(c); a.print(); b.print(); return 0; } complex::complex(double r,double m) { realpart=r; imaginarypart=m; } complex::complex() { realpart=0; imaginarypart=0; } complex complex::add(complex x) { complex z; z.realpart=realpart+x.realpart; z.imaginarypart=imaginarypart+x.imaginarypart; return z; } complex complex::sub(complex y) { complex n; n.realpart=realpart-y.realpart; n.imaginarypart=imaginarypart-y.imaginarypart; return n; } void complex::print() { cout<<realpart<<"+"<<imaginarypart"i"<<endl; cout<<realpart<<"-"<<imaginarypart<<"i"<<endl; }

2nd Jul 2020, 10:00 AM
Elahe Anna
Elahe Anna - avatar
8 Answers
2nd Jul 2020, 10:34 AM
rodwynnejones
rodwynnejones - avatar
+ 8
Your last line of code giving errors u need to correct it
3rd Jul 2020, 5:33 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Gusy plz help me where is my problem? Why i have errors? C++
2nd Jul 2020, 10:01 AM
Elahe Anna
Elahe Anna - avatar
0
example of what you need to do (you need to use the 'this->' pointer):- complex complex::add(complex x) { complex z; z.realpart=this->realpart+x.realpart; z.imaginarypart=this->imaginarypart+x.imaginarypart; return z; }
2nd Jul 2020, 10:15 AM
rodwynnejones
rodwynnejones - avatar
0
Still i have errors😣 Who can help me to write this code?
2nd Jul 2020, 10:22 AM
Elahe Anna
Elahe Anna - avatar
0
I suggest you to only share a link to your code, so we can run it ourselves abd try to find your mistake.....
2nd Jul 2020, 10:23 AM
Alexander Thiem
Alexander Thiem - avatar
0
Ä° don't understand what you say? And what can i do?
2nd Jul 2020, 10:28 AM
Elahe Anna
Elahe Anna - avatar
0
Thank youuuuu😍
2nd Jul 2020, 10:35 AM
Elahe Anna
Elahe Anna - avatar