GIT地址 | https://github.com/1402120950 |
---|---|
GIT用户名 | 1402120950 |
学号后五位 | 24115 |
博客地址 | https://www.cnblogs.com/Amazing-zyj/ |
做业连接 | https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/homework/7582 |
对vs2015采用最简单的输出代码进行环境测试。git
5.输入地址进行克隆。github
用if函数判断答题的对或错算法
主函数dom
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 ;
}
}
}单元测试
结果截图
测试
由于没有对代码进行改动,因此无需进行回归测试spa
虽然将代码进行更改(如下为更改部分,大幅度增长循环次数,不用选择算法可是仍是由于代码的局限性,因此没法进行几百万次计算)设计
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)
分析结果如图