fork download
  1. #include<iostream>
  2. class Complex
  3. {
  4. int real,img;
  5. public:
  6. Complex(int p=0,int q=0)
  7. {
  8. real=p;
  9. img=q;
  10. }
  11. Complex Complex::operator+(Complex compl)
  12. {
  13. Complex temp;
  14. temp.real=real+compl.real;
  15. temp.img=img+compl.img;
  16. retutn (temp);
  17. }
  18. Complex Complex::operator-(Complex compl)
  19. {
  20. Complex temp;
  21. temp.real=real-compl.real;
  22. temp.img=img-compl.img;
  23. retutn (temp);
  24. }
  25. void dump()
  26. {
  27. cout<<"real part "<<real<<endl;
  28. cout<<"imaginary part"<<img<<endl;
  29. }
  30. };
  31. int main()
  32. {
  33. Complex C1=new Complex(5,6);
  34. complex C2=new Complex(6,5);
  35. Complex temp;
  36. temp=c1+c2;
  37. cout<<"after adding the two numbers"<<endl;
  38. temp.dump();
  39. }
  40.  
  41.  
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:11: error: expected ‘,’ or ‘...’ before ‘~’ token
prog.cpp:11: error: extra qualification ‘Complex::’ on member ‘operator+’
prog.cpp:18: error: expected ‘,’ or ‘...’ before ‘~’ token
prog.cpp:18: error: extra qualification ‘Complex::’ on member ‘operator-’
prog.cpp: In member function ‘Complex Complex::operator+()’:
prog.cpp:14: error: expected primary-expression before ‘.’ token
prog.cpp:15: error: expected primary-expression before ‘.’ token
prog.cpp:16: error: ‘retutn’ was not declared in this scope
prog.cpp:17: warning: no return statement in function returning non-void
prog.cpp: In member function ‘Complex Complex::operator-()’:
prog.cpp:21: error: expected primary-expression before ‘.’ token
prog.cpp:22: error: expected primary-expression before ‘.’ token
prog.cpp:23: error: ‘retutn’ was not declared in this scope
prog.cpp:24: warning: no return statement in function returning non-void
prog.cpp: In member function ‘void Complex::dump()’:
prog.cpp:27: error: ‘cout’ was not declared in this scope
prog.cpp:27: error: ‘endl’ was not declared in this scope
prog.cpp: In function ‘int main()’:
prog.cpp:33: error: invalid conversion from ‘Complex*’ to ‘int’
prog.cpp:33: error:   initializing argument 1 of ‘Complex::Complex(int, int)’
prog.cpp:34: error: ‘complex’ was not declared in this scope
prog.cpp:34: error: expected `;' before ‘C2’
prog.cpp:36: error: ‘c1’ was not declared in this scope
prog.cpp:36: error: ‘c2’ was not declared in this scope
prog.cpp:37: error: ‘cout’ was not declared in this scope
prog.cpp:37: error: ‘endl’ was not declared in this scope
stdout
Standard output is empty