Advertisement
Guest User

Untitled

a guest
May 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class cComplex{
  5. public:
  6. double a;
  7. double b;
  8. void init(){
  9. a = b = 0;
  10. }
  11. void set(double x, double y){
  12. a = x;
  13. b = y;
  14. }
  15. void print(){
  16. if(b >= 0){
  17. cout << a << "+" << b << "i" << endl;
  18. }else{
  19. cout << a << b << "i" << endl;
  20. }
  21. }
  22. cComplex add(cComplex o){
  23. cComplex sum;
  24. sum.a = a + o.a;
  25. sum.b = b + o.b;
  26. return sum;
  27. }
  28. };
  29.  
  30. int main(){
  31.  
  32. cComplex i, my, me;
  33. i.init();
  34. my.init();
  35. i.print();
  36. my.print();
  37.  
  38. i.set(2, 3);
  39. my.set(1, -1);
  40. i.print();
  41. my.print();
  42.  
  43. me = i.add(my);
  44. me.print();
  45.  
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement