fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Complex
  4. {
  5. private:
  6. double real;
  7. double img;
  8. public:
  9. void setvalue(double r,double i)
  10. {
  11. real=r;
  12. img=i;
  13. }
  14. double getreal()
  15. {
  16. return real;
  17. }
  18. double getimg()
  19. {
  20. return img;
  21. }
  22. void display()
  23. {
  24. if(img < 0) cout << real << " - " << abs(img) << "i" <<endl;
  25. else cout << real << " + " << (img) << "i" <<endl;
  26. }
  27. void add(Complex c,Complex d)
  28. {
  29. Complex e;
  30. e.real = c.real +d.real;
  31. e.img = c.img + d.img ;
  32. e.display();
  33. }
  34. void sub(Complex c,Complex d)
  35. {
  36. Complex e;
  37. e.real = c.real -d.real;
  38. e.img = c.img - d.img ;
  39. e.display();
  40. }
  41.  
  42. };
  43. int main()
  44. {
  45. Complex a,b;
  46. a.setvalue(3,5);
  47. b.setvalue(9,6);
  48. a.display();
  49. b.display();
  50. }
  51.  
  52.  
  53.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
3 + 5i
9 + 6i