第二次博客作业

第二次作业

1、博客开头

git地址 https://github.com/cmd-sd
Git用户名 cmd-sd
学号后五位 62324
博客地址 https://www.cnblogs.com/themoon/
作业链接 https://www.cnblogs.com/themoon/p/11559104.html

环境配置

下载git并下载四则运算到电脑上
在这里插入图片描述
vs在之前已经安装并且配置好了,当时安装的时候遇到一些困难,但是现在并没有什么困难了。
在这里插入图片描述

代码设计思路

代码如下:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
class jisuan
{
StreamWriter sw1 = new StreamWriter(@"D:\ce.txt");
Random b1 = new Random();
public static bool ansx(double sum)
{
if (sum == (int)sum)
return true;
else
return false;
}
public static double counter(int c, int d, string e)
{
if (e == "+")
return c + d;
else if (e == "-")
return c - d;
else if (e == "*")
return c * d;
else
{
if (d != 0)
{
int m = c / d;
if (m * d == c)
return c / d;
else
{
return -1;
}

            }
            else
            {
                return -1;
            }
        }
    }
    public void process1(int c1,int c2,int c3,string str1,string str2)
    {
        if ((str1 == "+" || str1 == "-") && (str2 == "*" || str2 == "/"))
        {
            double sum = counter(c2, c3, str2);
            while (sum < 0&& ansx(sum)==false)
            {
                c3 = b1.Next(1, 100);
                c2 = b1.Next(1, 100);
                sum=counter(c3,c2,str2);
            }
            double temp = counter(c1, (int)sum, str1);
            while (temp < 0 && ansx(temp)==false)
            {
                c1 = b1.Next(1, 100);
                temp = counter(c1, (int)sum, str1);
            }
            Console.WriteLine(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "=" + (int)temp);
            sw1.Write(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "=" + (int)temp + "\r\n");
        }
        else
        {
            double sum = counter(c1, c2, str1);
            while (sum < 0 && ansx(sum)==false)
            {
                c1 = b1.Next(1, 100);
                c2 = b1.Next(1, 100);
                sum = counter(c1, c2, str1);
            }
            double temp = counter(c3, (int)sum, str2);
            while (temp < 0 && ansx(temp)==false)
            {
                c3 = b1.Next(1, 100);
                temp = counter(c3, (int)sum, str1);
            }
            Console.WriteLine(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "=" + (int)temp);
            sw1.Write(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "=" + (int)temp + "\r\n");
        }
    }
    public void process2(int c1,int c2,int c3,int c4,string str1,string str2,string str3)
    {
        if ((str1 == "+" || str1 == "-") && (str2 == "*" || str2 == "/") && (str3 == "*" || str3 == "/"))
        {
            double sum = counter(c2, c3, str2);
            while (sum < 0 && ansx(sum)==false)
            {
                c3 = b1.Next(1, 100);
                c2 = b1.Next(1, 100);
                sum = counter(c3, c2, str2);
            }
            double temp = counter(c4, (int)sum, str3);
            while (temp < 0 && ansx(temp)==false)
            {
                c4 = b1.Next(1, 100);
                temp = counter(c4, (int)sum, str3);
            }
            double final = counter(c1, (int)temp, str1);
            while (final < 0 && ansx(final) == false)
            {
                c1 = b1.Next(1, 100);
                final = counter(c1, (int)temp, str1);
                if (final > 0 && ansx(final))
                {
                    Console.WriteLine(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final);
                    sw1.Write(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final + "\r\n");
                    //break;
                }
            }

        }
        else if ((str1 == "+" || str1 == "-") && (str2 == "*" || str2 == "/") && (str3 == "-" || str3 == "+"))
        {
            double sum = counter(c2, c3, str2);
            while (sum < 0 && ansx(sum)==false)
            {
                c3 = b1.Next(1, 100);
                c2 = b1.Next(1, 100);
                sum = counter(c3, c2, str2);
            }
            double temp = counter(c1, (int)sum, str1);
            while (temp < 0 && ansx(temp)==false)
            {
                c1 = b1.Next(1, 100);
                temp = counter(c1, (int)sum, str1);
            }
            double final = counter(c4, (int)temp, str3);
            while (final < 0 && ansx(final)==false)
            {
                c4 = b1.Next(1, 100);
                final = counter(c4, (int)temp, str1);
                if (final > 0 && ansx(final)==false)
                {
                    Console.WriteLine(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final);
                    sw1.Write(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final + "\r\n");
                    //break;
                }
            }
        }
        else if ((str1 == "*" || str1 == "/") && (str2 == "+" || str2 == "-") && (str3 == "*" || str3 == "/"))
        {
            double sum = counter(c1, c2, str1);
            while (sum < 0 && ansx(sum)==false)
            {
                c1 = b1.Next(1, 100);
                c2 = b1.Next(1, 100);
                sum = counter(c1, c2, str1);
            }
            double temp = counter(c3,c4 , str3);
            while (temp < 0 && ansx(temp)==false)
            {
                c3 = b1.Next(1, 100);
                c4 = b1.Next(1, 100);
                temp = counter(c3, c4, str3);
            }
            double final = counter((int)sum, (int)temp, str2);
            Console.WriteLine(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final);
            sw1.Write(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final + "\r\n");
        }
        else
        {
            double sum = counter(c1, c2, str1);
            while (sum < 0 && ansx(sum)==false)
            {
                c1 = b1.Next(1, 100);
                c2 = b1.Next(1, 100);
                sum = counter(c1, c2, str1);
            }
            double temp = counter(c3, (int)sum, str2);
            while (temp < 0 && ansx(temp)==false)
            {
                c3 = b1.Next(1, 100);
                temp = counter(c3, (int)sum, str2);
            }
            double final = counter(c4, (int)temp, str3);
            while (final < 0 && ansx(final)==false)
            {
                c4 = b1.Next(1, 100);
                final = counter(c4, (int)temp, str1);
                if (final > 0 && ansx(final))
                {
                    Console.WriteLine(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final);
                    sw1.Write(c1 + "" + str1 + "" + c2 + "" + str2 + "" + c3 + "" + str3 + c4 + "=" + (int)final + "\r\n");
                }
            }
        }
    }
}

}
思路为:先判断符号,两个符号就是三位数,三个符号就是四位数。再去处理符号优先级,然后是计算过程。

github克隆及提交过程

下载
在这里插入图片描述
然后到本地
在这里插入图片描述
然后上传成功的:

单元测试和回归测试的过程

右键项目,新建,选择test,进行测试,这里我测试的是jisuan:
在这里插入图片描述

总结

1、github和git都是没有用过的东西,进了github的网站还觉得有点懵,全英语,感觉有点高级,但是多看几眼发现还是挺方便的一个东西。git用起也很舒服,下载直接用,指令比较简单,也不需要配置什么环境之类的。总的来说这两个东西以前没有用过还觉得有点可惜。
2、以前测试软件可以不可以用就直接运行排错,现在发现单元测试和回归测试确实是好用,我用的vs2013,之前没有下载组件,找了大半天的测试都没找到,然后去百度vs单元测试也发现不一样,这也算低级错误嘛,结果一搜vs2013单元测试一下就找到了。单元测试的思想感觉以前也想到过,但是没真正的试过,知道这种方法的话,以后估计还是经常用。
3、vs以前学c#的时候经常用,但是距今也有很长时间没用了,拿起来还是比较手生,要找些功能或者要写一些语句都忘记怎么操作了。看来这些工具还是要多用,代码也要多写。
posted @ 2019-09-20 19:25  a王越  阅读(163)  评论(2编辑  收藏  举报