Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::string;
  5. class complex{
  6. public:
  7. void complex();
  8. void complex(double, double, string);
  9. complex add(complex, complex);
  10. complex subtract(complex, complex);
  11. complex multiply(complex, complex);
  12. void output();
  13. double getReal(){return real;}
  14. double getImaginary(){return imaginary;}
  15. void setReal(double r){real = r;}
  16. void setImaginary(double im){imaginary = im;}
  17. private:
  18. double imaginary;
  19. double real;
  20. string i;
  21.  
  22.  
  23. };
  24.  
  25. void complex::complex(){
  26. imaginary = 1;
  27. real = 2;
  28. i = "(SQRT(-1))";
  29. }
  30.  
  31. void complex::complex(double a, double b){
  32. real = a;
  33. imaginary = b;
  34.  
  35. i = "(SQRT(-1))";
  36. }
  37.  
  38. void complex::setComplexumber(double a, double b){
  39. real = a;
  40. imaginary = b;
  41. }
  42.  
  43. complex complex::add(complex lhs, complex rhs){
  44. lhs.setReal(lhs.getReal()+rhs.getReal());
  45. lhs.setImaginary(lhs.getImaginary()+rhs.getImaginary());
  46. return complex(lhs.getReal(), lhs.getImaginary());
  47. }
  48.  
  49. complex complex::subtract(complex lhs, complex rhs){
  50. lhs.setReal(lhs.getReal()-rhs.getReal());
  51. lhs.setImaginary(lhs.getImaginary()-rhs.getImaginary());
  52. return complex(lhs.getReal(), lhs.getImaginary());
  53.  
  54. }
  55.  
  56. complex complex::multiply(complex lhs, complex rhs){
  57. lhs.setReal(lhs.getReal()*rhs.getReal());
  58. lhs.setImaginary(lhs.getImaginary()*rhs.getImaginary());
  59. return complex(lhs.getReal(), lhs.getImaginary());
  60.  
  61. }
  62.  
  63. void complex::output(){
  64. std::cout << std::stod(real) << " + " << std::stod(imaginary)<<" * " << i << "\n";
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement