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

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

小组成员:框架

王浩淳 dom

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

基本功能:this

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

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

3) 支持负数。3d

须要支持的基本设定参数代码规范

1) 题目的数量code

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("\n");
                        }
                        else
                        {
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            input(" = ");
                            input("\n");
                        }
                    }
                    else
                    {
                        if (checkBox2.Checked == true)//有乘除法
                        {
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            input(" = ");
                            input("\n");
                        }
                        else
                        {
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            input(" = ");
                            input("\n");
                        }
                    }
                }
                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("\n");
                            }
                            else
                            {
                                shu(b, c);
                                fh1();
                                shu(b, c);
                                fh1();
                                shu(b, c);
                                input(" = ");
                                input("\n");
                            }
                        }
                    }
                    else
                    {
                        if (checkBox3.Checked == true)//有括号
                        {
                            input("(");
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            input(")");
                            fh2();
                            shu(b, c);
                            input(" = ");
                            input("\n");
                        }
                        else
                        {
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            fh2();
                            shu(b, c);
                            input(" = ");
                            input("\n");
                        }
                    }
                }
                else
                {
                    if (checkBox2.Checked == true)//有乘除法
                    {
                        if (checkBox3.Checked == true)//有括号
                        {
                            input("(");
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            input(")");
                            fh1();
                            randzs(b, c);
                            input(" = ");
                            input("\n");
                        }
                        else
                        {
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            fh1();
                            randzs(b, c);
                            input(" = ");
                            input("\n");
                        }
                    }
                    else
                    {
                        if (checkBox3.Checked == true)//有括号
                        {
                            input("(");
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            input(")");
                            fh2();
                            randzs(b, c);
                            input(" = ");
                            input("\n");
                        }
                        else
                        {
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            fh2();
                            randzs(b, c);
                            input(" = ");
                            input("\n");
                        }
                    }
                }
            }
        }


        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;
        }
    }

    }

窗体框架:

 

 

 

运行结果截图:

总结:

通过两周的学习,我和个人伙伴在编程基础能力上都有了提高,对代码规范也更加剧视,可是通过结对编程我和个人同伴也都了解到了本身在编程时的优势和不足,在这次结对编程中,我更多的是负责了动脑子的工做,动手敲代码的环节少了些,在以后的编程中本身也要重视本身的动手能力。在有伙伴的状况下,本身的责任心也更增强了,两我的都开始努力研究程序,在这之中咱们也互相学到了不少新的知识。

小组编程截图: