第二次作业(修改)
GIT地址 | https://github.com/1402120950 |
---|---|
GIT用户名 | 1402120950 |
学号后五位 | 24115 |
博客地址 | https://www.cnblogs.com/Amazing-zyj/ |
作业链接 | https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/homework/7582 |
1. 配置环境
-
本次作业直接采用的上学期安装并使用的vs2015进行。
-
对vs2015采用最简单的输出代码进行环境测试。
-
2. 克隆项目
- 1.GItHUb账户是一开始申请好了的,只是忘记了密码,用邮箱找回了密码。
- 2.直接进入 https://github.com/ChildishChange/Calculator ,拷贝仓库。
- 3.安装Git,所有安装设置全部默认设置,除了安装位置。
- 4.为了方便,直接在桌面新建了一个文件夹,将项目克隆在桌面,方便操作。
- 5.输入地址进行克隆。
3.编写代码
设计思路
-
- 采用随机数来实现随机出题
-
- 用switch-case来实现计算方法的选择
-
- 所有方法为一个大类,计算方法为一个小类,需要时调用
-
- 用两个数来记录答题的错误数和正确数
-
- 用if函数判断答题的对或错
代码
主函数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _Random
{
class Program
{
static void Main(string[] args)
{
mathvoid op = new mathvoid();
int a = 0;
int n = 0;
int i = 0;
string Z = "";
Random r = new Random();
a = r.Next(0, 4);
Console.WriteLine("");
Console.WriteLine("请输入出题数目:");
n = int.Parse(Console.ReadLine());
for (i = 0; i < n; i++)
{
Z = a.ToString();
switch (Z)
{
case "1":
op.mathjia();
continue;
case "2":
op.mathjian();
continue;
case "3":
op.mathcheng();
continue;
case "4":
op.mathchu();
continue;
}
}
Console.WriteLine("总共答对" + op.getright() + "道题!答错"+op.getwrongt ()+"道题!");
}
}
}
调用的方法 (加,减,乘,除)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _Random
{
public class mathvoid
{
public static int right = 0; //记录答对的总数!
public static int wrong = 0; //记录答错的总数!
public void mathjia() //加法运算!
{
int a, b;
int result;
Random rd = new Random();
a = rd.Next(0, 11);
b = rd.Next(0, 11);
Console.WriteLine("请计算:{0}+{1}=?", a, b);
result = Convert.ToInt32(Console.ReadLine());
if (result == a + b)
{
Console.WriteLine("回答正确!");
right++;
}
else
{
Console.WriteLine("错误,继续努力!");
wrong++;
}
}
public void mathjian() //减法运算!
{
int a, b;
int result;
Random rd = new Random();
a = rd.Next(0, 11);
b = rd.Next(0, 11);
Console.WriteLine("请计算:{0}-{1}=?", a, b);
result = Convert.ToInt32(Console.ReadLine());
if (result == a - b)
{
Console.WriteLine("回答正确!");
right++;
}
else
{
Console.WriteLine("错误,继续努力!");
wrong++;
}
}
public void mathcheng() //乘法运算!
{
int a, b;
int result;
Random rd = new Random();
a = rd.Next(0, 11);
b = rd.Next(0, 11);
Console.WriteLine("请计算:{0}*{1}=?", a, b);
result = Convert.ToInt32(Console.ReadLine());
if (result == a * b)
{
Console.WriteLine("回答正确!");
right++;
}
else
{
Console.WriteLine("错误,继续努力!");
wrong++;
}
}
public void mathchu() //除法运算!
{
int a, b;
int result;
Random rd = new Random();
a = rd.Next(0, 11);
b = rd.Next(0, 11);
if (b != 0)
{
Console.WriteLine("请计算:{0}/{1}=?", a, b);
result = Convert.ToInt32(Console.ReadLine());
if (result == a / b)
{
Console.WriteLine("回答正确!");
right++;
}
else
{
Console.WriteLine("错误,继续努力!");
wrong++;
}
}
else
{
if (a != 0)
{
Console.WriteLine("请计算:{0}/{1}=?", b, a);
result = Convert.ToInt32(Console.ReadLine());
if (result == b / a)
{
Console.WriteLine("回答正确!");
right++;
}
else
{
Console.WriteLine("错误,继续努力!");
wrong++;
}
}
}
}
public int getright() //统计结果!
{
return right;
}
public int getwrongt() //统计结果!
{
return wrong ;
}
}
}
结果截图
3. 单元测试
-
- 右击mathvoid类,点击创建单元测试
-
- 编写简单的测试代码,测试结果如下图,判断的语言不一样导致结果不一定都是正确的,代码并没有问题
4. 基本操作
-
1. 断点
- 如图,在21行处设置一个断点,然后启动,输入2,此时Z的值也是2
- 按F11,逐步调试代码,系统自动给出的减法是3-5,我们输入5,如图
- 继续下一步(F11),后续各个值如图
-
2.条件断点
- 1.设置条件为Z==“3”时候触发断点,点击启动,结果以及条件如图
5.回归测试
因为没有对代码进行改动,所以无需进行回归测试
6.效能工具介绍
-
- 虽然将代码进行更改(以下为更改部分,大幅度增加循环次数,不用选择算法但是还是因为代码的局限性,所以无法进行几百万次计算)
int i = 0, z = 0; andom r = new Random();
long n = 10000000000000;
Console.WriteLine("-------------------------------四则运算-------------------------");
Console.WriteLine("");
Console.WriteLine("请选择您使用的运算方法:1.加法 2.减法 3.乘法 4.除法 5.退出!");
for (i = 0; i < n; i++)
{
z = r.Next(1, 4);
Z = z.ToString();
switch (Z)
分析结果如图
7. 提交代码
-
- 找到本地存放代码的文件夹用右击,找到git blush上传,如图
-
- 在完成 push 后,我们就可以开始向源仓库(即阿超的仓库)发起 Pull Request(简称 PR ,指发起请求给仓库贡献代码),如图(已经成功提交)
- 在完成 push 后,我们就可以开始向源仓库(即阿超的仓库)发起 Pull Request(简称 PR ,指发起请求给仓库贡献代码),如图(已经成功提交)