Experimental Class Task 4-1: Pupil Calculator

mac2025-09-05  13

Experimental Class Task 4-1: Pupil Calculator

Task requirements

1.The “computer-aided teaching system for primary school students” is reprogrammed by the modular programming method. Requirements: (1) Display the menu in the main function in the following format: 1.Task 1: Randomly produces positive integers between 1-10, with multiplication questions until the student answers correctly. * * 2. Task 2: On the basis of Task 1, students are given up to three chances when they answer the wrong question. * * 3. Task 3: On the basis of task 1, even do 10 multiplication questions, do not give the opportunity to redo, statistics total score, correct rate. * * 4. Task 4: On the basis of Task 3, 10 four-way calculation questions are randomly generated, not given the opportunity to redo, and the total score and correctness rate are calculated. * * 5. Task 5: On the basis of Task 4, if the answer accuracy is less than 75%, then 10 questions are done, until the correct rate is higher than 75%. * * 6. Quits Require the menu to be used repeatedly until exit is selected. (2) At least the following functions are included: . Each task is encapsulated as one function. Create a random number function. The score statistics function (with the function of total statistical score and correct calculation rate). Determine if the answer is the correct function. For division, determine whether the resulting random number is legal. (Selected)

Because the program is not very long, the function is encoded first

Compilation interface

#include<stdio.h> #include<stdlib.h> #include<math.h> #include<time.h> void menu() { printf("1:乘法运算\n2:计数乘法\n3:乘法十题\n4:四则运算十题\n5:得分率要求四则运算十题\n6:EXIT\n"); } int sjs(int a,int b) { int x; if(a>b) { x=a; a=b; b=x; } x=rand()%(b-a+1)+a; return x; } int cf(int a,int b)//Since the value is taken from 1-10, the rationality of division is determined to deal with the calculation of the division of the decimal { while(1) { if(a%b!=0) b=sjs(1,10); else break; } return b; } int pd(int a,int b,char c,float m) { int jg=0; switch(c) { case '+': if(fabs(a+b-m)<=1e-6) jg=1; break; case '-': if(fabs(a-b-m)<=1e-6) jg=1; break; case '*': if(fabs(a*b-m)<=1e-6) jg=1; break; case '/': if(fabs(a/(float)b-m)<=1e-6) jg=1; break; } return jg; } int tj(int a,int b) { int dfl; dfl=((float)a/b)*100; return dfl; } void rw1() { int a,b,c; a=sjs(1,10); b=sjs(1,10); while(1) { printf("%d*%d=",a,b); scanf("%d",&c); if(pd(a,b,'*',c)) { printf("Right!\n"); break; } else printf("Wrong!Please try again.\n"); } } void rw2() { int a,b,c,i=1; a=sjs(1,10); b=sjs(1,10); while(1) { printf("%d*%d=",a,b); scanf("%d",&c); if(pd(a,b,'*',c)) { printf("Right!\n"); break; } else if(i!=3) printf("Wrong!Please try again.\n"); else { printf("Wrong!You have tried three times!Test over!\n"); break; } i++; } } void rw3() { int a,b,c,i=10,zf=0,s=0; while(i--) { a=sjs(1,10); b=sjs(1,10); printf("第%d题:%d*%d=",10-i,a,b); scanf("%d",&c); if(pd(a,b,'*',c)) { printf("Right!\n"); zf++; } else printf("Wrong!\n"); s++; } printf("总分:%d\n得分率:%d\n",zf,tj(zf,s)); } void rw4() { int a,b,i=10,zf=0,s=0,op,t; float c; char d[4]; d[0]='+',d[1]='-',d[2]='*',d[3]='/'; while(i--) { a=sjs(1,10); op=sjs(0,3); b=sjs(1,10); if(a<b) { t=a; a=b; b=t; } if(op==3&&a%b!=0) b=cf(a,b); printf("第%d题:%d%c%d=",10-i,a,d[op],b); scanf("%f",&c); if(pd(a,b,d[op],c)) { printf("Right!\n"); zf++; } else printf("Wrong!\n"); s++; } printf("总分:%d\n得分率:%d%%\n",zf,tj(zf,s)); } void rw5() { int a,b,i=10,zf=0,s=0,op,t; float c; char d[4]; d[0]='+',d[1]='-',d[2]='*',d[3]='/'; while(i--) { a=sjs(1,10); op=sjs(0,3); b=sjs(1,10); if(a<b) { t=a; a=b; b=t; } if(op==3&&a%b!=0) b=cf(a,b); printf("第%d题:%d%c%d=",10-i,a,d[op],b); scanf("%f",&c); if(pd(a,b,d[op],c)) { printf("Right!\n"); zf++; } else printf("Wrong!\n"); s++; if(i==0) { printf("总分:%d\n得分率:%d%%\n",zf,tj(zf,s)); if (zf<7.5) { i=10; zf=0; s=0; } } } } int main() { int n,flag=1; while(flag) { srand(time(NULL)); system("cls"); menu(); scanf("%d",&n); switch(n) { case 1: rw1(); break; case 2: rw2(); break; case 3: rw3(); break; case 4: rw4(); break; case 5: rw5(); break; case 6: flag=0; break; } system("pause"); } return 0; }

Run the interface

最新回复(0)