• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            實現四則運算的小程序源代碼

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

            源代碼如下:
            #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: 實現四則運算的小程序源代碼  回復  更多評論   

            2011-12-15 18:46 by 路過
            表示感謝
            国产成人久久AV免费| 亚洲人AV永久一区二区三区久久| 国产激情久久久久影院| 国产韩国精品一区二区三区久久| 久久久久久久久久久久久久| 国产激情久久久久影院小草| 四虎国产精品免费久久久| 97热久久免费频精品99| 69国产成人综合久久精品| 999久久久免费精品国产| 久久九九有精品国产23百花影院| 精品免费久久久久久久| 久久91综合国产91久久精品| 久久久久久久99精品免费观看| 国产精品天天影视久久综合网| 精品久久久久久久| 国产AⅤ精品一区二区三区久久| 99久久精品久久久久久清纯| 久久人人爽人人澡人人高潮AV | 欧美激情精品久久久久久久九九九| 亚洲国产二区三区久久| 精品久久综合1区2区3区激情 | 国产激情久久久久影院| 久久乐国产精品亚洲综合| 中文字幕无码久久人妻| 久久久国产精品亚洲一区| 精品久久久无码中文字幕| 精产国品久久一二三产区区别| 亚洲精品乱码久久久久久自慰| 国产美女久久精品香蕉69| 亚洲国产成人久久综合碰碰动漫3d | 久久国产亚洲精品无码| 99久久精品无码一区二区毛片 | 伊人久久国产免费观看视频| 亚洲中文久久精品无码ww16| 国产精品久久国产精麻豆99网站| 狠狠精品久久久无码中文字幕| 久久婷婷色香五月综合激情| 久久久久99精品成人片直播| 久久天天躁狠狠躁夜夜2020| 久久精品aⅴ无码中文字字幕重口|