Coding地址:https://coding.net/u/Julyyun/p/homework/git
一、题目简介
- 除了整数以外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24
- 运算符为 +, −, ×, ÷
- 并且要求能处理用户的输入,并判断对错,打分统计正确率。
- 要求能处理用户输入的真分数, 如 1/2, 5/12 等
- 使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目Myapp.exe -n 10
二、需求分析
编写一段程序,能够输出小学四则运算的题目,并且支持真分数的操作,同时能够对用户输入的答案判定正确与否,给出成绩。
三、功能设计
1用户能自定义此次题目的数量;
2能够输出四则运算题目,并支持真分数的运算;
3能对答案进行判定,并给出正确答案。
四、代码说明
.整数部分
void zhengshu(int m, int a[]) { for (int p = 0; p<m; p++) { int i = (int)rand() % 50; int j = (int)rand() % 50; int k = (int)rand() % 100 / 25; switch (k) { case 0: int o; cout << i << "+" << j << "="; a[p] = i + j; cin >> o; if ((i + j) == o) cout << "答案正确" << endl; else cout << "答案错误" << endl; break; case 1: int q; cout << i << "-" << j << "="; a[p] = i - j; cin >> q; if ((i - j) == q) cout << "答案正确" << endl; else cout << "答案错误" << endl; break; case 2: int r; cout << i << "*" << j << "="; a[p] = i*j; cin >> r; if ((i * j) == r) cout << "答案正确" << endl; else cout << "答案错误" << endl; break; case 3: int s; a[p] = i / j; cout << i << "/" << j << "="; cin >> s; if ((i / j) == s) cout << "答案正确" << endl; else cout << "答案错误" << endl; break; } } }
.真分数部分
void fenshu(int m, int a[][2]) { for (int p = 0; p<m; p++) { int ti,tj; int i = (int)rand() %10; int j = (int)rand() %10; while (j == 0 || i >= j) { i = (int)rand() %10; j = (int)rand() %10; } int x = (int)rand() %10; int y = (int)rand() %10; while (y == 0 || x >= y) { x = (int)rand() %10; y = (int)rand() %10; } int k = (int)rand() % 100 / 25; switch (k) { case 0: cout << "(" << i << "/" << j << ")" << "+" << "(" << x << "/" << y << ")" << "="; a[p][0] = i*y + x*j; a[p][1] = j*y; scanf("%d/%d",&ti,&tj); if(a[p][0]==ti && a[p][1]==tj){ cout << "答案正确" << endl; } else{ cout << "答案错误" << endl; } break; case 1: cout << "(" << i << "/" << j << ")" << "-" << "(" << x << "/" << y << ")" << "="; a[p][0] = i*y - x*j; a[p][1] = j*y; scanf("%d/%d",&ti,&tj); if(a[p][0]==ti && a[p][1]==tj){ cout << "答案正确" << endl; } else{ cout << "答案错误" << endl; } break; case 2: cout << "(" << i << "/" << j << ")" << "*" << "(" << x << "/" << y << ")" << "="; a[p][0] = i*x; a[p][1] = j*y; scanf("%d/%d",&ti,&tj); if(a[p][0]==ti && a[p][1]==tj){ cout << "答案正确" << endl; } else{ cout << "答案错误" << endl; } break; case 3: cout << "(" << i << "/" << j << ")" << "/" << "(" << x << "/" << y << ")" << "="; a[p][0] = i*y; a[p][1] = j*x; scanf("%d/%d",&ti,&tj); if(a[p][0]==ti && a[p][1]==tj){ cout << "答案正确" << endl; } else{ cout << "答案错误" << endl; } } }
五、测试运行
PSP表格
PSP2.1 | Personal Software Process Stages | Time (%) Senior Student | Time (%) |
Planning | 计划 | 8 | 6 |
· Estimate | 估计这个任务需要多少时间 | 150 | 160 |
Development | 开发 | 80 | 70 |
· Analysis | 需求分析 (包括学习新技术) | 25 | 20 |
· Design Spec | 生成设计文档 | 5 | 5 |
· Design Review | 设计复审 | 5 | 5 |
· Coding Standard | 代码规范 | 3 | 3 |
· Design | 具体设计 | 30 | 20 |
· Coding | 具体编码 | 80 | 100 |
· Code Review | 代码复审 | 7 | 5 |
· Test | 测试(自我测试,修改代码,提交修改) | 15 | 20 |
Reporting | 报告 | 10 | 15 |
· | 测试报告 | 3 | 2 |
· | 计算工作量 | 2 | 1 |
· | 并提出过程改进计划 | 3 | 3 |