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

            天之道

            享受編程的樂(lè)趣。
            posts - 118, comments - 7, trackbacks - 0, articles - 0
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            實(shí)現(xiàn)四則運(yùn)算的小程序源代碼

            Posted on 2011-10-05 22:03 hoshelly 閱讀(1292) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): C++
             小累,國(guó)慶假期過(guò)去一大半,C++這時(shí)候才把遞歸和函數(shù)這一塊知識(shí)點(diǎn)慢慢地啃完了,結(jié)束之前,今晚自己寫(xiě)了一個(gè)小程序,實(shí)現(xiàn)四則運(yùn)算,適合小學(xué)生使用。
            程序說(shuō)明:
            1)允許用戶選擇一種類(lèi)型的算術(shù)問(wèn)題來(lái)學(xué)習(xí),輸入1表示加法,2表示減法,3表示乘法,4表示除法,5表示四種混合運(yùn)算;
            2)由于程序代碼中反復(fù)無(wú)窮遞歸,所以該程序的運(yùn)算會(huì)不斷進(jìn)行下去,退出請(qǐng)自動(dòng)關(guān)閉程序;

            源代碼如下:
            #include<iostream>
            #include
            <cstdlib>
            #include
            <ctime>
            using namespace std;
            int Mul(int,int);
            int Plus(int,int);
            int Sub(int,int);
            float Div(float,float);
            int main()
            {
                
            int a=0,b=0;
                
            int i;
                  srand(time(0));
                cout
            <<"What do you want to study?(1-Plus,2-Sub,3-Mul,4-division,5-all the above)"<<endl;
                cin
            >>i
                
            switch(i)
                
            {
                
            case 1:Plus(a,b);break;
                
            case 2:Sub(a,b);break;
                
            case 3:Mul(a,b);break;
                
            case 4:Div(a,b);break;
                
            case 5:switch(1+rand()%4)
                       
            {
                
            case 1:Plus(a,b);break;
                
            case 2:Sub(a,b);break;
                
            case 3:Mul(a,b);break;
                
            case 4:Div(a,b);break;
                
            default:break;
                       }
            break;

                
            default:break;
                }

                
            return 0;
            }

            float Div(float x,float y)
            {
                
            float m1, m;
                
            int k;
                k
            =1+rand()%4;
                
            int a1;
                cout
            <<"Please choose the level of this game(1 or 2):"<<endl;
                cin
            >>a1;
                srand(time(
            0));
                
            if(a1==1)
                
            {
                     x
            =1+rand()%9;
                    y
            =1+rand()%9;
                }

                
            if(a1==2)
                
            {
                    x
            =1+rand()%99;
                    y
            =1+rand()%99;
                }

                    m
            =x/y;
                cout
            <<x<<"/"<<y<<"=?"<<endl;
                cin
            >>m1;
                
            if(m1==m)
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Very good!"<<endl;break;
                    
            case 2:cout<<"Excellent!"<<endl;break;
                    
            case 3:cout<<"Nice work!"<<endl;break;
                    
            case 4:cout<<"Keep up the good work!"<<endl;break;
                    
            default:break;
                    }

                    Div(x,y);
                }

                
            else
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Sorry,your answer is wrong!"<<endl;break;
                    
            case 2:cout<<"Wrong.Try once again!"<<endl;break;
                    
            case 3:cout<<"Don't give up!"<<endl;break;
                    
            case 4:cout<<"No.Keep trying."<<endl;break;
                    
            default:break;
                    }

                    Div(x,y);
                }

                
            return 0;
            }



            int Sub(int x,int y)
            {
                    
            int m1, m,k;
                k
            =1+rand()%4;
                
            int a1;
                cout
            <<"Please choose the level of this game(1 or 2):"<<endl;
                cin
            >>a1;
                srand(time(
            0));
                
            if(a1==1)
                
            {
                     x
            =1+rand()%9;
                    y
            =1+rand()%9;
                }

                
            if(a1==2)
                
            {
                    x
            =1+rand()%99;
                    y
            =1+rand()%99;
                }

                    m
            =x-y;
                cout
            <<x<<"-"<<y<<"=?"<<endl;
                cin
            >>m1;
                
            if(m1==m)
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Very good!"<<endl;break;
                    
            case 2:cout<<"Excellent!"<<endl;break;
                    
            case 3:cout<<"Nice work!"<<endl;break;
                    
            case 4:cout<<"Keep up the good work!"<<endl;break;
                    
            default:break;
                    }

                    Sub(x,y);
                }

                
            else
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Sorry,your answer is wrong!"<<endl;break;
                    
            case 2:cout<<"Wrong.Try once again!"<<endl;break;
                    
            case 3:cout<<"Don't give up!"<<endl;break;
                    
            case 4:cout<<"No.Keep trying."<<endl;break;
                    
            default:break;
                    }

                    Sub(x,y);
                }

                
            return 0;
            }


            int Plus(int x,int y)
            {
                
            int m1, m,k;
                k
            =1+rand()%4;
                
            int a1;
                cout
            <<"Please choose the level of this game(1 or 2):"<<endl;
                cin
            >>a1;
                srand(time(
            0));
                
            if(a1==1)
                
            {
                     x
            =1+rand()%9;
                    y
            =1+rand()%9;
                }

                
            if(a1==2)
                
            {
                    x
            =1+rand()%99;
                    y
            =1+rand()%99;
                }

                    m
            =x+y;
                cout
            <<x<<"+"<<y<<"=?"<<endl;
                cin
            >>m1;
                
            if(m1==m)
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Very good!"<<endl;break;
                    
            case 2:cout<<"Excellent!"<<endl;break;
                    
            case 3:cout<<"Nice work!"<<endl;break;
                    
            case 4:cout<<"Keep up the good work!"<<endl;break;
                    
            default:break;
                    }

                    Plus(x,y);
                }

                
            else
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Sorry,your answer is wrong!"<<endl;break;
                    
            case 2:cout<<"Wrong.Try once again!"<<endl;break;
                    
            case 3:cout<<"Don't give up!"<<endl;break;
                    
            case 4:cout<<"No.Keep trying."<<endl;break;
                    
            default:break;
                    }

                    Plus(x,y);
                }

                
            return 0;
            }



            int Mul(int x,int y)
            {

                
            int m1, m,k;
                k
            =1+rand()%4;
                
            int a1;
                cout
            <<"Please choose the level of this game(1 or 2):"<<endl;
                cin
            >>a1;
                srand(time(
            0));
                
            if(a1==1)
                
            {
                     x
            =1+rand()%9;
                    y
            =1+rand()%9;
                }

                
            if(a1==2)
                
            {
                    x
            =1+rand()%99;
                    y
            =1+rand()%99;
                }

                    m
            =x*y;
                cout
            <<x<<"*"<<y<<"=?"<<endl;
                cin
            >>m1;
                
            if(m1==m)
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Very good!"<<endl;break;
                    
            case 2:cout<<"Excellent!"<<endl;break;
                    
            case 3:cout<<"Nice work!"<<endl;break;
                    
            case 4:cout<<"Keep up the good work!"<<endl;break;
                    
            default:break;
                    }

                    Mul(x,y);
                }

                
            else
                
            {
                    
            switch(k)
                    
            {
                    
            case 1:cout<<"Sorry,your answer is wrong!"<<endl;break;
                    
            case 2:cout<<"Wrong.Try once again!"<<endl;break;
                    
            case 3:cout<<"Don't give up!"<<endl;break;
                    
            case 4:cout<<"No.Keep trying."<<endl;break;
                    
            default:break;
                    }

                    Mul(x,y);
                }

                
                
            return 0;
            }



            小程序的壓縮版下載地址:http://ishare.iask.sina.com.cn/f/19626833.html

            Feedback

            # re: 實(shí)現(xiàn)四則運(yùn)算的小程序源代碼  回復(fù)  更多評(píng)論   

            2011-12-15 18:46 by 路過(guò)
            表示感謝
            久久久一本精品99久久精品88| 国产精品久久午夜夜伦鲁鲁| 九九久久自然熟的香蕉图片| 久久亚洲色一区二区三区| 少妇久久久久久被弄高潮| 免费一级欧美大片久久网| 久久中文娱乐网| 国内精品九九久久久精品| 欧美亚洲国产精品久久| 久久精品99无色码中文字幕| 国产美女久久久| 亚洲狠狠婷婷综合久久蜜芽| 亚洲精品美女久久久久99小说| 伊人丁香狠狠色综合久久| 久久久久亚洲AV成人片| 久久久噜噜噜久久中文字幕色伊伊| 精品久久久久久无码中文字幕| 久久97精品久久久久久久不卡| 亚洲AV日韩精品久久久久久久| 亚洲七七久久精品中文国产| 精品久久久久一区二区三区| 大美女久久久久久j久久| 99精品久久精品| 国产精品免费看久久久| 久久精品aⅴ无码中文字字幕不卡| 日韩欧美亚洲综合久久| 久久精品国产欧美日韩99热| 亚洲国产精品综合久久网络 | 一本色综合网久久| 伊人久久大香线蕉综合热线| 亚洲v国产v天堂a无码久久| 久久久久久亚洲精品不卡 | 日韩久久久久中文字幕人妻| 精品久久久久久无码中文字幕| 国产精品美女久久久久AV福利| 99久久国产综合精品五月天喷水 | 国产99久久久国产精品~~牛| 久久国产精品99久久久久久老狼| 99久久免费国产精精品| 久久综合九色综合97_久久久| 热99re久久国超精品首页|