demand analysis:
Design of a pupil can be automatically generated questions four operations program. Using C language or Java language (here using the C language compiler for the vc ++ 6.0)
Design features:
- Basic functions :
Automatically generating four arithmetic operation of Equation 2 number less than 10 100 (+ - * /), the calculation result is within 100
Discarding duplicates equation (2 + 3 + 2 = 3 and a = 2 + 3 = Equation repeated 3 + 2 = and are not repeated equation)
The number of items can be customized
Related parameters can be controlled, whether to include multiplication and division, the number of controllable operation range of values (e.g., less than 100 or operand within 1000), whether or not containing a negative operand
Generating operation to an external file title stored in result.txt
- Extensions :
Two random numbers are multiplied, the result is greater than the fault tolerance 100
Two random numbers are subtracted, the result is negative tolerant
Design and Implementation:
C language has no concept of class. Function of the C language header files carrying function <stdlin.h>, <stdio.h>
Test run:
Because of the use freopen ( "D: \\ result.txt", "w", stdout); code, does not appear in the result of the command line c, and stores the result document D directly to disc result.txt , obtained in the result.txt not necessarily four arithmetic operations 10, because the random number subtraction is negative four operations has been printed, the red part of FIG code is not running, but do fault tolerance, can be run after removing annotations .
Case . 1 : Result = first_num- second_num; // Primary no concept of positive and negative numbers, if the number of positive-negative skip this problem IF (Result < 0 ) { // if negative occurs, regenerate a new random number until results positive comes along, increases time complexity / * the while (. 1) { IF (result <0) { FIRST_NUM = RAND (% 50); second_num = RAND ()% 50; result = FIRST_NUM-second_num; } the else IF (result> = 0) { printf("%d-%d=%d\n",first_num,second_num,result); break; } }*/ continue; } else printf("%d-%d=%d\n",first_num,second_num,result); break;
Code shows:
// Primary no concept of positive and negative numbers, if the number of positive-negative skip this problem IF (Result < 0 ) { // if negative occurs, regenerate a new random number until a positive result appears so far, increasing the time complexity / * the while (. 1) { IF (Result <0) { FIRST_NUM = RAND ()% 50; second_num = RAND ()% 50; Result = FIRST_NUM-second_num; } the else IF (Result> = 0) { the printf ( "% D% =% D- D \ n-", FIRST_NUM, second_num, Result); BREAK; } }*/ continue; }
// results of fault tolerance than 100, when the random number is multiplied by two is greater than 100, to regenerate a new random number IF (Result> 100 ) { FIRST_NUM = RAND ()% 10 ; second_num = RAND ()% 10 ; Result FIRST_NUM * = second_num; }
to sum up:
During design, the program needs to be designed for a branch design. The main function of the first code design: procedures for the four operations, can be achieved when the body functions, fault-tolerant process is performed, for example, a negative result of the concept of fault tolerance, etc. does not exist within the fault tolerance 100, primary, the final test code .
Psp:
SUMMARY |
Program requires successful completion time (min) |
Time required completion time (min) |
Estimated time required tasks and general steps |
10 |
8 |
Develop |
150 |
160 |
demand analysis |
3 |
4 |
Generate design documents |
20 |
40 |
Code Specification |
6 |
5 |
Specific design |
20 |
10 |
Specific coding |
120 |
180 |
test |
30 |
50 |
testing report |
20 |
30 |
Computing workload |
2 |
2 |
Hindsight |
20 |
60 |