功能:
一自定义功能
- 由用户自定义是否有乘除法运算
- 由用户自定义是否带括号进行运算
- 由用户自定义是否包含真分数运算
- 由用户自定义运算中数字的取值上限
- 由用户自定义是否有出题数量
二 运算功能
- 用户定义取值范围和出题数量之后,题目依次呈现,可依次作答,并随之判断答案是否正确;
- 若回答错误,则会发布正确答案供答题者参考
- 结束答题后,系统将会分别汇总答对题的数量和答错题的数量。
实现:
- 用户输入对应参数,实现自定义运算
srand((int)time(NULL)); //设置时间种子 ,使得程序每次运行的结果都不同
int num1, num2, num3, num4, count, n, change, amount, shuchu, range, j, repeat = 0, bracket, proper_fs, right = 0, wrong = 0;
string str_num1, str_num2, temp;
float Answer, InputAns;
cout << "敢不敢来做一做我出的计算题呢?小伙伴儿,你要加油喽!!!一定要按要求作答哦~" << endl;
cout << "请老师先出题吧~" << endl;
cout << "有无乘除法?1有,0没有:" << endl;
cin >> n;
cout << "是否有括号?1有,0没有:" << endl;
cin >> bracket;
cout << "是否有真分数?1有,0没有:" << endl;
cin >> proper_fs;
cout << "请输入数字范围:" << endl;
cin >> range;
cout << "请输入出题数量:" << endl;
cin >> amount;
string Equation[1000];
char symbol;
cout << amount << "道四则运算题如下,小伙伴们,开始答题啦:" << endl;
2由用户输入自定义参数的四则运算后,调用函数,完成输出表达式
1 for (int i = 0; i<amount; i++) 2 { 3 //count = random() % 3 + 2; 4 count = 4; 5 str_num1 = create_num(proper_fs, range); 6 str_num2 = create_num(proper_fs, range); 7 symbol = create_symbol(n); 8 Equation[i] = combination(str_num1, str_num2, symbol); 9 if (count>2) 10 { 11 for (count; count > 2; count--) 12 { 13 symbol = create_symbol(n); 14 str_num1 = Equation[i]; 15 if (bracket == 1) 16 { 17 change = random() % 3; 18 if (change == 0) 19 { 20 str_num1 = '(' + str_num1 + ')'; 21 } 22 } 23 symbol = create_symbol(n); 24 str_num2 = create_num(proper_fs, range); 25 change = random() % 2; 26 if (change == 0) 27 { 28 temp = str_num1; 29 str_num1 = str_num2; 30 str_num2 = temp; 31 } 32 Equation[i] = combination(str_num1, str_num2, symbol); 33 } 34 } 35 //判断是否重复 36 for (j = 0; j < i; j++) 37 { 38 if (Equation[j] == Equation[i]) 39 { 40 i = i - 1; 41 repeat = 1; 42 break; 43 } 44 } 45 if (repeat != 1)//若不重复,则输出 46 { 47 cout << Equation[i] << "=";
3由答题者输入答案后,先计算正确答案,再和答题者答案进行比较,若答对,提示答案正确,若打错,则给出正确答案。
1 //得出正确答案 2 float get_ans(string str) 3 { 4 int len; 5 float ans; 6 len = str.length(); 7 //char num[len]; 8 char *num = new char[len]; 9 for (int j = 0; j<len; j++) 10 { 11 num[j] = str[j]; 12 } 13 //用堆栈解决。。。 14 ans = EvaluateExpression(num); 15 return ans; 16 } 17 18 //判断是否为正确答案 19 //判断结果是否正确 20 cin >> InputAns; 21 Answer = get_ans(Equation[i]); 22 Answer *= 100; 23 int temp = (int)Answer; 24 Answer = ((double)temp) / 100.00; 25 if (InputAns == Answer) 26 { 27 cout << "回答正确,好棒呢!"; 28 right++; 29 } 30 else 31 { 32 cout << "你的答案好像不对哦!正确答案是"; 33 cout << setprecision(2) << fixed << Answer; 34 wrong++; 35 } 36 cout << endl;
4.结束答题后,系统将会分别汇总答对题的数量和答错题的数量。
cout << "你一共答对" << right << "道题哦,真棒呢!答错" << wrong << "道题,没关系,再接再厉哦!" << endl <<endl;
感想:首先我不是个内向的人,很显然媛媛也是。作为一个成年人,面对分歧的时候我们都能做到坐下来好好谈并且清晰的表达出各自的想法,我们上次的编程略显简陋,因为没有时间了。这次我们在选哪种语言,还有一些设置上进行了细致的商讨,我觉得我们合作的挺愉快。收益的话目前我没感受到。庆幸自己的伙伴是媛媛。
SSH:git@git.coding.net:shenbaishan/sizeyunsuan.git