• <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
            設計一個長方形類Triangle,包含長和寬兩個私有數據成員。
            要求重載運算符
            ·=
             能夠支持:對象=數值  普通變量=對象  對象=對象  支持連續的賦值
            ·+= :自定義加法功能
             聯系與=的聯系
            ·>  :實現比較兩個矩形對象面積大小的比較
             能夠支持:兩個對象的比較,對象和數字的比較,數字和對象的比較
            ·>> :實現矩形對象的輸入
            ·<< :實現矩形對象的輸出
              1 #include <iostream>
              2 using namespace std;
              3 
              4 class Triangle
              5 {
              6 private:
              7     double length;
              8     double width;
              9 public:
             10     Triangle(double l = 0.0double w = 0.0) : length(l), width(w) {}
             11     ~Triangle() {}
             12     Triangle(const Triangle& t) : length(t.length), width(t.width) {}
             13     Triangle& operator =(const Triangle& t)
             14     {
             15         if (this != &t)
             16         {
             17             length = t.length;
             18             width  = t.width;
             19         }
             20         return *this;
             21     }
             22     Triangle& operator =(double d)
             23     {
             24         length = width = d;
             25         return *this;
             26     }
             27     operator double ()
             28     {
             29         return length * width;
             30     }
             31     Triangle& operator +=(const Triangle& t)
             32     {
             33         length += t.length;
             34         width  += t.width;
             35         return *this;
             36     }
             37     friend bool operator > (const Triangle& lhs, const Triangle& rhs);
             38     friend bool operator > (const Triangle& lhs, double rhs);
             39     friend bool operator > (double lhs,          const Triangle& rhs);
             40     friend istream& operator >>(istream& in,     Triangle& rhs);
             41     friend ostream& operator <<(ostream& out,    const Triangle& rhs);
             42 };
             43 
             44 bool operator >(const Triangle& lhs, const Triangle& rhs)
             45 {
             46     return lhs.length * lhs.width > rhs.length * rhs.width;
             47 }
             48 
             49 bool operator >(const Triangle& lhs, double rhs)
             50 {
             51     return lhs.length * lhs.width > rhs;
             52 }
             53 
             54 bool operator >(double lhs, const Triangle& rhs)
             55 {
             56     return lhs > rhs.length * rhs.width;
             57 }
             58 
             59 istream& operator >>(istream& in, Triangle& rhs)
             60 {
             61     in >> rhs.length >> rhs.width;
             62     if (!in)
             63     {
             64         cerr << "Input error!" << endl;
             65         exit(1);
             66     }
             67     return in;
             68 }
             69 
             70 ostream& operator <<(ostream& outconst Triangle& rhs)
             71 {
             72     out << rhs.length << '\t' << rhs.width;
             73     return out;
             74 }
             75 
             76 Triangle& operator +(const Triangle& lhs, const Triangle& rhs)
             77 {
             78     Triangle tmp(lhs);
             79     return tmp += rhs;
             80 }
             81 
             82 int main()
             83 {
             84     Triangle t1(1.02.0);
             85     Triangle t2;
             86     t1 = t2;
             87 
             88     cin >> t1 >> t2;
             89     cout << t1 << endl;
             90     cout << t2 << endl;
             91 
             92     t1 = t2;
             93     cout << t1 << endl;
             94     cout << t2 << endl;
             95 
             96     t1 = 10.0;
             97     cout << t1 << endl;
             98     double d = 0.0;
             99     d = t1;
            100     cout << d << endl;
            101 
            102     cout << (t1 > t2) << endl;
            103     cout << (t1 > 5.0<< endl;
            104     cout << (5.0 > t1) << endl;
            105 
            106     t1 += t2;
            107     cout << t1 << endl;
            108     cout << t2 << endl;
            109 
            110     return 0;
            111 }
            posted on 2011-04-29 00:40 unixfy 閱讀(211) 評論(0)  編輯 收藏 引用
            久久精品国产精品亚洲下载| 久久亚洲精品无码AV红樱桃| 伊人久久一区二区三区无码| 色88久久久久高潮综合影院 | 色欲综合久久中文字幕网| 久久久久高潮毛片免费全部播放 | 奇米影视7777久久精品人人爽 | 伊人久久五月天| 久久免费高清视频| 久久久久女人精品毛片| 亚洲va久久久久| 成人精品一区二区久久久| 一本久久a久久精品亚洲| 久久久精品人妻无码专区不卡| 久久99国产综合精品免费| 亚洲精品WWW久久久久久 | 亚洲国产精品久久久久| 久久婷婷五月综合97色一本一本| 99久久国产亚洲综合精品| 理论片午午伦夜理片久久 | 久久久久精品国产亚洲AV无码| 久久久久97国产精华液好用吗| 狠狠色丁香婷综合久久| 99国产精品久久| 久久亚洲精品中文字幕| 久久久久亚洲AV无码麻豆| 亚洲色大成网站WWW久久九九| 久久青青草视频| 亚洲色大成网站WWW久久九九| 久久久久av无码免费网| 波多野结衣久久一区二区| 久久乐国产综合亚洲精品| 久久强奷乱码老熟女网站| 成人综合久久精品色婷婷| 亚洲AV无一区二区三区久久| 国产A三级久久精品| 九九精品99久久久香蕉| 国产精品视频久久| 国产精品激情综合久久| 日本久久久久久久久久| 三级三级久久三级久久|