c++四则运算

  • bYP5m787Oy
    了解作者
  • C/C++
    开发工具
  • 968B
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 2 积分
    下载积分
  • 0
    下载次数
  • 2022-12-04 03:57
    上传日期
非常适合期末大学生实训,需要的可以自取,欢迎大家
新建文件夹.zip
  • 新建文本文档.txt
    3.8KB
内容介绍
#include<iostream> #include<time.h> using namespace std; void additiveTest(int a) { int m,n,k=0,Qian,Hou; srand(time(0)); for(n=1;n<=a;n++){ cout<<(Qian=rand()%100)<<"+"<<(Hou=rand()%100)<<"="; cin>>m; if(Qian+Hou==m){ cout<<"正确!"<<endl; k=k+1; } else{ cout<<"错误!"<<endl; } } cout<<"答题正确数量为:"<<k<<endl; k=((100/a)*k); cout<<"答题正确分数为:"<<k<<"分"<<endl; } void subtractionTest(int a){ int m,n,zk=0,Qian,Hou; srand(time(0)); for(n=1;n<=a;n++){ cout<<(Qian=rand()%100)<<"-"<<(Hou=rand()%100)<<"="; cin>>m; if(Qian-Hou==m){ cout<<"正确!"<<endl; zk=zk+1; } else{ cout<<"错误!"<<endl; } } cout<<"答题正确数量为:"<<zk<<endl; zk=((100/a)*zk); cout<<"答题正确分数为:"<<zk<<"分"<<endl; } void multiplicationTest(int a){ int m,n,k=0,Qian,Hou; srand(time(0)); for(n=1;n<=a;n++){ cout<<(Qian=rand()%10)<<"*"<<(Hou=rand()%10)<<"="; cin>>m; if(Qian*Hou==m){ cout<<"正确!"<<endl; k=k+1; } else{ cout<<"错误!"<<endl; } } cout<<"答题正确数量为:"<<k<<endl; k=((100/a)*k); cout<<"答题正确分数为:"<<k<<"分"<<endl; } void divisionTest(int a){ int m,n,k=0,Qian,Hou; srand(time(0)); for(n=1;n<=a;n++){ cout<<(Qian=rand()%100)<<"/"<<(Hou=rand()%10)<<"="; cin>>m; if(Qian/Hou==m){ cout<<"正确!"<<endl; k=k+1; } else{ cout<<"错误!"<<endl; } } cout<<"答题正确数量为:"<<k<<endl; k=((100/a)*k); cout<<"答题正确分数为:"<<k<<"分"<<endl; } void mixedTest(int a){ int m,n,k=0,Qian,Hou; srand(time(0)); for(n=1;n<=a;n++){ if(n%4==0){ cout<<(Qian=rand()%100)<<"/"<<(Hou=rand()%10)<<"="; cin>>m; if(Qian/Hou==m){ cout<<"正确!"<<endl; k=k+1; } else{ cout<<"错误!"<<endl; } } if(n%4==1){ cout<<(Qian=rand()%10)<<"*"<<(Hou=rand()%10)<<"="; cin>>m; if(Qian*Hou==m){ cout<<"正确!"<<endl; k=k+1; } else{ cout<<"错误!"<<endl; } } if(n%4==2){ cout<<(Qian=rand()%100)<<"+"<<(Hou=rand()%100)<<"="; cin>>m; if(Qian+Hou==m){ cout<<"正确!"<<endl; k=k+1; } else{ cout<<"错误!"<<endl; } } if(n%4==3){ cout<<(Qian=rand()%100)<<"-"<<(Hou=rand()%100)<<"="; cin>>m; if(Qian-Hou==m){ cout<<"正确!"<<endl; k=k+1; } else{ cout<<"错误!"<<endl; } } } cout<<"答题正确数量为:"<<k<<endl; k=((100/a)*k); cout<<"答题正确分数为:"<<k<<"分"<<endl; } void showMenu(int a) { int b; if(a==1){ cout<<"现在开始两位数以内加法测试!"<<endl; cout<<"请输入需要测试的题数:"<<endl; cin>>b; additiveTest(b); } if(a==2){ cout<<"现在开始两位数以内减法测试!"<<endl; cout<<"请输入需要测试的题数:"<<endl; cin>>b; subtractionTest(b); } if(a==3){ cout<<"现在开始两位数以内乘法测试!"<<endl; cout<<"请输入需要测试的题数:"<<endl; cin>>b; multiplicationTest(b); } if(a==4){ cout<<"现在开始两位数以内除法测试!"<<endl; cout<<"请输入需要测试的题数:"<<endl; cin>>b; divisionTest(b); } if(a==5){ cout<<"现在开始两位数以内加、减、乘、除法测试!"<<endl; cout<<"请输入需要测试的题数:"<<endl; cin>>b; mixedTest(b); } if(a==6){ cout<<"现在已经退出!"<<endl; } } int main() { int x; while(x!=6){ cout<<"1、两位数以内加法测试!"<<endl; cout<<"2、两位数以内减法测试!"<<endl; cout<<"3、两位数以内乘法测试!"<<endl; cout<<"4、两位数以内除法测试!"<<endl; cout<<"5、两位数以内加、减、乘、除法测试!"<<endl; cout<<"6、退出!"<<endl; cout<<"请输入相应的测试对应的数字!"<<endl; cin>>x; showMenu(x); } }
评论
    相关推荐
    • C++ PRrimer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • c++课件
      c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件
    • C++
      C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
    • Effective C++
      学习c++的经典书籍!每一个学习c++的人有时间最好看看!你会获得很大收获!
    • c++information
      c++c++c++c++c++c++c++c++c++c++c++c++
    • SourceStyler C++
      用DEV-C++写代码很方便,就是不能格式化有点郁闷 c++格式化的好工具 效率高
    • c++yuyanbiancheng
      这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!
    • C++ primier
      学习C++的经典之作,希望大家学习愉快,快速掌握C++的各种知识。多下哈
    • effective C++
      有关C++编程方面的检验性介绍,对由C转向C++,和有C++编程基础的程序员有帮助,不过是英文版
    • effective c++
      C++经典书籍Effective C++ By Scott Meyers, 已译成中文,chm格式,方便检阅 Uploaded by save (chaisave@sohu.com)