作业四-结队编程项目-四则运算

四则运算-结队编程

队友:郑都都

学号:130201239

博客地址:http://www.cnblogs.com/dudu-27/

作业要求:

基本功能要求:

1) 实现一个带有用户界面的四则运算。

2) 生成的题目不能重复。

3) 支持负数,例如-1,-1/2,-3‘4/5等。

需要支持的基本设定参数

1) 题目的数量(个人项目的要求)

2) 数值的范围(个人项目的要求)

3) 题目中最多几个运算符

4) 题目中或运算过程中有无有分数(比如进行整数除法的时候不能除尽)

5) 题目中是否有乘除法

6) 题目中是否有括号

7) 题目中或运算过程中有无负数

2.附加题----能把四则运算计算的功能封装起来,通过测试程序和API接口测试其简单的加法功能。(10分)

        注意: 博客中需要给出单元测试的步骤及截图

完成状态:

题目上述要求都已完成,但附加题中只是把四则运算的功能进行简单封装。

负责内容:

负责的内容都差不多,毕竟都是在一起共同花时间完成的,每个部分的程序设计都有参加,但是括号功能没能过多的去写代码。

优缺点:

优点:

1、可以耐心的去完成自己的任务,并且可以再出现问题是及时解决。

2、能够把自己之前学到的知识充分的运用到编程中,并且会积极思考现在以及将要面临的问题。

3、有良好的沟通与解释能力,能与队友有好的沟通,并为他解决不懂的问题。

缺点:

1、对待问题有时缺乏积极性,不能积极的对待某个问题的解决。

2、在编程时知识掌握不牢固,有时会感到知识的匮乏,还需向网络求助。

团队合作的优缺点:

优点:

能够增加自己的沟通和交往能力,激发个人的想象力,使自己的想法在队友的帮助下边的更好,更完善;再者,一个优秀的团队能高效快速的解决问题,比一个人更加迅速。

缺点:

有时会在一个问题上产生分歧,会浪费时间。不同人打的代码不一致,在修改错误时会很麻烦。

照片与成果:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 四则运算
{
    public partial class Form1 : Form
    {
        int i, j;
        char[] fh = { '', '', '×', '÷' };
       // char[] fs = { ' ', '-' };
        public Form1()
        {
            InitializeComponent();
        }
        static int GetRandomSeed()  //随机数种子,解决随机数一致问题
        {
            byte[] bytes = new byte[4];
            System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
            rng.GetBytes(bytes);
            return BitConverter.ToInt32(bytes, 0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            i = int.Parse(textBox1.Text);//获取题数
            j = int.Parse(textBox2.Text);//获取运算符数
            int m = 0;
            Random rd = new Random(GetRandomSeed());
            int n=1;
            for (int a = 0; a < i; a++)
            {
                if (checkBox2.Checked == true)
                {
                    m = input_qkh(m, n);
                    input_num();
                    for (int b = 0; b < j; b++)
                    {
                        input_fh();
                        //input_fs();
                        if (b < j - n) { m = input_qkh(m, n); }
                        input_num();
                        m = input_hkh(m, n);
                        //input(" ");


                    }
                    input("=
");
                }
                else {
                        input_num();
                        for (int b = 0; b < j; b++){
                            input_fh();
                           // input_fs();
                            input_num();
                           // input(" ");
                        }
                            input("=
");
                }
               
              
            }


        }
        public void input_num()
        {
            int a = int.Parse(textBox4.Text);
            int b = int.Parse(textBox5.Text);

            if (checkBox3.Checked == true)
            {
                Random rd = new Random(GetRandomSeed());
                int c = rd.Next(2);
                int num1 = rd.Next(a, b + 1);
                int num2 = rd.Next(0, b + 1);
                switch (c)
                {
                    case 0: {
                            input(num1.ToString());
                            input("/");
                            input(num2.ToString());
                        } break;
                    case 1: input(num1.ToString()); break;
                }

            }
            else
            {
                Random rd = new Random(GetRandomSeed());
                int num1 = rd.Next(a, b + 1);
                input(num1.ToString());
            }
        }
        public int input_qkh(int m,int n)//(前括号)m为判定有无前括号,n为后括号添加位置
        {
            
            Random rd = new Random(GetRandomSeed());
            if(m == 0)                //判定有无前括号
            {
                int a = rd.Next(2);
                if (a == 0)     //随机概率添加前括号
                { input("(");
                    m = 1;
                }
            }
            else
            {
                
            }
           // input("m=" + m.ToString());
            return m;
            
        }
        public int input_hkh(int m, int n)//(后括号)m为判定有无前括号,n为后括号添加位置
        {

            Random rd = new Random(GetRandomSeed());
            if (m == 0)                //判定有无前括号
            {
                
            }
            else
            {
                if (m == n + 1)
                {
                    input(")");
                    m = 0;
                }
                else
                { m++; }
            }
         //   input("m="+m.ToString());
            return m;

        }
        /*public void input_fs()
        {
            if (checkBox1.Checked == true)
            {
                Random rd = new Random(GetRandomSeed());
                input(fs[rd.Next(2)].ToString());//符号
            }
            else {
                input(" ");
            }
           
        }*/
        public void input_fh()
        {
            if (checkBox4.Checked == true)
            {
                Random rd = new Random(GetRandomSeed());
                input(fh[rd.Next(4)].ToString());//符号
            }
            else {
                Random rd = new Random(GetRandomSeed());
                input(fh[rd.Next(2)].ToString());//符号
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox3.Text = "";
            textBox1.Text = "";
            textBox2.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
        }

     

        public void input(string t)
        {
            textBox3.AppendText(t);
        }

    }
}
原文地址:https://www.cnblogs.com/zzkmark/p/5361038.html