20194595-自动生成四则运算题第一版报告
需求分析
该软件能够按照用户需求来自动生成类别不同的算式,可以做到随时出题节省时间。
功能设计
软件基本功能
(1)自动生成10道100以内的2个操作数的四则运算算式(+ - * /),要求运算结果也在100以内
(2)剔除重复算式。 2 + 3 = 和 2 + 3 = 是重复算式 2 + 3 = 和 3 + 2 = 不属于重复算式
(3)题目数量可定制
(4)相关参数可控制
是否包含乘法和除法
操作数数值范围可控(如操作数 在100以内 还是1000以内)
操作数是否含负数
(5)生成的运算题存储到外部文件result.txt中
扩展功能
(1)生成的答案存储到answer.txt中
设计实现
代码基于Java语言编写
类:Question,定义了生成算不同算式的函数CreateQuestion(),通过重载该函数可以生成不同模式的算式。
测试运行


代码片段
生成包含乘除、负数的算式
1 public String[][] CreateQuestion(int num, boolean include_Multiplication_division,int size_operationNum) { 2 int num1, num2, result; 3 int type; 4 int count = 0; 5 String[][] Question_Answer = new String[999][2]; 6 while (true) { 7 if (count >= num) 8 break; 9 num1 = (int) (Math.random() * size_operationNum); 10 num2 = (int) (Math.random() * size_operationNum); 11 type = 1 + (int) (Math.random() * 4); 12 if (type == 1) { 13 result = num1 + num2; 14 if (result < 100) { 15 Question_Answer[count][0] = num1 + " + " + num2 + " =\r\n"; 16 Question_Answer[count][1] = result + "\r\n"; 17 count++; 18 } 19 } else if (type == 2) { 20 result = num1 - num2; 21 if (result < 100) { 22 Question_Answer[count][0] = num1 + " - " + num2 + " =\r\n"; 23 Question_Answer[count][1] = result + "\r\n"; 24 count++; 25 } 26 } else if (type == 3) { 27 result = num1 * num2; 28 if (result < 100) { 29 Question_Answer[count][0] = num1 + " * " + num2 + " =\r\n"; 30 Question_Answer[count][1] = result + "\r\n"; 31 count++; 32 } 33 } else if (type == 4) { 34 Double result_; 35 if (num2 == 0) 36 continue; 37 result_ = (double) num1 / num2; 38 if (result_ < 100) { 39 Question_Answer[count][0] = num1 + " / " + num2 + "=\r\n"; 40 Question_Answer[count][1] = result_ + "\r\n"; 41 count++; 42 } 43 } 44 } 45 return Question_Answer; 46 }
总结
代码实现了一些基本的功能,但是重复代码太多,组织结构有点混乱。
PSP
|
PSP |
任务内容 |
计划共完成需要的时间(min) |
实际完成需要的时间(min) |
|
Planning |
计划 |
60 |
80 |
|
· Estimate |
· 估计这个任务需要多少时间,并规划大致工作步骤 |
60 |
80 |
|
Development |
开发 |
40 |
120 |
|
·· Analysis |
需求分析 (包括学习新技术) |
3 |
5 |
|
· Design Spec |
· 生成设计文档 |
2 |
5 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
2 |
5 |
|
· Coding Standard |
代码规范 (为目前的开发制定合适的规范) |
1 |
5 |
|
· Design |
具体设计 |
5 |
10 |
|
· Coding |
具体编码 |
20 |
60 |
|
· Code Review |
· 代码复审 |
5 |
20 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
2 |
10 |
|
Reporting |
报告 |
30 |
60 |
|
·· Test Report |
· 测试报告 |
10 |
20 |
|
· Size Measurement |
计算工作量 |
10 |
20 |
|
· Postmortem & Process Improvement Plan |
· 事后总结 ,并提出过程改进计划 |
10 |
20 |
浙公网安备 33010602011771号