第二次作业

 

二. 博客要求

   1. 博客开头:

 

GIT地址 https://github.com/joker221822
GIT用户名  joker221822
学号后五位 62118
博客地址 https://www.cnblogs.com/sasd221822/
作业链接  https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/homework/2793

 

 

   2. 博客内容:

  • 请以博客记录的方式,体现环境配置过程(包括遇到了哪些问题,你是如何解决的)

 

           

            使用上学期用过的VS2017,使用C#编程,其中没有遇到什么问题。

 

  • 体现你代码设计的思路(注意:请保证代码能够运行通过)

 

          1. 选择使用的一个大循环来实现这个程序。

           2. 使用随机数算法 “Random” 来随机出式子中所需要的数字存储在 “list” 中。

           3. 符号则是在循环中直接使用随机的方法得到,然后通过循环将 “list” 中的数字和符号组合成一个式子。

           4. 答案的输出直接判断符号随机数决定出 “+”,“-”,“*”,“/” 来进行运算得出结果。

 

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace joker221822
    {
        class Program
        {
            public class FUhao//运用随机数随机出运算符
            {
                public string fuhao(int fuhao)
                {
                    switch (fuhao)
                    {
                        case 1:
                            return "+";
                        case 2:
                            return "-";
                        case 3:
                            return "*";
                        case 4:
                            return "/";
                    }
                    return "0";
                }
            }
    
    
            static void Main(string[] args)
            {
                Random N = new Random();
                int n;
                Console.Write("需要的题目数为:");
                n = int.Parse(Console.ReadLine());
    
                //题目的输出
                for (int i = 0; i < n; i++)
                {
                    int fuhao_1 = N.Next(1, 5);
                    int fuhao_2 = N.Next(1, 5);
                    FUhao FUHAO = new FUhao();
    
                    List<int> TIMU = new List<int>();
                    int timu = N.Next(2, 4);
                    for (int j = 0; j < timu; j++)
                    {
                        TIMU.Add(N.Next(1, 101));  //运用随机数随机出题目所需的数字
                    }
    
    
                    if (TIMU.Count == 2)  //当题目中数字个数为两个的处理
                    {
                        if (fuhao_1 == 4) //排除除法中出现小数的情况,让其重新随机
                        {
                            while (TIMU[0] % TIMU[1] != 0)
                            {
                                TIMU[0] = N.Next(1, 101);
                                TIMU[1] = N.Next(1, 101);
                            }
                        }
                        Console.WriteLine(TIMU[0] + " " + FUHAO.fuhao(fuhao_1) + " " + TIMU[1] + " " + "=");
                        //两个数的式子运算答案
                        if (fuhao_1 == 1)
                            Console.WriteLine("答案为:" + (TIMU[0] + TIMU[1]));
                        if (fuhao_1 == 2)
                            Console.WriteLine("答案为:" + (TIMU[0] - TIMU[1]));
                        if (fuhao_1 == 3)
                            Console.WriteLine("答案为:" + (TIMU[0] * TIMU[1]));
                        if (fuhao_1 == 4)
                            Console.WriteLine("答案为:" + (TIMU[0] / TIMU[1]));
                        Console.WriteLine();
                    }
    
    
                    if (TIMU.Count == 3)  //当题目中数字个数为三个的处理
                    {
                        if (fuhao_1 == 4)   //排除第一个运算符为除法中出现小数的情况,让其重新随机
                        {
                            while (TIMU[0] % TIMU[1] != 0)
                            {
                                TIMU[0] = N.Next(1, 101);
                                TIMU[1] = N.Next(1, 101);
                            }
                        }
                        if (fuhao_2 == 4)
                        {
                            while (TIMU[1] % TIMU[2] != 0)  //排除第二个运算符为除法中出现小数的情况,让其重新随机
                            {
                                TIMU[1] = N.Next(1, 101);
                                TIMU[2] = N.Next(1, 101);
                            }
                        }
                        Console.WriteLine(TIMU[0] + " " + FUHAO.fuhao(fuhao_1) + " " + TIMU[1] + " " + FUHAO.fuhao(fuhao_2) + " " + TIMU[2] + " " + "=");
                        //三个数的式子运算答案
                        if (fuhao_1 == 1)
                        {
                            if (fuhao_2 == 1)
                                Console.WriteLine("答案为:" + (TIMU[0] + TIMU[1] + TIMU[2]));
                            if (fuhao_2 == 2)
                                Console.WriteLine("答案为:" + (TIMU[0] + TIMU[1] - TIMU[2]));
                            if (fuhao_2 == 3)
                                Console.WriteLine("答案为:" + (TIMU[0] + TIMU[1] * TIMU[2]));
                            if (fuhao_2 == 4)
                                Console.WriteLine("答案为:" + (TIMU[0] + TIMU[1] / TIMU[2]));
                        }
                        if (fuhao_1 == 2)
                        {
                            if (fuhao_2==1)
                                Console.WriteLine("答案为:" + (TIMU[0] - TIMU[1]+TIMU[2]));
                            if (fuhao_2 == 2)
                                Console.WriteLine("答案为:" + (TIMU[0] - TIMU[1] - TIMU[2]));
                            if (fuhao_2 == 3)
                                Console.WriteLine("答案为:" + (TIMU[0] - TIMU[1] * TIMU[2]));
                            if (fuhao_2 == 4)
                                Console.WriteLine("答案为:" + (TIMU[0] - TIMU[1] / TIMU[2]));
                        }
                        if (fuhao_1 == 3)
                        {
                            if (fuhao_2==1)
                                Console.WriteLine("答案为:" + (TIMU[0] * TIMU[1] + TIMU[2]));
                            if (fuhao_2 == 2)
                                Console.WriteLine("答案为:" + (TIMU[0] * TIMU[1] - TIMU[2]));
                            if (fuhao_2 == 3)
                                Console.WriteLine("答案为:" + (TIMU[0] * TIMU[1] * TIMU[2]));
                            if (fuhao_2 == 4)
                                Console.WriteLine("答案为:" + (TIMU[0] * TIMU[1] / TIMU[2]));
                        }
                        if (fuhao_1 == 4)
                        {
                            if (fuhao_2==1)
                                Console.WriteLine("答案为:" + (TIMU[0] / TIMU[1]+TIMU[2]));
                            if (fuhao_2 == 2)
                                Console.WriteLine("答案为:" + (TIMU[0] / TIMU[1] - TIMU[2]));
                            if (fuhao_2 == 3)
                                Console.WriteLine("答案为:" + (TIMU[0] / TIMU[1] * TIMU[2]));
                            if (fuhao_2 == 4)
                                Console.WriteLine("答案为:" + (TIMU[0] / TIMU[1] / TIMU[2]));
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
    }
    四则运算

       

          

 

  • 记录你使用github克隆项目以及提交代码的整个过程(包括遇到的问题,你是如何解决的)

         

     1.  注册账号并将阿超的四则运算库拷贝到自己的同名仓库

 

 

 

 

 

2.提交代码遇到了很多困难,查阅了很多东西但还是没有成功将代码顺利地提交上去

 

 

  • 记录你对项目进行单元测试和回归测试的过程(包括你遇到的问题,解决的方法是什么)

 

       单元测试(我使用方法编写的代码中只有一个类,所以只能进行一个单元测试):

 

 

 性能测试:

 

 

    你对本次工具的熟悉过程,有什么感想?分享你学习到的新知识

         在使用  “git  bash” 这个工具时,遇到了很多问题,有些问题还没有得到解决,准备再继续尝试使用这个工具上传代码。

         在编写代码的时候因为没有使用类的方法,导致后面单元测试的时候没有办法顺利地进行,但在对单元测试时,我将之前写过的一些代码进行单元测试,基本掌握了方法。

posted on 2019-03-29 17:40  我佛辣  阅读(181)  评论(1编辑  收藏  举报