四则运算02(附第三周进度条)

程序思想:

1.将随机数生成、加减符号生成、乘除符号生成、括号生成、储存分别用函数封装

2.判断是否有乘除,是否有负数,是否有余数、是否有括号、位数。

3.通过判断依次引用函数。

代码

using namespace std;

string *o;

int j=0,js=0;

int Rnum(int min,int max ) //randon number (digit)

{

    int random;

    srand(time(NULL));

    random=(rand()%(max-min+1))+min;

    return random;

}

char Ras(int judgemd )// add  subtraction multiplication division operator

    {

        int random;

        char operation;

        if(judgemd=2)random=Rnum(1,2);

        else random=Rnum(3,4);

        switch(random)

        {

            case(1):{operation='+';break;}

            case(2):{operation='-';break;}

            case(3):{operation='*';break;}

            case(4):{operation='/';break;}

 

        }

        return operation;

    }

bool Compare(string str)

{

    bool b=true;

    for(int i=0;i<j;i++)

    {

        if(str==o[i])

        b=false;

    }

    return b;

}

void Storage(string str)//string or 邻ⅷ?接ó表括?

{

    o[j]=str;

    j++;

}

void Asout (int judgen,int min,int max)// if here is not negaive it is true,else false

    {

        int num1,num2,num;

        char ope;

        string o="";

        num1= Rnum(min,max);

        num2= Rnum(min,max);

        ope=Ras(2);

        if(judgen==2)

        {

            if(ope=='-')

            {

                if(num1<num2)

                {

                num=num1;

                num1=num2;

                num2=num;

                }

            }

        }

        o=num1+ope+num2;

        if(Compare(o)==true)

        {

            Storage(o);

            js++;

        }

       

 

        //比括?较? 和í储洹?存?

        cout<<num1<<ope<<num2<<"="<<endl;

    }

void Mdout(int judger,int min,int max)//

    {

        int num1,num2,num;

        char ope;

        string o;

        num1= Rnum(min,max);

        num2= Rnum(min,max);

        ope=Ras(1);

        if(judger==2)

        {

            if(ope=='/')

            {

                num=num1*num2;

                num1=num;

            }

        }

        o=num1+ope+num2;

        if(Compare(o)==true)

        {

            Storage(o);

            js++;

        }

       

        //比括?较? 和í储洹?存?

        cout<<num1<<ope<<num2<<"="<<endl;

    }//没?写′完?

void Asmdout(int judgen,int judger,int min,int max)

    {

    Asout ( judgen, min, max);

    Mdout(judger, min, max);

    }

void Bracket(int judgemd,int min,int max)//it  has braket, randem digit.

    {

        int num;

        string o="",o1;

        num=Rnum(3,10);

        int *bnum;

        char *bope;

        bnum= new int[num];

        bope=new char[num-1];

        o="(";

        for(int i=0;i<num;i++)

        {

            bnum[i]=Rnum(min,max);

        }

        for(int i=0;i<num-1;i++).0

        {

            bope[i]=Ras(judgemd);

        }

        for(int i=0;i<num;i++)

        {

            cout<<bnum[i];

            o1=bnum[i];

            o= o +o1;

            if(i=2)o=o+")";

            if(i=num-1)break;

            cout<<bope[i];

            o=o+bope[i];

        }

        if(Compare(o)==true)

        {

            Storage(o);

            js++;

        }

       

    }

void main()

    {

         int judgeb,judgemd,judgen,judger=2,min,max,n;

         cout<<"Do you want multiplication and division? 1.Yes 2.No"<<endl;

         cin>>judgemd;

         cout<<"Do you want bracket? 1.Yes 2.No"<<endl;

         cin>>judgeb;

         if(judgeb==2)

         {

             cout<<"Do you want negative? 1.Yes 2.No"<<endl;

             cin>>judgen;

             if(judgemd==1)

             {

             cout<<"Do you want remainder? 1.Yes 2.No"<<endl;

             cin>>judger;

             }

         }

         cout<<"which is the scope of the number? input the min and max"<<endl;

         cin>>min>>max;

         cout<<"数簓量?"<<endl;

         cin>>n;

         o=new string[n];

         while(js<n)

         {

             if(judgeb==1){ Bracket(judgemd, min, max);};

             if(judgeb==2){Asmdout( judgen, judger, min, max);};

 

         }

 

    }

 

日期任务 听课 编写程序 阅读课本 准备考试     日统计   日期 开始时间 结束时间 中断时间 净时间 活动 备注
周日                 3.14 8:00 9:50 10 100 上课  
周一 100 60         160   3.15            
周二                 3.16 2:00 4:00   120 写程序  
周三   120         120   3.17            
周四                 3.18 7:15 9:30 15 120 写程序  
周五   120         120   3.19 8:00 10:00   120 写程序  
周六   120         120                
                               
日期 编号 引入阶段 排除阶段 修复时间 描述                    
3.18 1 编码 译码 10 调用函数放在了主函数后面                    
posted @ 2016-03-19 16:48  键盘已坏  阅读(166)  评论(0编辑  收藏  举报