• <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 路過
            表示感謝
            国内精品人妻无码久久久影院| 国产精品久久久久久福利69堂| 久久久国产视频| 国产成人久久精品麻豆一区| 国内精品综合久久久40p| 亚洲人成电影网站久久| 久久九九久精品国产免费直播| 亚洲精品乱码久久久久久按摩 | 亚洲伊人久久成综合人影院 | 亚洲精品乱码久久久久久| 国产成人精品综合久久久| 久久婷婷五月综合色高清| 久久中文精品无码中文字幕| 777米奇久久最新地址| 91超碰碰碰碰久久久久久综合| 欧美成人免费观看久久| 色偷偷88888欧美精品久久久| 精品久久香蕉国产线看观看亚洲| 久久天天躁狠狠躁夜夜2020一 | 国产成人久久精品一区二区三区| 久久夜色精品国产噜噜麻豆 | 久久久久国产精品麻豆AR影院| 香蕉aa三级久久毛片| 精品蜜臀久久久久99网站| 久久性精品| 69久久夜色精品国产69| 久久久久久久91精品免费观看| 精品久久久久久久| 波多野结衣AV无码久久一区| 丁香久久婷婷国产午夜视频| 日韩人妻无码精品久久久不卡| 国产精品成人精品久久久| 国产高潮国产高潮久久久| 天天躁日日躁狠狠久久| 亚洲七七久久精品中文国产| 天天久久狠狠色综合| 99久久国产亚洲高清观看2024| 人妻精品久久久久中文字幕一冢本| 久久人人超碰精品CAOPOREN| 久久―日本道色综合久久| 人妻少妇久久中文字幕|