Complex.cpp
上传用户:huifengb
上传日期:2007-12-27
资源大小:334k
文件大小:2k
源码类别:

多媒体

开发平台:

Visual C++

  1. // Complex.cpp: implementation of the CComplex class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Complex.h"
  6. #include "math.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CComplex::CComplex()
  16. {
  17. m_dReal=m_dImag=0;
  18. }
  19. CComplex::~CComplex()
  20. {
  21. }
  22. CComplex CComplex::operator +(CComplex second)
  23. {
  24. CComplex first;
  25. first.m_dImag=m_dImag+second.m_dImag;
  26. first.m_dReal=m_dReal+second.m_dReal;
  27. return first;
  28. }
  29. CComplex CComplex::operator -(CComplex second)
  30. {
  31. CComplex first;
  32. first.m_dImag=m_dImag-second.m_dImag;
  33. first.m_dReal=m_dReal-second.m_dReal;
  34. return first;
  35. }
  36. CComplex CComplex::operator *(CComplex second)
  37. {
  38. CComplex first;
  39. first.m_dImag=m_dReal*second.m_dImag+m_dImag*second.m_dReal;
  40. first.m_dReal=m_dReal*second.m_dReal-m_dImag*second.m_dImag;
  41. return first;
  42. }
  43. CComplex CComplex::operator /(CComplex second)
  44. {
  45. CComplex first;
  46. double module=second.Module();
  47. second.m_dImag=-second.m_dImag;
  48. first=(*this)*second;
  49. first.m_dImag/=module;
  50. first.m_dReal/=module;
  51. return first;
  52. }
  53. double CComplex::Module()
  54. {
  55. return(double(sqrt(pow(m_dImag,2)+pow(m_dReal,2))));
  56. }
  57. CComplex CComplex::operator =(CComplex second)
  58. {
  59. m_dReal=second.m_dReal;
  60. m_dImag=second.m_dImag;
  61. return (*this);
  62. }
  63. CComplex CComplex::operator /(double divb)
  64. {
  65. m_dReal/=divb;
  66. m_dImag/=divb;
  67. return(*this);
  68. }
  69. CComplex CComplex::operator *(double mivb)
  70. {
  71. m_dReal*=mivb;
  72. m_dImag*=mivb;
  73. return(*this);
  74. }
  75. double CComplex::Arg()
  76. {
  77. return (atan2(m_dReal,m_dImag));
  78. }