第二次作业————熟悉工具
第二次作业——熟悉使用工具
Git地址 | 在这里 |
---|---|
Git用户名 | 2786865424 |
学号后五位 | 61315 |
博客地址 | 博客地址 |
作业链接 | 作业链接 |
- 请以博客记录的方式,体现环境配置过程(包括遇到了哪些问题,你是如何解决的)
按照老师的步骤一步一步进行配置,在使用过程中会遇到一些细小的问题,但都很容易解决,目前来说未遇到不懂的情况。 - 体现你代码设计的思路(注意:请保证代码能够运行通过)
1、要生成一个四则运算则要生成运算数和运算符号利用char op(int n)函数和random()函数产生随机数用来随机生成运算符
char op(int a)
{
char c[4] = { '+','-','*','/' };
return c[a];
}
2、利用famula函数开始生成表达式
string formula()
{
string suanshi;
int num1, num2, temp, a, t,count,i,j,Q;
num1 = random() % 100 + 1;
temp = num1;
suanshi += to_string(num1);
count = random() % 2 + 1;
for (i = 0; i < count; i++)
{
char c;
a = random() % 4;
c = op(a);
num2 = random() % 100 + 1;
if (c == '/')
{
while(temp<num2){
temp = random() % 100 + 1;
num2 = random() % 100 + 1;
suanshi = to_string(temp);
}
while (temp%num2 != 0)
{
Q = temp % num2;
num2 = Q;
}//为了使两个数能够整除
}
suanshi+= op(a) + to_string(num2);
t = temp;
temp = num2;
q1.push(t);
q1.push(num2);
}
return suanshi;
}
3、利用栈对算术式进行求值
void Result(T k[], int n) {
int i, top = 0, a, b;
char c;
for (i = 0; i < n; i++)
{
if (top == 0)
{
c = k[i].oppp[top];
s1.push(k[i].sss[top]);
s1.push(k[i].sss[top + 1]);
s2.push(c);
if (c== '*')
{
s2.top();
a = s1.top();
b = s1.top();
k[i].result = a * b;
s1.push(k[i].result);
}
if (c == '/')
{
s2.top();
a = s1.top();
b = s1.top();
k[i].result = b/ a;
s1.push(k[i].result);
}
top++;
}
else if (top > 0 && top < k[i].ca - 1)
{
s2.push(k[i].oppp[top]);
s1.push(k[i].sss[top + 1]);
if (k[i].oppp[top + 1] == '/' || k[i].oppp[top + 1] == '*')
{
if (k[i].oppp[top] == '*')
{
s2.top();
a = s1.top();
b = s1.top();
k[i].result = a * b;
s1.push(k[i].result);
}
if (k[i].oppp[top] == '/')
{
s2.top();
a = s1.top();
b = s1.top();
k[i].result = b / a;
s1.push(k[i].result);
}
top++;
}
else
{
if (k[i].oppp[top] = '-')
{
s2.pop();
a = s1.top();
b = s1.top();
k[i].result = b - a;
s1.push(k[i].result);
}
}
}
else if (top == k[i].ca - 1)
{
s1.push(k[i].sss[top + 1]);
s2.push(k[i].oppp[top]);
c = s2.top();
do {
a = s1.top();
b = s1.top();
if (c == '-')
{
k[i].result = b - a;
s1.push(k[i].result);
}
if (c == '+')
{
k[i].result = b + a;
s1.push(k[i].result);
}
if (c== '*')
{
k[i].result = b * a;
s1.push(k[i].result);
}
if (c== '/')
{
k[i].result = b / a;
s1.push(k[i].result);
}
} while (!s2.empty());
}
s1.empty();
}
}
4、将生成的算术是写入文件
void wenjian(string s[], int n)
{
int i;
ofstream out;
out.open("daan.txt");
for (i = 0; i < n; i++)
{
out<<s[i]<<endl;
}
out.close();
}
- 记录你使用github克隆项目以及提交代码的整个过程(包括遇到的问题,你是如何解决的)
1、使用GitHub克隆项目完全没有问题。
2、使用GitHub提交代码
**噼里啪啦一顿操作后
别问我为什么这么弄,毕竟我就是个弟弟
感想
在这次作业中我发现了许多自身的不足,有许多的东西到最后都没有整明白,课后应该多花功夫去实践,单元测试·,回归测试,一直没弄明白,就连GIT也不知道叫没有交上,我果然是个弟中弟