系统包括加、减、乘、除四种基本运算,包含显示答卷、错题正解、系统评估、错题重做、退出系统五种功能,由七个小子函数和主函数构成。
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #include <ctype.h> 5 6 int sy[10],sr[10],jd[10],jg[10]; 7 int fs=0; 8 char fh[10]; 9 10 void division(int *s1,int *s2,int *s3); 11 void calculate(); 12 char menu(); 13 void evaluate(); 14 void answer(); 15 void Ranswer(); 16 void reform(); 17 18 void main() 19 { 20 int key=1; 21 calculate(); 22 while(key) 23 { 24 switch(menu()) 25 { 26 case '1': { printf(" "); answer(); } break; 27 case '2': { printf(" "); Ranswer(); } break; 28 case '3': { printf(" "); evaluate(); } break; 29 case '4': { printf(" "); reform(); } break; 30 case '0': { printf(" 您已退出四则运算系统,谢谢支持! ");key=0;} 31 } 32 } 33 } 34 35 36 void division(int *s1,int *s2,int *s3) 37 { 38 int i,b=1,c,jg; 39 int cs[20]={0},sy,sr; 40 srand( (unsigned)time( NULL ) ); 41 fa: sy=rand()%100; 42 if(sy==0) goto fa; 43 for(i=1;i<=sy;i++) 44 { 45 if(sy%i==0) { cs[b]=i; b++;} 46 else continue; 47 } 48 c=rand()%b; 49 if(c==0) c=c+1; 50 sr=cs[c]; 51 jg=sy/sr; 52 *s1=sy; 53 *s2=sr; 54 *s3=jg; 55 } 56 57 58 void calculate() 59 { 60 int p; 61 int i,gh; 62 printf("欢迎来到四则运算测试系统! 您将进行的是100以内数字的四则运算!Are you ready?Go! "); 63 srand( (unsigned)time( NULL ) ); 64 65 66 for(i=0;i<10;i++) 67 { 68 sy[i]=rand()%100; 69 sr[i]=rand()%100; 70 p=rand()%4; 71 72 if(p==0) 73 { fh[i]='+'; jg[i]=sy[i]+sr[i]; } 74 else if(p==1) 75 { fh[i]='-'; 76 if(sy[i]<sr[i]) { gh=sy[i]; sy[i]=sr[i];sr[i]=gh; } 77 jg[i]=sy[i]-sr[i]; 78 } 79 else if(p==2) 80 { fh[i]='*'; jg[i]=sy[i]*sr[i]; } 81 else if(p==3) 82 { 83 fh[i]='/'; 84 division(&sy[i],&sr[i],&jg[i]); 85 } 86 printf("第%2d题: %2d %c %2d = ",i+1,sy[i],fh[i],sr[i]); 87 88 scanf("%d",&jd[i]); 89 if(jd[i]==jg[i]) fs+=10; 90 } 91 printf(" 测试结束! "); 92 } 93 94 95 char menu() 96 { 97 char c='0'; 98 printf(" ************ 四则运算测试系统 ************** "); 99 printf(" 1.显示答卷 2.错题正解 "); 100 printf(" 3.系统评估 4.错题重做 "); 101 printf(" 0.退出系统 "); 102 printf(" ********************************************"); 103 printf(" 请输入选项(0-4):"); 104 do 105 { scanf("%c",&c); } 106 while(!(c>'0'&&c<='6')); 107 return c; 108 } 109 110 111 void evaluate() 112 { 113 printf("您的成绩是%d分. ",fs); 114 switch(fs) 115 { case 100: printf("Very good!不要骄傲哦! "); break; 116 case 90: printf("优秀!恭喜您取得了好成绩! "); break; 117 case 80: 118 case 70: printf("良好!请继续努力,下次取得更好的成绩! "); break; 119 case 60: printf("及格!成绩不太理想哟!再接再励吧! "); break; 120 case 50: 121 case 40: 122 case 30: 123 case 20: 124 case 10: printf("多花点功夫吧,不然你会后悔的!! "); break; 125 case 0: printf("太差劲了!再不努力的话,会后悔的哦!再做一次吧!!!! "); break; 126 } 127 printf(" "); 128 } 129 130 131 void answer() 132 { 133 int j; 134 printf("您的答卷为: "); 135 for(j=0;j<10;j++) 136 printf("%2d %c %2d = %2d ",sy[j],fh[j],sr[j],jd[j]); 137 printf(" "); 138 } 139 140 141 void Ranswer() 142 { 143 int k; 144 printf("您答错的题的正确答案为: "); 145 for(k=0;k<10;k++) 146 { if(jd[k]==jg[k]) continue; 147 else 148 { 149 printf("%2d %c %2d = %2d ",sy[k],fh[k],sr[k],jg[k]); 150 } 151 } 152 printf(" "); 153 } 154 155 156 void reform() 157 { 158 int m,n; 159 printf("以下是您做错的题,请重做: "); 160 for(m=0;m<10;m++) 161 if(jd[m]==jg[m]) continue; 162 else 163 { printf("%2d %c %2d =",sy[m],fh[m],sr[m]); 164 scanf("%d",&jd[m]); 165 if(jd[m]==jg[m]) printf("恭喜!您做对了! "); 166 else 167 { 168 for(n=0;n<3;n++) 169 { printf("仍未做对!您只有%d次机会了哦: ",2-n); 170 printf("%2d %c %2d =",sy[m],fh[m],sr[m]); 171 scanf("%d",&jd[m]); 172 if(jd[m]==jg[m]) { printf("恭喜!您做对了! "); break;} 173 } 174 175 } 176 } 177 printf(" "); 178 }