https://github.com/yekai1/-.git
题目:
能自动生成小学四则运算题目,并且不能出现负数;
能支持真分数的四则运算;
功能设计:
实现四则运算题目和答案的生成,对生成的四则运算题目进行查重,支持对提供的题目进行查重和答案求解并给出正确错误及题目重复的结果。
设计实现:
类1:生成随机数
类2:生成整个表达式
类3:表达式转换成为逆波兰式
类4:树
类5:类中存放一个数的分子与分母,同时toString方法输出真分数形式
类6:计算结果
类7:二叉树的查重
类8:主函数
代码说明:
生成表达式:
def createarithmetic(self):
list = []
f1 = function1.function1()
f2 = function2()
operator_no = random.randint(1,3)
if operator_no == 1:
list.append(f1.createNum())
list.append(f2.createOperator())
list.append(f1.createNum())
elif operator_no == 2:
start = random.randint(0,2)
end = 0
if start == 0:
end == 0
else:
end = start +1
for i in range(1,4):
if i == start:
list.append("(")
list.append(f1.createNum())
if i == end:
list.append(")")
list.append(f2.createOperator())
list.pop()
elif operator_no == 3:
start = random.randint(0, 3)
end = 0
if start == 0:
end == 0
else:
end = start + 1 + random.randint(0,1)
if end >= 4:
end=4
for i in range(1, 5):
if i == start:
list.append("(")
list.append(f1.createNum())
if i == end:
list.append(")")
list.append(f2.createOperator())
list.pop()
else:
list.append(f1.createNum())
list.append(f2.createOperator())
list.append(f1.createNum())
return list
逆波兰式生成:
def toRPN(self,list):
right = []
aStack = []
position = 0
while True:
if self.isOperator(list[position]):
if list ==[] or list[position] == "(" :
aStack.append(list[position])
else:
if list[position] == ")":
while True:
if aStack != [] and aStack[-1] !="(" :
operator = aStack.pop()
right.append(operator)
else :
if aStack !=[]:
aStack.pop()
break
else:
while True:
if aStack != [] and self.priority(list[position],aStack[-1]):
operator = aStack.pop()
if operator != "(":
right.append(operator)
else:
break
aStack.append(list[position])
else:
right.append(list[position])
position = position +1
if position >= len(list):
break
while aStack != []:
operator = aStack.pop()
if operator != "(":
right.append(operator)
return right
测试运行:
主界面
功能选择:
题目:
答案:
psp
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
Planning | 计划 | 20 | 10 |
Estimate | 估计这个任务需要多少时间 | 8 | 6 |
Development | 开发 | 300 | 320 |
Analysis | 需求分析(包括学习新技术) | 6 | 10 |
Design spec | 生成设计文档 | 10 | 6 |
Design Review | 设计复查(和同事审核设计文档) | 4 | 6 |
Coding Standard | 代码规范(为目前开发制定合适的规范) | 3 | 5 |
Design | 具体设计 | 10 | 12 |
Coding | 具体编码 | 36 | 21 |
Code Review | 代码复审 | 7 | 9 |
Test | 测试(自我测试,修改代码,提交修改) | 13 | 21 |
Reporting | 报告 | 20 | 30 |
Test Report | 测试报告 | 3 | 2 |
Size Measurement | 计算工作量 | 2 | 1 |
Postmortem & Process Improvement Plan | 事后总结,并提出过程改进计划 | 3 | 3 |
合计 |