结对编程项目---四则运算

 结对编程项目---四则运算

小组成员:

王浩淳 

吴献荣 中软1班 130201237  博客地址:http://www.cnblogs.com/bgdwxr/

基本功能:

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

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

3) 支持负数。

需要支持的基本设定参数

1) 题目的数量

2) 数值的范围

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

4) 题目中或运算过程中有无有分数

5) 题目中是否有乘除法

6) 题目中是否有括号

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

工作分配:

我:窗体框架的设计与实现,总体代码功能的设计,bug排除。

吴献荣:功能代码的实现,整体代码规范,代码细节与bug排除。

结对的每一个人的优点和缺点:

优点:我的伙伴吴献荣同学动手能力很强,很有钻研精神,编程基础好

缺点:编程时遇到问题容易烦躁

结对编程的优点和缺点:

 优点:编程效率更高,能力互补,相互学习更有效的解决问题

 缺点:有时想法不统一,编程习惯不同

编程代码:

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
    {
        public Form1()
        {
            InitializeComponent();
        }

        char[] fh = { '+', '-', '*', '/' };

        private void button2_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(this.textBox1.Text);  //获取生成题目数
            int b = Convert.ToInt32(this.textBox2.Text);  //获取生成数的最小值
            int c = Convert.ToInt32(this.textBox3.Text);  //获取生成数的最大值
            int fhs = Convert.ToInt32(this.comboBox1.Text.ToString());  //获取运算符个数
            for (int i = 0; i < a; i++)
            {
                if (fhs == 1)//一个运算符
                {
                    if (checkBox1.Checked == true)//有分数
                    {
                        if (checkBox2.Checked == true)//有乘除法
                        {
                            shu(b, c);
                            fh1();
                            shu(b, c);
                            input(" = ");
                            input("
");
                        }
                        else
                        {
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            input(" = ");
                            input("
");
                        }
                    }
                    else
                    {
                        if (checkBox2.Checked == true)//有乘除法
                        {
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            input(" = ");
                            input("
");
                        }
                        else
                        {
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            input(" = ");
                            input("
");
                        }
                    }
                }
                else if (fhs == 2)
                {
                    if (checkBox1.Checked == true)//有分数
                    {
                        if (checkBox2.Checked == true)//有乘除法
                        {
                            if (checkBox3.Checked == true)//有括号
                            {
                                input("(");
                                shu(b, c);
                                fh1();
                                shu(b, c);
                                input(")");
                                fh1();
                                shu(b, c);
                                input(" = ");
                                input("
");
                            }
                            else
                            {
                                shu(b, c);
                                fh1();
                                shu(b, c);
                                fh1();
                                shu(b, c);
                                input(" = ");
                                input("
");
                            }
                        }
                    }
                    else
                    {
                        if (checkBox3.Checked == true)//有括号
                        {
                            input("(");
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            input(")");
                            fh2();
                            shu(b, c);
                            input(" = ");
                            input("
");
                        }
                        else
                        {
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            input(" = ");
                            input("
");
                        }
                    }
                }
                else
                {
                    if (checkBox2.Checked == true)//有乘除法
                    {
                        if (checkBox3.Checked == true)//有括号
                        {
                            input("(");
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            input(")");
                            fh1();
                            randzs(b, c);
                            input(" = ");
                            input("
");
                        }
                        else
                        {
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            input(" = ");
                            input("
");
                        }
                    }
                    else
                    {
                        if (checkBox3.Checked == true)//有括号
                        {
                            input("(");
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            input(")");
                            fh2();
                            randzs(b, c);
                            input(" = ");
                            input("
");
                        }
                        else
                        {
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            input(" = ");
                            input("
");
                        }
                    }
                }
            }
        }


        public void fh1() //含有乘除法
        {
            String fh1;
            System.Random i = new Random(System.DateTime.Now.Millisecond);
            fh1 = fh[i.Next(4)].ToString();
            input(fh1);
        }

        public void fh2()//无乘除法
        {
            String fh2;
            System.Random i = new Random(System.DateTime.Now.Millisecond);
            fh2 = fh[i.Next(2)].ToString();
            input(fh2);
        }

        public void randzs(int b,int c)//随机整数
        {
            int zs;
            System.Random num = new Random(System.DateTime.Now.Millisecond);
            zs = num.Next(b, c);
            input(zs.ToString());
        }

        public void randfs(int b,int c)//随机分数
        {
            int n, m;
            System.Random num = new Random(System.DateTime.Now.Millisecond);
            do
            {
                n = num.Next(b, c);
                m = num.Next(b, c);
            } while (n == 0 || m == 0 || n == m);
            input(n.ToString());
            input("/");
            input(m.ToString());
        }

       public void shu(int b,int c)
        {
            int e;
            System.Random num = new Random(System.DateTime.Now.Millisecond);
            e = num.Next(2);
            if (e == 0) { randzs(b,c); }
            else { randfs(b,c);  }
        }

        public void input(string t)//输出到TextBox4中
        {
            textBox4.AppendText(t);
        }

        private void button3_Click(object sender, EventArgs e)//清除输出结果
        {
            textBox4.Clear();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            checkBox1.Checked = false;
            checkBox2.Checked = false;
            checkBox3.Checked = false;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
            comboBox1.Text = "请选择";
            checkBox1.Checked = false;
            checkBox2.Checked = false;
            checkBox3.Checked = false;
        }
    }

    }

窗体框架:

 

运行结果截图:

总结:

经过两周的学习,我和我的伙伴在编程基础能力上都有了提升,对代码规范也更加重视,但是经过结对编程我和我的同伴也都了解到了自己在编程时的优点和不足,在此次结对编程中,我更多的是负责了动脑子的工作,动手敲代码的环节少了些,在之后的编程中自己也要重视自己的动手能力。在有伙伴的情况下,自己的责任心也更加强了,两个人都开始努力研究程序,在这之中我们也互相学到了很多新的知识。

小组编程截图:

原文地址:https://www.cnblogs.com/wanghaochun/p/5361059.html