• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 183,  comments - 10,  trackbacks - 0

            + - * / += -= *= /= >> <<

              1 #include <iostream>
              2 using namespace std;
              3 
              4 class Complex
              5 {
              6 private:
              7     double real;
              8     double image;
              9 public:
             10     Complex(double r = 0.0double i = 0.0) : real(r), image(i) {}
             11     Complex(const Complex& c)
             12     {
             13         real = c.real;
             14         image = c.image;
             15     }
             16     ~Complex() {}
             17     Complex& operator=(const Complex& c)
             18     {
             19         if (this != &c)
             20         {
             21             real = c.real;
             22             image = c.image;
             23         }
             24         return *this;
             25     }
             26     Complex& operator+=(const Complex& c)
             27     {
             28         real += c.real;
             29         image += c.image;
             30         return *this;
             31     }
             32     Complex& operator-=(const Complex& c)
             33     {
             34         real -= c.real;
             35         image -= c.image;
             36         return *this;
             37     }
             38     Complex& operator*=(const Complex& c)
             39     {
             40         double r2 = real, i2 = image;
             41         real = r2 * c.real - i2 * c.image;
             42         image = r2 * c.image + i2 * c.real;
             43         return *this;
             44     }
             45     Complex& operator/=(const Complex& c)
             46     {
             47         double r2 = real, i2 = image;
             48         real = (r2 * c.real + i2 * c.image) / (c.real * c.real + c.image * c.image);
             49         image = (i2 * c.real - r2 * c.image) / (c.real * c.real + c.image * c.image);
             50         return *this;
             51     }
             52     friend Complex operator+(const Complex& c1, const Complex& c2);
             53     friend Complex operator-(const Complex& c1, const Complex& c2);
             54     friend Complex operator*(const Complex& c1, const Complex& c2);
             55     friend Complex operator/(const Complex& c1, const Complex& c2);
             56     friend istream& operator>>(istream& in, Complex& c);
             57     friend ostream& operator<<(ostream& outconst Complex& c);
             58 };
             59 
             60 Complex operator+(const Complex& c1, const Complex& c2)
             61 {
             62     Complex t(c1);
             63     return t += c2;
             64 }
             65 
             66 Complex operator-(const Complex& c1, const Complex& c2)
             67 {
             68     Complex t(c1);
             69     return t -= c2;
             70 }
             71 
             72 Complex operator*(const Complex& c1, const Complex& c2)
             73 {
             74     Complex t(c1);
             75     return t *= c2;
             76 }
             77 
             78 Complex operator/(const Complex& c1, const Complex& c2)
             79 {
             80     Complex t(c1);
             81     return t /= c2;
             82 }
             83 
             84 istream& operator>>(istream& in, Complex& c)
             85 {
             86     in >> c.real >> c.image;
             87     if (!in)
             88     {
             89         cerr << "Input error!" << endl;
             90         exit(1);
             91     }
             92     return in;
             93 }
             94 
             95 ostream& operator<<(ostream& outconst Complex& c)
             96 {
             97     out << c.real << '+' << c.image << 'i';
             98     return out;
             99 }
            100 
            101 int main()
            102 {
            103     Complex c1(1.02.0), c2(3.04.0);
            104     cout << c1 << endl;
            105     cout << c2 << endl;
            106     cout << c1 + c2 << endl;
            107     cout << c1 - c2 << endl;
            108     cout << c1 * c2 << endl;
            109     cout << c1 / c2 << endl;
            110 
            111     Complex c3(5.06.0), c4(7.08.0);
            112     c1 += c2 += c3 += c4;
            113     cout << c1 << endl;
            114     cout << c2 << endl;
            115     cout << c3 << endl;
            116     cout << c4 << endl;
            117     return 0;
            118 }
            posted on 2011-04-21 23:46 unixfy 閱讀(194) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            蜜桃麻豆www久久国产精品| 国产精品一区二区久久精品无码 | 日本久久中文字幕| 成人资源影音先锋久久资源网| 亚洲午夜精品久久久久久app| 精品熟女少妇aⅴ免费久久| 狠狠色丁香婷婷久久综合不卡| 色婷婷久久综合中文久久蜜桃av| 久久婷婷五月综合色奶水99啪| 国产精品综合久久第一页| 青青草国产精品久久| 国产高潮久久免费观看| 国产精品熟女福利久久AV| 久久93精品国产91久久综合| 日日狠狠久久偷偷色综合免费 | 精品国际久久久久999波多野| 欧洲成人午夜精品无码区久久| 日韩人妻无码精品久久久不卡| 久久人妻少妇嫩草AV无码专区| jizzjizz国产精品久久| 久久亚洲精品中文字幕三区| 精品久久久久久无码中文字幕 | 久久久综合香蕉尹人综合网| 久久国产视频99电影| 国产精品成人久久久| 久久久无码精品亚洲日韩蜜臀浪潮| 中文字幕热久久久久久久| 国产91色综合久久免费| 久久国产精品一区| 亚洲精品乱码久久久久久中文字幕 | 久久免费视频1| 久久精品国产亚洲精品2020| 国产精品亚洲美女久久久| 精品人妻伦九区久久AAA片69| 韩国免费A级毛片久久| 久久亚洲国产精品123区| 久久午夜无码鲁丝片| 久久亚洲国产成人影院网站| 国产精品久久久久久福利漫画 | 久久伊人色| 久久久精品免费国产四虎|