Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class complexNum
  4. {
  5.  
  6. private:
  7.  
  8.     double w, i;
  9.  
  10. public:
  11.  
  12.     complexNum ();
  13.     complexNum (double, double);
  14.  
  15.     void add      (complexNum o)
  16.     {
  17.         w += o.getWholePart();
  18.         i += o.getImagiPart();
  19.     }
  20.     void subtract (complexNum o)
  21.     {
  22.         w -= o.getWholePart();
  23.         i -= o.getImagiPart();
  24.     }
  25.     void multiply (complexNum o)
  26.     {
  27.         w = w*o.getWholePart() - i*o.getImagiPart();
  28.         i = w*i + i*o.getWholePart();
  29.     }
  30.    
  31.     double getWholePart ()
  32.     {
  33.         return w;
  34.     }
  35.     double getImagiPart ()
  36.     {
  37.         return i;
  38.     }
  39.     void print()
  40.     {
  41.         std :: cout << "(" << w << " + " << i<<"i)";
  42.     }
  43.  
  44.  
  45. };
  46.  
  47. complexNum::complexNum ()
  48. {
  49.     w = 16;
  50.     i = 12;
  51. }
  52.  
  53. complexNum::complexNum (double wPart, double iPart)
  54. {
  55.     w = wPart;
  56.     i = iPart;
  57. }
  58.  
  59. int main()
  60. {
  61.     double x1, y1, x2, y2;
  62.     std::cout << "Enter an x1 and y1 value in the form \"x1 y1\"\n";
  63.     std::cin >> x1 >> y1;
  64.     std::cout << "Enter an x2 and y2 value in the form \"x2 y2\"\n";
  65.     std::cin >> x2 >> y2;
  66.  
  67.     complexNum a = complexNum(x1, y1), b = complexNum(x2, y2);
  68.     a.print();
  69.  
  70.  
  71.     system("PAUSE");
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement