⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex4-1.cpp

📁 一些学习c++的例题
💻 CPP
字号:
#include <iostream.h>

class CComplex
{
private:
   double m_fReal, m_fImage;

public:
   CComplex(double r=0.0, double i=0.0)
   {
      m_fReal = r;
      m_fImage = i;
   }

   CComplex(CComplex& c)
   {
      m_fReal = c.m_fReal;
      m_fImage = c.m_fImage;
   }

   ~CComplex() { }

   const CComplex operator+(const CComplex& c)
   {
      CComplex tmp;

      tmp.m_fReal = m_fReal + c.m_fReal;
      tmp.m_fImage = m_fImage + c.m_fImage;

      return tmp;
   }

   friend ostream& operator<<(ostream& os, const CComplex& c);
};

ostream& operator<<(ostream& os, const CComplex& c)
{
   os << c.m_fReal << "+i" << c.m_fImage;
   return os;
}

void main(void)
{
   CComplex c1(1.0, 2.0), c2(3.0, 4.0);

   cout << c1 + c2 << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -