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

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

            一個(gè)簡(jiǎn)單的分?jǐn)?shù)類

            就是寫得太長(zhǎng)了 可以更精簡(jiǎn)些的
            #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 
            & ); //約分函數(shù)  
                  int gcd(int a,int b); //求最大公約數(shù)函數(shù)

            }
            ;  


            //類成員函數(shù)的定義 
              
            CFraction::CFraction(
            int fractionSon ,int fractionMother )  
            {  
             m_fractionSon 
            = fractionSon; //構(gòu)造函數(shù)不能有返回類型,
             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; //除以一個(gè)數(shù)等價(jià)于乘上這個(gè)數(shù)的倒數(shù)  
                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
            <<"請(qǐng)輸入分?jǐn)?shù)a的分子:"<<endl;
             cin
            >>ason;
             cout
            <<"請(qǐng)輸入分?jǐn)?shù)a的分母:"<<endl;
             cin
            >>amom;
             
            if ( amom == 0 )
             
            {
                 cout
            <<"分母不能為0!"<<endl;
                 
            return 0;
             }

             cout
            <<"請(qǐng)輸入分?jǐn)?shù)b的分子:"<<endl;
             cin
            >>bson;
             cout
            <<"請(qǐng)輸入分?jǐn)?shù)b的分母:"<<endl;
             cin
            >>bmom;
             
            if ( bmom == 0 )
             
            {
                 cout
            <<"分母不能為0!"<<endl;
                 
            return 0;
             }

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

             cout
            <<"分?jǐn)?shù) a = "<< a <<endl;  
             cout
            <<"分?jǐn)?shù) 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;  
            }
             


            轉(zhuǎn)自:http:
            //blog.csdn.net/marine_lich/archive/2008/05/15/2449778.aspx

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


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


            久久精品中文字幕第23页| 国产亚洲欧美精品久久久| 2020最新久久久视精品爱 | 久久婷婷五月综合97色直播| 久久精品一区二区三区中文字幕| 久久综合九色综合久99| 狠狠精品久久久无码中文字幕| 久久精品无码午夜福利理论片| 成人国内精品久久久久影院VR| 精品久久久久久久久久中文字幕| 久久天天婷婷五月俺也去| 色综合久久久久综合体桃花网| 日本福利片国产午夜久久| 久久99热这里只有精品66| 国产国产成人精品久久| 国产精品美女久久福利网站| 国内精品人妻无码久久久影院| 色播久久人人爽人人爽人人片aV| 日韩av无码久久精品免费| 久久精品亚洲乱码伦伦中文| 99久久久精品| 中文字幕久久波多野结衣av| 国产精品久久久99| 精品久久久久久综合日本| 性欧美大战久久久久久久| 亚洲一区中文字幕久久| 久久精品国产网红主播| 久久久久久久97| 天天影视色香欲综合久久| 狠狠久久综合| 狠狠综合久久综合中文88| 精品久久久久久中文字幕| 久久精品九九亚洲精品| 少妇人妻88久久中文字幕| 久久精品青青草原伊人| 怡红院日本一道日本久久 | 99久久99久久精品国产片| 久久无码人妻一区二区三区午夜| 久久久久久精品成人免费图片| 亚洲婷婷国产精品电影人久久| 免费一级欧美大片久久网|