• <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++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
             小累,國(guó)慶假期過去一大半,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)行下去,退出請(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 路過
            表示感謝
            一级做a爰片久久毛片看看| 久久香综合精品久久伊人| 无码人妻久久一区二区三区免费丨 | 噜噜噜色噜噜噜久久| 东京热TOKYO综合久久精品| 九九精品久久久久久噜噜| 免费精品99久久国产综合精品| 精品久久亚洲中文无码| 久久99久久成人免费播放| 精品久久久久久久久中文字幕| 久久久久精品国产亚洲AV无码| 精品久久国产一区二区三区香蕉 | 亚洲色欲久久久久综合网| 四虎国产永久免费久久| 久久AV高清无码| 日韩久久久久久中文人妻| 欧美精品九九99久久在观看| 国产AⅤ精品一区二区三区久久| 久久久无码精品亚洲日韩蜜臀浪潮| 久久毛片一区二区| 久久综合色之久久综合| 九九热久久免费视频| 日韩精品久久久久久| 久久精品国内一区二区三区| 老司机国内精品久久久久| 成人妇女免费播放久久久| 久久棈精品久久久久久噜噜| 无码精品久久久久久人妻中字| 国内精品九九久久精品| 久久99精品久久久大学生| 成人久久免费网站| 伊人久久大香线焦AV综合影院| 青青草原综合久久大伊人| 久久这里有精品| 亚洲香蕉网久久综合影视| 亚洲国产精品无码久久| 久久亚洲AV成人无码电影| 精品熟女少妇a∨免费久久| 久久精品国产亚洲av日韩| 久久精品国产亚洲αv忘忧草| 久久精品一本到99热免费|