设计思路:随机两个两位数,再随机产生一个+-*/符号,连接两个数。将正确答案存和答案比较,用来判断正误。
代码:
1 #include<iostream.h> 2 #include<stdlib.h> 3 #include<time.h> 4 void boom() 5 { 6 float x,y; 7 int a,b; 8 int first_num,second_num; 9 srand(time(NULL)); 10 int n; 11 float k; 12 float d; 13 float daan[100]; 14 int zq=0; 15 int cw=0; 16 cout<<"输入题目数量:"<<endl; 17 cin>>n; 18 for(int i=0;i<n;i++) 19 { 20 21 a=rand()%4; 22 first_num=rand()%100; 23 second_num=rand()%100; 24 a=rand()%4; 25 switch(a) 26 { 27 case 0: 28 cout<<i+1<<"、 "<<first_num<<"+"<<second_num<<"="<<" "; 29 daan[i+1]=first_num+second_num; 30 break; 31 case 1: 32 cout<<i+1<<"、 "<<first_num<<"*"<<second_num<<"="<<" "; 33 daan[i+1]=first_num*second_num; 34 break; 35 case 2: 36 if(first_num>second_num) 37 {cout<<i+1<<"、 "<<first_num<<"-"<<second_num<<"="<<" "; 38 daan[i+1]=first_num-second_num; 39 } 40 else{ 41 i=i-1; 42 } 43 daan[i+1]=first_num-second_num; 44 break; 45 case 3: 46 47 if(y!=0&&first_num>second_num&&first_num%second_num==0) 48 { 49 cout<<i+1<<"、 "<<first_num<<"/"<<second_num<<"="<<" "; 50 } 51 else 52 { 53 i=i-1; 54 } 55 daan[i+1]=first_num/second_num; 56 break; 57 } 58 if((i+1)%3==0) 59 { 60 for(int c=0;c<=1;c++) 61 { 62 cout<<endl; 63 } 64 } 65 if((i+1)==n) 66 { 67 cout<<endl; 68 } 69 } 70 for(i=1;i<=n;i++) 71 { 72 cout<<"请答题:"<<endl; 73 cout<<i<<"、"; 74 cin>>d; 75 if(d==daan[i]) 76 { 77 cout<<"回答正确!"<<endl; 78 cout<<endl; 79 zq=zq+1; 80 } 81 else 82 { 83 cout<<"回答错误,正确答案为:"<<" "<<daan[i]<<endl; 84 cout<<endl; 85 cw=cw+1; 86 } 87 } 88 k=(float)zq/n; 89 cout<<"答对数为:"<<" "<<zq<<"个"<<endl; 90 cout<<"答错数为:"<<" "<<cw<<"个"<<endl; 91 cout<<"正确率为:"<<" "<<k<<endl; 92 } 93 int main() 94 { 95 boom(); 96 main(); 97 return 0; 98 }
项目计划总结:
运行截图
团队皂片: