Mission requirements: the use of C or Java language to automatically generate a complete four arithmetic questions of procedure. The basic software functions are as follows.
(1) automatically generates four arithmetic operation of Equation 2 number less than 10 100 (+ - * /), operation results are required within 100
(2) discarding duplicates equation. = 2 + 3 + 3 = 2 and Equation 2 is repeated and 3 + = 3 + 2 = not repeated formula
Number (3) title can be customized
(4) parameters can be controlled
Whether to include multiplication and division
Controllable range values of the operands (e.g., operands within 100 or within 1000)
Whether operands containing negative
(5) generating operation to an external file title stored in result.txt
A. Requirements Analysis
In response to master degree students familiar practice for four operations, reduce the burden Setters, so design a program can automatically write the four operations in the title.
II. Functional Design
- basic skills
- Automatically generating a count of formula
- Randomly generated symbols arithmetic formula
- extensions
- An arithmetic formula to generate automatically calculated and the arithmetic answers given
- Arithmetic equation can be controlled if there is negative
- Arithmetic formula can control whether or not there is an expression, multiplication and division
- Finally, the results generated will be saved for easy viewing in result.txt file
- Arithmetic formula can control its operating range
III. Design and Implementation
- C language
- Quote <stdio.h> library
- Quote <time.h> Library
- Quote <stdlib.h> library
- And then multiplied by 2 minus the calculated negative value itself stars
- fopen function to store an output value
IV. Test Run
In the console inside the test run results and performance in the output text inside
V. snippet
rand () to generate random values, use it to obtain the value of n, can be calculated and assigned corresponding to the following formula op.
for(a=0;a<size;a++) { i=rand()%z+1; j=rand()%z+1; n=rand()%4; if(n==0){op='+'; q=i+j;} if(n==1){op='-'; q=i-j;} if(n==2){op='*'; q=i*j;} if(n==3){op='/'; q=i/j;} printf("%d%c%d=%d\n",i,op,j,q); fprintf(fp,"%d%c%d=%d\n",i,op,j,q); }
If you want to generate negative then the upper limit is multiplied by 2 and then subtract itself is the answer you want.
i=rand()%(2*z)-z+1; j=rand()%(2*z)-z+1; n=rand()%2; if(n==0){op='+'; q=i+j;} if(n==1){op='-'; q=i-j;}
VI. Summary
Write your own if the judge sentences a little more, and I wrote the comment caused by bad habits sometimes I just could not understand what they write, but after this first experience and training, I believe that next time I will be able to based on the original do better.
Seven. PSP
PSP |
SUMMARY |
Plan time (min) required to complete a total of |
The actual time required for completion (min) |
Planning |
plan |
8 |
6 |
Estimate |
It estimated that the task requires much time and planning generally work steps |
8 |
6 |
Development |
Develop |
66 |
64 |
Analysis |
Needs analysis (including learning new technologies) |
6 |
10 |
Design |
Specific design |
10 |
12 |
Coding |
Specific coding |
40 |
30 |
Test |
Test (self-test, modify the code, submit modifications) |
10 |
12 |
Reporting |
report |
3 |
3 |
Postmortem & Process Improvement Plan |
Later summarized, and process improvement plan |
3 |
3 |