Git地址 | https://github.com/doraemon-n/dora |
---|---|
Git用户名 | doraemon-n |
学号后五位 | 61205 |
博客地址 | https://www.cnblogs.com/summer-00/ |
做业连接 | https://www.cnblogs.com/ChildishChange/p/10398212.htm |
在网上找vs的安装包而后勾选对应的我所须要的东西开始下载(因为在这以前已经有了vs,因此就没有截图了),看https://www.cnblogs.com/math/p/git.html了解Git的基本做用,该如何使用。
遇到的问题大概就是下载很慢,Git是全英文,对新的环境不熟悉
***html
打开vs,点新建->项目->c++建立项目开始编写个人代码
ios
背景
阿超家里的孩子上小学一年级了,这个暑假老师给家长们布置了一个做业:家长天天要给孩子出一些合理的,但要有些难度的四则运算题目,而且家长要对孩子的做业打分记录。练习题在运算过程当中不得出现非整数。
设计
(1)四则运算符:出题的四则运算符应该是随机的,因此能够想到用随机函数srand(),只有四个运算符(+,-,*,/),因此用数组的方式列举出来(或用enum)。c++
char operate()//获取随机运算符 { int seed;//随机数种子 cout << "请输入随机数种子以产生运算符"<<endl; cin >> seed; char ope[4] = { '+','-','*','/' }; srand(seed); return ope[rand() % 4]; }
(2)四则运算数:运算数在0~100之间,因此有1+rand()%100,因为是小学一年级,运算结果不是分数,运算的过程数据也不能出现分数。git
int num()//获取随机数 { int seed; cout << "请输入随机数种子以产生0~100的数字" << endl; cin >> seed; srand(seed); return 1 + rand() % 100; }
(3)完整代码,能力有限,并无一个文件,运行界面也不同。github
#include "pch.h" #include <iostream> #include<cstdlib> #include<fstream> using namespace std; char operate()//获取随机运算符 { int seed; cout << "请输入随机数种子以产生运算符"<<endl; cin >> seed; char ope[4] = { '+','-','*','/' }; srand(seed); return ope[rand() % 4]; } int num()//获取随机数 { int seed; cout << "请输入随机数种子以产生0~100的数字" << endl; cin >> seed; srand(seed); return 1 + rand() % 100; } int main() { int n; char char_1,char_2; int num1, num2, num3, operate_num; cout << "请输入你想要的题目总数" << endl; cin >> n; while (n)//while循环,以产生对应数目的题 { cout << "请输入操做符数目(2或3)来肯定运算数的数目" << endl; cin >> operate_num; if (operate_num == 2)//有三个运算数,两个运算符 { num1 = num(); num2 = num(); num3 = num(); cout << "三个随机运算数为" << num1 << ";" << num2 << ";" << num3 << endl; char_1 = operate(); char_2 = operate(); cout << "两个随机运算符为" << char_1 << ";" << char_2 << endl; cout << num1 << char_1 << num2 << char_2 << num3 << "= " << endl; } else if (operate_num == 3)//有四个运算数,三个运算符 { int num4; char char_3; num1 = num(); num2 = num(); num3 = num(); num4 = num(); cout << "四个随机运算数为" << num1 << ";" << num2 << ";" << num3 << ";" << num4 << endl; char_1 = operate(); char_2 = operate(); char_3 = operate(); cout << "三个随机运算符为" << char_1 << ";" << char_2 << ";" << char_3 << endl; cout << num1 << char_1 << num2 << char_2 << num3 << char_3 << num4 << "= " << endl; } n--; } return 0; }
结果数组
请输入你想要的题目总数 2 49*52-55= 52/55*59+62=
代码在运行的时候显得繁琐,结果不能保证不出现非整数。
****
函数
学习使用一个新的工具仍是有一点麻烦的,尤为是界面是全英文,可是在不断地摸索以后会慢慢地习惯了解。在写代码的过程当中,最开始是不知道要怎么随机的产生不一样的运算符的,经过不断思考选择用数组,本身在写代码的过程当中,其实有不少没必要要的,可是限于能力,就以为本身应该多练习下各类不一样的题型。而后就是本身真的不知道的必定要去问别人或者百度把它搞清楚。助教给的操做过程已经很清楚了,但本身有些地方仍是看不懂,由于有些步骤操做出来的结果与做业连接上说的不太同样,就本身琢磨哪一步不对。工具