GIT地址 | https://github.com/Wamnario |
---|---|
GIT用户名 | Wamnario |
学号后五位 | 24114 |
博客地址 | https://www.cnblogs.com/unmario/ |
作业链接 | https://www.cnblogs.com/unmario/articles/11545935.html |
配置环境
原链接要求使用 Microsoft Visual Studio 2017 Community ,原因是要求使用C#和.NET Framework 4.6开发环境。由于专业特殊原因需要使用 Microsoft Visual Studio 2012 Ultimate 进行 ArcEngine .NET 开发(2017无法完美适配ArcObjects),故无法安装链接提供的 Microsoft Visual Studio 2017 Community.那必不可能是因为懒
话虽如此,但步骤一该有的步骤VS2012一样能做。
首先是.NET版本的切换,可右键点击 Solution -> Properties -> Application -> Target Framework 选择 .NET Framework 4.6.1.
其次是选择使用C#的桌面开发,点击项目栏的 TOOLS -> Import and Export Settings -> Reset all settings -> 「根据自身选择是否备份现有设定」 -> Visual C# Development Settings.
这样步骤一就大功告成辣。顺便吐槽一下原文说使用Outlook账号登陆,改为使用Microsoft账号登陆,毕竟live邮箱等微软邮箱都能登陆Visual Studio.
安装配置Git,在 Github 上 Fork目标项目,再将文件通过 git clone <url>
下载到本地文件夹。
在 clone下来的 AchaoCalculator 文件夹内新建以自己 Github ID 为名称的文件夹。再以之为根目录,在 Visual Studio 2012 创建 Windows Form 新项目。项目解决方案为 AchaoCalculator.
代码思路
生成随机数
using System.Text;
using System.Threading.Tasks;
using System.Threading;
int a, b, c;
a = random.Next(0, 101);
Thread.Sleep(1);
b = random.Next(0, 101);
Thread.Sleep(1);
c = random.Next(0, 101);
生成随机符号
string s1, s2;
s1 = sym[random.Next(0, 4)];
Thread.Sleep(1);
s2 = sym[random.Next(0, 4)];
运算法则
通过switch实现运算,因为要输出答案,并且根据题目要求,不能有分数。把所需 式子 + 答案 整理到 line.再将 line 输入到列表中.
不过不能有分数却可以有负数,这学校的小学生真奇怪吼
switch (ch1)
{
case '+':
switch (ch2)
{
case '+':
res = a + b + c;
flag = true;
break;
case '-':
res = a + b - c;
flag = true;
break;
case '*':
res = a + b * c;
flag = true;
break;
case '/':
if (c == 0)
continue;
else if (b % c == 0)
{
res = a + b / c;
flag = true;
}
break;
}
break;
case '-':
switch (ch2)
{
case '+':
res = a - b + c;
flag = true;
break;
case '-':
res = a - b - c;
flag = true;
break;
case '*':
res = a - b * c;
flag = true;
break;
case '/':
if (c == 0)
continue;
else if (b % c == 0)
{
res = a - b / c;
flag = true;
}
break;
}
break;
case '*':
switch (ch2)
{
case '+':
res = a * b + c;
flag = true;
break;
case '-':
res = a * b - c;
flag = true;
break;
case '*':
res = a * b * c;
flag = true;
break;
case '/':
if (c == 0)
continue;
else if (b % c == 0)
{
res = a * b / c;
flag = true;
}
break;
}
break;
case '/':
if (b == 0)
continue;
else switch (ch2)
{
case '+':
if (a % b == 0)
{
res = a / b + c;
flag = true;
}
break;
case '-':
if (a % b == 0)
{
res = a / b - c;
flag = true;
}
break;
case '*':
if (a % b == 0)
{
res = a / b * c;
flag = true;
}
break;
case '/':
if (c == 0)
continue;
else if (a % b % c == 0)
{
res = a / b / c;
flag = true;
}
break;
}
break;
}
line = a + " " + ch1 + " " + b + " " + ch2 + " " + c + " = " + res;
....
....
Common.list.Add(line);
....
....
选择输出路径
using System.IO;
FolderBrowserDialog fd = new FolderBrowserDialog();
fd.ShowDialog();
Common.outputpath = fd.SelectedPath;
输出
StreamWriter sw = new StreamWriter(Common.outputpath + "/q.txt", false, Encoding.Default);
for (q = 0; q < Common.list.Count; q++)
{
sw.WriteLine(Common.list[q]);
}
sw.Flush();
sw.Close();
Clone\Add\Commit\Push流程
1.项目的开头肯定是Clone了,先将 *https://github.com/Cherish599/AchaoCalculator*的项目Fork到自己账户。
2.进入自己的磁盘的某个目录,右键Git Bash. 输入
git clone https://github.com/Wamnario/AchaoCalculator.git
3.在Clone下来的项目目录里新建以自己ID为名称的文件夹。将C#项目新建到刚才建立的空文件夹。开始编写。
4.编写结束后,在自己名称上的文件夹上右键 Git Bash ,输入
git add .
告诉系统哪些东西是要提交的。
5.将暂存区的文件提交到本地的版本库。
git commit -m "leave some useful messages"
6.将本地版本库的文件传送到远程服务器上。
git push
单元测试
在 Visual Studio 2012 Ultimate 中右键点击 Solution Explorer 中的 Solution'AchaoCaculator' 上点击右键, Add -> New Item -> Test -> Unit Test Project .
项目名为 CaculatorUnitTest ,在CaculatorUnitTest
加入引用
断点测试
从截图可以看到,运行到 a = random.Next(0, 101); 的时候,a被赋值,运行到 b = random.Next(0, 101); 的时候,b被赋值,但是还没有运行到 c = random.Next(0, 101); 所以c未被赋值。
回归测试
效能测试
在框中输入了生成1000道题,这大概是CPU使用状态。
所有评论(0)