第二次作业(修改)

GIT地址 https://github.com/1402120950
GIT用户名 1402120950
学号后五位 24115
博客地址 https://www.cnblogs.com/Amazing-zyj/
作业链接 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/homework/7582

1. 配置环境

2. 克隆项目

3.编写代码

设计思路

    1. 采用随机数来实现随机出题
    1. 用switch-case来实现计算方法的选择
    1. 所有方法为一个大类,计算方法为一个小类,需要时调用
    1. 用两个数来记录答题的错误数和正确数
    1. 用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 ;
}
}
}

结果截图
![在这里插入图片描述]( https://img-blog.csdnimg.cn/2019091917500222.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21vbWluZzIz,size_16,color_FFFFFF,t_70)

3. 单元测试

4. 基本操作

5.回归测试

因为没有对代码进行改动,所以无需进行回归测试

6.效能工具介绍

    1. 虽然将代码进行更改(以下为更改部分,大幅度增加循环次数,不用选择算法但是还是因为代码的局限性,所以无法进行几百万次计算)

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)

分析结果如图
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20190918213143542.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21vbWluZzIz,size_16,color_FFFFFF,t_70)

7. 提交代码

posted @ 2019-09-18 23:43  Amazing-ZYJ  阅读(252)  评论(5)    收藏  举报