• <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>

            The Fourth Dimension Space

            枯葉北風寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢令

            一個簡單的分數類

            就是寫得太長了 可以更精簡些的
            #include <iostream>  
            using namespace std; 
            class CFraction 
            {  
               
            private:  
                  
            int m_fractionSon; //分子  
                  int m_fractionMother; //分母  

                  friend ostream 
            &operator<<(ostream &output,const CFraction &fraction)  
                  
            {  
                     output
            <<fraction.m_fractionSon<<"/"<<fraction.m_fractionMother<<endl;  
                     
            return output;  
                  }

              
                  friend istream 
            &operator>>(istream &input, CFraction &fraction)  
                  
            {  
                     input
            >>fraction.m_fractionSon;  
                     input
            >>fraction.m_fractionMother;  
                     
            return input;  
                  }
             

               
            public:
                  CFraction(
            int=1 ,int=1 );    
                  
            const CFraction operator+const CFraction & );  
                  
            const CFraction operator-const CFraction & );  
                  
            const CFraction operator*const CFraction & );  
                  
            const CFraction operator/const CFraction & );   
                  
            bool operator<const CFraction & );  
                  
            bool operator>const CFraction & );  
                  
            bool operator==const CFraction & );  
                  
            bool operator!=const CFraction & );    
                  CFraction Easiest(CFraction 
            & ); //約分函數  
                  int gcd(int a,int b); //求最大公約數函數

            }
            ;  


            //類成員函數的定義 
              
            CFraction::CFraction(
            int fractionSon ,int fractionMother )  
            {  
             m_fractionSon 
            = fractionSon; //構造函數不能有返回類型,
             m_fractionMother = fractionMother;
            }
             

            const CFraction CFraction::operator+const CFraction &rightNumber )  

               CFraction resultValue;  
               resultValue.m_fractionSon 
            = m_fractionSon * rightNumber.m_fractionMother + m_fractionMother * rightNumber.m_fractionSon;  
               resultValue.m_fractionMother 
            = m_fractionMother * rightNumber.m_fractionMother;  
               
            return Easiest( resultValue );  
            }
             

            const CFraction CFraction::operator-const CFraction &rightNumber )  

                CFraction resultValue;  
                resultValue.m_fractionSon 
            = m_fractionSon * rightNumber.m_fractionMother - m_fractionMother * rightNumber.m_fractionSon;  
                resultValue.m_fractionMother 
            = m_fractionMother * rightNumber.m_fractionMother; 
                
            return Easiest( resultValue );  
            }


            const CFraction CFraction:: operator*(const CFraction &rightNumber )  

                CFraction resultValue;  
                resultValue.m_fractionSon 
            = m_fractionSon * rightNumber.m_fractionSon;  
                resultValue.m_fractionMother 
            = m_fractionMother * rightNumber.m_fractionMother;  
                
            return Easiest( resultValue );  
            }
              

            const CFraction CFraction::operator/const CFraction &rightNumber )  

                CFraction resultValue;  
                resultValue.m_fractionSon 
            = m_fractionSon * rightNumber.m_fractionMother;  
                resultValue.m_fractionMother 
            = m_fractionMother * rightNumber.m_fractionSon; //除以一個數等價于乘上這個數的倒數  
                return Easiest( resultValue );  
            }


            bool CFraction::operator<const CFraction &rightNumber ) 
            {  
              
            int leftNumberFractionSon,rightNumberFractionSon;
              leftNumberFractionSon 
            = m_fractionSon * rightNumber.m_fractionMother;
              rightNumberFractionSon 
            = rightNumber.m_fractionSon * m_fractionMother;
              
            if ( leftNumberFractionSon < rightNumberFractionSon )
              
            {
                  
            return true;
              }
             
              
            else
              
            {
                  
            return false;
              }

            }
              

            bool CFraction::operator>const CFraction &rightNumber)  
            {  
              
               
            int leftNumberFractionSon,rightNumberFractionSon;
               leftNumberFractionSon 
            = m_fractionSon * rightNumber.m_fractionMother;
               rightNumberFractionSon 
            = rightNumber.m_fractionSon * m_fractionMother;
               
            if ( leftNumberFractionSon > rightNumberFractionSon )
               
            {
                  
            return true;
               }
             
               
            else
               
            {
                  
            return false;
               }


            }
             

            bool CFraction::operator==const CFraction &rightNumber ) 
            {  
                
            int leftNumberFractionSon,rightNumberFractionSon;
                leftNumberFractionSon 
            = m_fractionSon * rightNumber.m_fractionMother;
                rightNumberFractionSon 
            = rightNumber.m_fractionSon * m_fractionMother;
                
            if ( leftNumberFractionSon == rightNumberFractionSon )
                
            {
                  
            return true;
                }
             
                
            else
                
            {
                  
            return false;
                }

              
            }
             

            CFraction CFraction::Easiest( CFraction 
            &fraction )  
            {  
               
            int getgcd = gcd(fraction.m_fractionSon, fraction.m_fractionMother);
               CFraction value(fraction.m_fractionSon
            /getgcd, fraction.m_fractionMother/getgcd);
               
            return value;
            }
               

            int CFraction::gcd(int a,int b)
            {
             
            while(b)
             
            {
              
            int temp = b;
              b 
            = a%b;
              a 
            = temp;
             }

             
            return a;
            }

             
            int main()
            {  
             
            int ason, amom, bson, bmom;
             cout
            <<"請輸入分數a的分子:"<<endl;
             cin
            >>ason;
             cout
            <<"請輸入分數a的分母:"<<endl;
             cin
            >>amom;
             
            if ( amom == 0 )
             
            {
                 cout
            <<"分母不能為0!"<<endl;
                 
            return 0;
             }

             cout
            <<"請輸入分數b的分子:"<<endl;
             cin
            >>bson;
             cout
            <<"請輸入分數b的分母:"<<endl;
             cin
            >>bmom;
             
            if ( bmom == 0 )
             
            {
                 cout
            <<"分母不能為0!"<<endl;
                 
            return 0;
             }

             CFraction a(ason,amom);  
             CFraction b(bson,bmom);  

             cout
            <<"分數 a = "<< a <<endl;  
             cout
            <<"分數 b = "<< b <<endl;   
                
             cout
            <<"a+b="<< a+<<endl;  
             cout
            <<"a-b="<< a-<<endl;  
             cout
            <<"a*b="<< a*<<endl;  
             cout
            <<"a/b="<< a/<<endl;  
              
             
            if(a>b)  
             cout
            <<"a大于b"<<endl;  
             
            else if (a<b)  
             cout
            <<"a小于b."<<endl;   
             
            else if(a==b)  
             cout
            <<"a等于b."<<endl;  
             
            return 0;  
            }
             


            轉自:http:
            //blog.csdn.net/marine_lich/archive/2008/05/15/2449778.aspx

            posted on 2010-04-16 18:09 abilitytao 閱讀(247) 評論(0)  編輯 收藏 引用

            欧美日韩精品久久久免费观看| 人妻精品久久无码专区精东影业| 久久精品男人影院| 精品久久久久久99人妻| 久久久久噜噜噜亚洲熟女综合| 一本久久a久久精品综合香蕉| 伊人久久成人成综合网222| 伊人 久久 精品| 久久精品国产亚洲综合色| 久久久99精品成人片中文字幕 | 久久伊人精品一区二区三区| 欧美一级久久久久久久大| 久久久久99精品成人片直播| 国产福利电影一区二区三区,免费久久久久久久精 | 国产成人精品三上悠亚久久| 99久久精品国内| 久久性精品| 岛国搬运www久久| 99久久无色码中文字幕人妻| 国产亚州精品女人久久久久久| 无码人妻久久一区二区三区免费丨| 久久亚洲欧美日本精品| 亚洲国产精品一区二区久久hs| 欧美一区二区精品久久| 久久AV高潮AV无码AV| 久久久久婷婷| 精品久久久久久国产免费了| 99国产欧美久久久精品蜜芽| 一本色道久久综合狠狠躁| 亚洲国产成人精品91久久久| 国产精品伊人久久伊人电影| 国内精品伊人久久久久| 中文字幕乱码久久午夜| 香蕉久久久久久狠狠色| 久久99精品国产麻豆蜜芽| 亚洲伊人久久大香线蕉苏妲己| 国产精品美女久久久m| 久久久女人与动物群交毛片| 久久亚洲精品无码AV红樱桃| 日韩久久久久久中文人妻| 中文字幕热久久久久久久|