zoukankan      html  css  js  c++  java
  • 四则运算3

    工作照片:

    小组成员:
    李国帅,陈鹏
    设计思路:
    在2的基础上添加一个选择,使用递归来得到多项式。
    源代码:

    //
    四则运算 //2015.3.19 #include <iostream> #include <string> using namespace std; int t=0; //确定四则运算符号 char Judge3( int x) { char a; if(x==0) a='+'; if(x==1) a='-'; if(x==2) a='*'; if(x==3) a='/'; return a; } //确定得数 int Judge4(int a,int b,int c) { int d; if(b==0) d=a+c; if(b==1) d=a-c; if(b==2) d=a*c; if(b==3) d=a/c; return d; } //判断一个数是否为1或2 void Judge(int o) { for(int q=0;;q++) { if(o!=1||o!=2) { cout<<"输入错误!请重新输入(1或2):"<<endl; cin>>o; } else break; } } void Judge1(int a,int b,int c,int d) { int answer; cout<<a<<Judge3(b)<<c<<"=___"<<endl; cout<<"请输入正确答案:"; cin>>answer; if(answer==Judge4(a,b,c)) { cout<<" 正确"<<endl; d=+1; } } int Judge5(int a,int b ) { cout<<a<<Judge3(b); return 0; } int main() { int i=0,j,n,m,v,answer,p,l,k,a[100],b[100],c[100]; cout<<"请输入题目数(题目数为大于0的整数):"<<endl; cin>>j; for(int q=0;;q++) { if(j==0) { cout<<"输入错误,请重新输入题目数(题目数为大于0的整数):"<<endl; cin>>j; } else break; } cout<<"数值范围(例:输入1 99 则数值范围为1-99):"<<endl; cin>>m>>n; cout<<"请选择运算方式:"; cout<<"1.简单运算"<<endl; cout<<"2.复杂运算"<<endl; cin>>v; if(v==1) { cout<<"是否有乘除法,若有则选1,没有则选2"<<endl; cin>>k; if(k==1) { cout<<"是否有负数,若有则选1,没有则选2"<<endl; cin>>l; //Judge(l); cout<<"除法有无余数,若有余数则选1,没有则选2"<<endl; cin>>p; //Judge(p); cout<<"输出的题目是:"<<endl; for(i=0;i<j;i++) { //产生随机数 a[i]=rand()%(n-m+1)+m; b[i]=rand()%4; c[i]=rand()%(n-m+1)+m; if(b[i]==0) { Judge1(a[i],b[i],c[i],t); } if(b[i]==1) { if(l==1) { Judge1(a[i],b[i],c[i],t); } else { if(a[i]>c[i]) { Judge1(a[i],b[i],c[i],t); } else { Judge1(c[i],b[i],a[i],t); } } } if(b[i]==2) { Judge1(a[i],b[i],c[i],t); } if(b[i]==3) { if(p==1) { if(c[i]!=0) { Judge1(a[i],b[i],c[i],t); } else { for(int y=0;;y++){ c[i]=rand()%(n-m+1)+m; if(c[i]!=0) break; } Judge1(a[i],b[i],c[i],t); } } else { if(c[i]!=0&&a[i]%c[i]==0) { Judge1(a[i],b[i],c[i],t); } else { for(int y=0;;y++){ a[i]=rand()%(n-m+1)+m; c[i]=rand()%(n-m+1)+m; if(c[i]!=0&&a[i]%c[i]==0) break; } Judge1(a[i],b[i],c[i],t); } } } } cout<<"答对题目的个数是:"<<t<<""; } else { cout<<"是否有负数,若有负数则选1,否则选2"<<endl; cin>>l; cout<<"输出的题目是:"<<endl; for(i=0;i<j;i++) { //产生随机数 a[i]=rand()%(n-m+1)+m; b[i]=rand()%2; c[i]=rand()%(n-m+1)+m; if(b[i]==0){ Judge1(a[i],b[i],c[i],t); } if(b[i]==1) { if(l==1) { Judge1(a[i],b[i],c[i],t); } else { if(a[i]>c[i]) { Judge1(a[i],b[i],c[i],t); } else { Judge1(c[i],b[i],a[i],t); } } } } } } //复杂运算 else { string u,h; for(i=0;i<j;i++) { c[i]=rand()%(n-m+1)+m; int num;//定义复杂运算的项 num=rand()%10;//随机产生复杂运算的项数 for(int y=0;y<num;y++) { //产生随机数 a[y]=rand()%(n-m+1)+m; b[y]=rand()%4; if(b[y]==3&&b[y-1]==3) { cout<<"("<<a[y]<<Judge3(b[y]); cout<<a[y-1]<<")"<<Judge3(b[y-1]); } else cout<<a[y]<<Judge3(b[y]); } cout<<c[i]<<"=___"<<endl; } } return 0; }
    结果截图:


    项目计划总结表:

    任务

    日期

    听课 编程 阅读课本 准备考试     日总计
    周日              
    周一 100 0 0 0     100
    周二 0 0 0 0     0
    周三 0 33 0 0     33
    周四 0 0 0 0     0
    周五 0 36 0 0     36
    周六 0 450 0 0     450
    周总计 100 519 0 0     619

    事件记录日志:

    日期 开始时间 结束时间 中断时间 净时间(分钟) 活动
    备注
    3.21 8:00 9:50 10 100 上课  
    3.23 5:32 6:05   33 编程  
    3.25 4:52 5:28   36 编程  
    3.26

    8:05

    1:35

    12:32

    4:40

      450 编程  

    错误:

    日期 错误
    3.26
  • 相关阅读:
    springboot 前后端分离开发 从零到整(三、登录以及登录状态的持续)
    鼠标跟随
    sublime_text编辑器下载安装使用
    实现el-dialog的拖拽,全屏,缩小功能
    vue 动态添加路由 require.context()
    Vue JsonView 树形格式化代码插件
    利用vue-gird-layout 制作可定制桌面 (二)
    利用vue-gird-layout 制作可定制桌面 (一)
    通过js 实现 向页面插入js代码并生效,和页面postMessage通讯
    简单实现一个ES5 Vue Dialog 插件
  • 原文地址:https://www.cnblogs.com/liguoshuai/p/5323590.html
Copyright © 2011-2022 走看看