• <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 - 118, comments - 7, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

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

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

            2011-12-15 18:46 by 路過
            表示感謝
            伊人色综合久久天天| 人妻无码中文久久久久专区| 狠狠色伊人久久精品综合网| 久久久久久综合一区中文字幕 | 久久99国产精品久久久| 欧美777精品久久久久网| 久久精品二区| 看久久久久久a级毛片| 久久本道综合久久伊人| 欧美熟妇另类久久久久久不卡| 久久亚洲国产午夜精品理论片| 亚洲国产成人久久综合碰| 午夜天堂精品久久久久| 久久久久九九精品影院| www久久久天天com| 久久精品国产2020| 久久本道久久综合伊人| 国产精品久久免费| 少妇久久久久久久久久| 欧美日韩精品久久久久| 99久久亚洲综合精品成人| 久久午夜羞羞影院免费观看 | 久久精品人人槡人妻人人玩AV | 久久99国产精一区二区三区| 97久久国产露脸精品国产| 久久久久久一区国产精品| 99久久99久久| 久久婷婷五月综合色高清| 久久夜色精品国产亚洲av| 久久91亚洲人成电影网站| 久久水蜜桃亚洲av无码精品麻豆| 综合久久给合久久狠狠狠97色| 久久se精品一区二区影院| 久久亚洲国产中v天仙www | 久久中文字幕视频、最近更新| 蜜桃麻豆www久久| 久久精品成人免费网站| 99精品久久精品| 青青青国产精品国产精品久久久久| 久久天天躁狠狠躁夜夜网站| 波多野结衣中文字幕久久|