第二次作业

第二次作业

GIT地址 https://github.com/a2084054502
GIT用户名 a2084054502
学号后五位 24241
-- --
博客地址 https://www.cnblogs.com/tulin250/
作业链接 https://www.cnblogs.com/harry240/p/11515697.html

一 配置环境

vs2010其它高版本电脑安装不了
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20190920125854374.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjMyNTkz,size_16,color_FFFFFF,t_70)

二 克隆项目

账号已注册,直接登录,进入班级仓库https://github.com/ChildishChange/Calculator点击fork,之后跟教程走![在这里插入图片描述]( https://img-blog.csdnimg.cn/20190920130912133.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjMyNTkz,size_16,color_FFFFFF,t_70)
接着安装GIT软件输入指令
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20190920161102314.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjMyNTkz,size_16,color_FFFFFF,t_70)这里主要是对这个 操作不熟悉,代码输错了好几次

三 编写代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace ConsoleApplication1
{
public class Program
{
public voidGreatCalculation(int n)
{
bool test = false;
Random r = new Random();
int op = r.Next(2, 4);//符号数
List l = new List();
List f = new List();
for (int li = 0; li < n; )
{
for (int i = 0; i < op; i++)
{
f.Add(r.Next(1, 5));

}
for (int i = 0; i <= op; i++)
{
l.Add(r.Next(0, 100));
}
Dictionary<int, string> h = new Dictionary<int, string> { { 1, "+" }, { 2, "-" }, { 3, "*" }, { 4, "/" } };
for (int i = 0; i < f.Count(); i++)
{
if (h[f[i]] == "/" && l[i] == 0)
test = false;
else
test = true;
}
string str = "";
for (int i = 0; i < f.Count; )
{
if (i == 0)
{
str = l[i].ToString() + h[f[i]].ToString() + l[i + 1].ToString();
i += 1;
}
else
{
str += h[f[i]].ToString() + l[i + 1].ToString();
i += 1;
}

}
if (test)
{
test = false;
DataTable table = new DataTable();
var re = table.Compute(str, null);
int s;
if (int.TryParse(re.ToString(), out s))
{
Console.WriteLine(str + "=" + re.ToString());
test = true;
}
}
if (test == true)
li++;
l.Clear();
f.Clear();
}

}
static void Main(string[] args)
{
Console.Write("请输入题目个数:");
int n = Convert.ToInt32(Console.ReadLine());
Program c = new Program();
c.GreatCalculation(n);
}
}
}
结果
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20190920172639688.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjMyNTkz,size_16,color_FFFFFF,t_70)单元测试
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20190920174741278.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjMyNTkz,size_16,color_FFFFFF,t_70)
**

提交代码

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20190920175450490.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjMyNTkz,size_16,color_FFFFFF,t_70)
**总的来说这次对我的难度挺大的,单元测试我也没搞太懂,这还是我室友帮我做的单元测试,我的编程能力也不高,甚至说有点低,希望下次简单点吧

posted on 2019-09-20 18:11  地信涂林  阅读(118)  评论(0)    收藏  举报

导航