--Title:
- Please write a software that can automatically generate primary arithmetic topics;
- Allow the program to accept the user to enter the answer, and determine the right and wrong;
- Finally, the total number of pairs/errors is given.
--Demand Analysis:
- Write the test system of primary school arithmetic, the system can complete the addition, subtraction, multiplication and divide operation within 100;
- The system can accept the user to input the answer, and can automatically judge the right and wrong;
- When the user input answers to judge, the wrong questions to give the correct answer;
- At the end of the answer, you can automatically output the user answers the total number of questions, answer the number of questions, the number of answers and the points obtained.
--Design:
- Defines num to represent the number of problems in the system, A[10], b[10] means the automatically generated random number, c[10] means the result of adding, subtraction, multiplication, d[10] to determine the operation of the test, s represents the result of the division operation;
- Result indicates the correct answer, and add indicates the score of the answer;
- E is the number of answers to the wrong question, R is the number of correct questions;
- Using a main function to realize the user input, the system automatically gives the correct answer after the end of the answer, and gives the total number of questions answered, answer the question number, answers the wrong number and the score.
--Code implementation:
#include <stdlib.h>#include<stdio.h>#include<conio.h>#include<time.h>voidMain () {inta[Ten],b[Ten],d[Ten],c[Ten],num=0, result,add=0; Doubles; intE=0, r=0; printf ("Welcome to the primary arithmetic test system!\n please complete the following topics carefully!\n\n"); Charf[5]={'+','-','*','/'}; Srand ((unsigned) time (NULL)); /*out of 10 questions*/ while(1) {D[num]=abs (rand ())%4;/*to ensure the randomness of the algorithm of the quiz*/ while(1)/*ensure the success of the quiz*/{C[num]=-1; A[num]=abs (rand ())% -; B[num]=abs (rand ())% -; if(d[num]==0) C[num]=a[num]+B[num]; Else if(d[num]==1) C[num]=a[num]-B[num]; Else if(d[num]==2) C[num]=a[num]*B[num]; Else if(d[num]==3) { if(b[num]>0) s=(1.0*a[num]/B[num]); Elses=-1; } if(d[num]<=2) { if(c[num]>=0&& c[num]<= -)/*guarantee that the calculation results are between 0-100*/ Break; }Else { if(a[num]==int(s) *b[num] && s>=0) {C[num]=int(s); Break; }}} num++; if(num==Ten) Break; } /*Answer*/Num=0; while(1) {printf ("%d%c%d=", A[num],f[d[num]],b[num]); scanf ("%d",&result); if(result==C[num]) {R++; printf ("Answer right!\n"); Add+=Ten; } Else{e++; printf ("error, correct answer:%d\n", C[num]); } num++; if(num==Ten) Break; } printf ("\ n You did a total of%d questions, of which the correct%d, the wrong%d, with a score of%d. \ n", e+R,r,e,add); printf ("after the answer, you are welcome to visit!\n again."); Getch ();}
--Testing:
Post-mortem analysis and summary:
1, in the process of doing the problem, I realized that I have a lot of shortcomings;
2, in writing code, the idea must be clear, maintain a clear mind, to effectively complete the work;
In this experiment, I realized that my shortcomings, in doing the problem must be more thinking, more analysis, more understanding;
In doing this topic, the system problems, let me write up the things all disappeared, which gave me an experience,
Next time you do a problem, be sure to remember to save it, so you can save a lot of time.
-Elapsed Time:
Project |
Time |
Demand analysis |
20 minutes |
Design |
30 minutes |
Code |
4.5 hours |
Test |
10 minutes |
Analysis and summary |
20 minutes |
The second operation of software engineering