• 四则运算03(附第四周进度条)


    设计思想:

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

    2.用判断来进行运算,多个数的存在链中,先算乘除,后算加减。

    3.用一个全局变量来记数答对多少。

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

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

    设计思想:
    1.将随机数生成、加减符号生成、乘除符号生成、括号生成、储存分别用函数封装
    2.用判断来进行运算,多个数的存在链中,先算乘除,后算加减。
    3.用一个全局变量来记数答对多少。
    4.判断是否有乘除,是否有负数,是否有余数、是否有括号、位数。
    5.通过判断依次引用函数。
    
    源程序
    #include<iostream>
    #include"string"
    #include<time.h>
    #include<stack>
    #define M 10;
    using namespace std;
    string *o;
    int j=0,js=0,correct=0;
    int Rnum(int min,int max ) //randon number (digit)
    {
        int random;
        
        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 num,num1,num2,num3;
            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++;
            }
            
            if(ope=='+')
            {
                num=num1+num2;
            }
            else
            {
                num=num1-num2;
            }
            //比括?较? 和í储洹?存?
            cout<<num1<<ope<<num2<<"=";
            cin>>num3;
            if(num3==num){cout<<"回?答鋏正y确ā?<<endl;correct++;}
            else {cout<<"正y确ā?答鋏案?为a"<<num<<endl;}
        }
    void Mdout(int judger,int min,int max)//
        {
            int num1,num2,num,num3,remainder,remainder2;
            char ope;
            string o;
            num1= Rnum(min,max);
            num2= Rnum(min,max);
            ope=Ras(1);
            if(ope=='/')
            {
                if(num2==0) {num2=Rnum(min,max);}
                else if(judger==2)
                {
                    num=num1*num2;
                    num1=num;
                }
                else
                {
                remainder=num1%num2;
                }
            }
            o=num1+ope+num2;
            if(Compare(o)==true)
            {
                Storage(o);
                js++;
            }
            if(ope=='*')
            {
                num=num1*num2;
                cout<<num1<<ope<<num2<<"=";
                cin>>num3;
                if(num3==num){cout<<"回?答鋏正y确ā?<<endl;correct++;}
            else {cout<<"正y确ā?答鋏案?为a"<<num<<endl;}
            }
            else
            {
                num=num1/num2;
                cout<<num1<<ope<<num2<<"=";
                if(remainder==0)
                {
                cin>>num3;
                if(num3==num){cout<<"回?答鋏正y确ā?<<endl;correct++;}
                else {cout<<"正y确ā?答鋏案?为a"<<num<<endl;}
                }
                else
                {
                cout<<"商Θ?为a";
                cin>>num3;
                cout<<"余�?数簓为a";
                cin>>remainder2;
                if(num3==num&&remainder==remainder2){cout<<"回?答鋏正y确ā?<<endl;correct++;}
                else {cout<<"正y确ā?答鋏案?为a"<<num<<"余�?数簓"<<remainder<<endl;}
                }
            }
            //比括?较? 和í储洹?存?
            
            
        }
    int Asmdout(int judgemd,int judgen,int judger,int min,int max)
        {
            if(judgemd==2)
            {
                Asout ( judgen, min, max);
            }
            else
            { 
                if(Rnum(1,2)==1)
                {
                Asout ( judgen, min, max);
                }
                else
                {
                Mdout(judger, min, max);
                }
            }
            return 0;
        }
    int Bracket(int judgemd,int min,int max)//it  has braket, randem digit.
        {
            int num,sum;
            num=Rnum(3,10);
            int *bnum;
            char *bope;
            typedef struct Num
            {
             //struct Num *prior;
             struct Num *next;
            int data;
            }Num,*Nlist;
            typedef struct Ope
            {
             //struct Ope *prior;
             struct Ope *next;
             char data;
            }Ope,*Olist;
            Nlist n=new Num;
            n->next=NULL;
            Nlist ir=n;
            Nlist ip;
            Olist o=new Ope;
            o->next=NULL;
            Olist cr=o;
            Olist cp;
            bnum= new int[num];
            bope=new char[num-1];
            for(int i=0;i<num;i++)
            {
                bnum[i]=Rnum(min,max);
                ip= new Num;
                ip->data=bnum[i];
                ip->next=NULL;
                ir->next=ip;
                ir=ip;
            }
            for(int i=0;i<num-1;i++)
            {
                bope[i]=Ras(Rnum(1,2));
                cp= new Ope;
                cp->data=bope[i];
                cp->next=NULL;
                cr->next=cp;
                cr=cp;
            }
    
            cp=o;ip=n;
            for(int i=0;i<num-1;i++)
            {
                if(cp->next->data=='*')
                {
                cr=cp;ir=ip;
                cr->next=cr->next->next;
                ir->next->data=ir->next->data*ir->next->next->data;
                ir->next->next=ir->next->next->next;
                continue;
                }
                if(cp->next->data=='/')
                {
                cr=cp;ir=ip;
                cr->next=cr->next->next;
                ir->next->data=ir->next->data/ir->next->next->data;
                ir->next->next=ir->next->next->next;
                continue;
                }
                cp=cp->next;
                ip=ip->next;
                if(cp->next->next==NULL) break;
            }
    
            cp=o;ip=n;
            for(int i=0;i<num-1;i++)
            {
                
                if(cp->next->data=='+')
                {
                cr=cp;ir=ip;
                cr->next=cr->next->next;
                ir->next->data=ir->next->data + ir->next->next->data;
                ir->next->next=ir->next->next->next;
                continue;
                }
                 if(cp->next->data=='-')
                {
                cr=cp;ir=ip;
                cr->next=cr->next->next;
                ir->next->data=ir->next->data - ir->next->next->data;
                ir->next->next=ir->next->next->next;
                continue;
                }
                cp=cp->next;
                ip=ip->next;
    
                if(cp->next->next==NULL) break;
            }
            for(int i=0;i<num;i++)
            {
                cout<<bnum[i];
                if(i==num-1){break;}
                cout<<bope[i];
            }
            
            js++;
            cout<<"=";
            cin>>sum;
            if(sum==n->next->data){cout<<"回?答鋏正y确ā?<<endl;correct++;}
            else{cout<<"回?答鋏错洙?误ó";}
            delete bnum,bope,ip,ir,cp,cr;
            return 0;
        }
    
    
    int main()
        {
            srand(time(NULL));
             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(judgemd, judgen, judger, min, max);};
    
             }
             cout<<"共2答鋏对?"<<correct<<"道台?题琣"<<endl;
             return 0;
        }

    日期任务 听课 编写程序 阅读课本 准备考试     日统计   日期 开始时间 结束时间 中断时间 净时间 活动 备注
    周日                 3.21 8:00 9:50 10 100 上课  
    周一 100 60         160   3.22            
    周二                 3.23 2:00 4:00   120 写程序  
    周三   120         120   3.24            
    周四                 3.25 7:15 9:30 15 120 写程序  
    周五   120         120   3.26 2:20 19:35 500 360 写程序  
    周六   360         360                
                                   
    日期 编号 引入阶段 排除阶段 修复时间 描述                    
    3.26 1 编码 译码   运用指针时,未知错误导致异常。                    
  • 相关阅读:
    CocoaPods使用详细说明
    cocoapod使用
    Android-利用LinearGradient实现文字一闪一闪
    Android5.0 CheckBox颜色修改
    android实现文字渐变效果和歌词进度的效果
    Ceph 常规操作笔记
    Git版本控制器使用总结性梳理
    CentOS 7.5 部署 MySQL 5.7 基于GTID主从复制+并行复制+半同步复制+读写分离(ProxySQL) 环境- 运维笔记 (完整版)
    Ansible-playbook 运维笔记
    Docker容器基础介绍
  • 原文地址:https://www.cnblogs.com/zuhaoran/p/5323803.html
Copyright © 2020-2023  润新知