软件工程(2019)结对编程第二次作业

一、题目要求

我们在刚开始上课的时候介绍过一个小学四则运算自动生成程序的例子,请实现它,要求:

  • 能够自动生成四则运算练习题
  • 可以定制题目数量
  • 用户可以选择运算符
  • 用户设置最大数(如十以内、百以内等)
  • 用户选择是否有括号、是否有小数
  • 用户选择输出方式(如输出到文件、打印机等)
  • 最好能提供图形用户界面(根据自己能力选做,以完成上述功能为主)

二、任务分工

  • 驾驶员:徐强(负责全部主要代码编写)
  • 领航员:王明阳(负责协助驾驶员完成全部代码的编写,并完成代码的测试工作)

三、源代码说明

coding代码地址:点击这里

1.定制题目数量及设置最大数模块

            int num = 0;
            int maxnum = 0;
            string te = number.Text;
            int len = te.Length;
            for (int i = 0; i < len; i++)
            {
                num *= 10;
                num += te[i] - '0';
            }
            if(num > 500)
            {
                num = 500;
            }
            te = textBox2.Text;
            len = te.Length;
            for (int i = 0; i < len; i++)
            {
                maxnum *= 10;
                maxnum += te[i] - '0';
            }
            if(maxnum == 0)
            {
                maxnum = 10;
            }

2.选择运算符模块

            string Op = "";
            if (checkedListBox1.GetItemChecked(0))
            {
                Op += "+";
            }
            if (checkedListBox1.GetItemChecked(1))
            {
                Op += "-";
            }
            if (checkedListBox1.GetItemChecked(2))
            {
                Op += "*";
            }
            if (checkedListBox1.GetItemChecked(3))
            {
                Op += "/";
            }
            if(Op.Length == 0)
            {
                Op = "+-*/";
            }

3.文件形式输出模块

 private void Button3_Click(object sender, EventArgs e)
        {
            string text = textbox.Text;
            string filePath = "D:\\SPACE\\operation\\printf.txt";
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);
            sw.Write(text);
            sw.Close();
        }

4.随机整数与浮点数的生成

           //范围内生成随机整数
            int number = new Random(Guid.NewGuid().GetHashCode()).Next(2,10);
           //范围内生成随机浮点数
           Random rand = new Random(Guid.NewGuid().GetHashCode());
            float number_f = rand1.Next() % MaxNum + 1 + (float)(rand1.Next() % MaxNum) / MaxNum;

5.窗体部分代码

           System.ComponentModel.ComponentResourceManager resources = new             System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.label1 = new System.Windows.Forms.Label();
            this.panel1 = new System.Windows.Forms.Panel();
            this.label2 = new System.Windows.Forms.Label();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.radioButton1 = new System.Windows.Forms.RadioButton();
            this.panel2 = new System.Windows.Forms.Panel();
            this.radioButton4 = new System.Windows.Forms.RadioButton();
            this.radioButton3 = new System.Windows.Forms.RadioButton();
            this.label3 = new System.Windows.Forms.Label();
            this.panel3 = new System.Windows.Forms.Panel();
            this.number = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.panel4 = new System.Windows.Forms.Panel();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.panel5 = new System.Windows.Forms.Panel();
            this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
            this.label6 = new System.Windows.Forms.Label();
            this.panel6 = new System.Windows.Forms.Panel();
            this.textbox = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.panel1.SuspendLayout();
            this.panel2.SuspendLayout();
            this.panel3.SuspendLayout();
            this.panel4.SuspendLayout();
            this.panel5.SuspendLayout();
            this.panel6.SuspendLayout();
            this.SuspendLayout();

四、执行结果

1.无括号无小数生成结果

文件输出结果:

2.有括号有小数生成结果

文件输出结果:

五、对伙伴的评价

   王明阳同学是一个做事非常认真的人,我们首先选择了四则运算的课题,我们在着手进行编程之前我们讨论了一些事实方案,他提出了为后面的编程工作提出了很多的有意义的建议,在我编程的过程中,他一直仔细的观察我输入的每一行代码,在我遇到问题进行不下去时,我会将我的思路讲给他,然后他会去查阅一些资料,帮助我解决了很多的困难,这也加快了我们的工作进程。并且在我编程的过程中,我会出现很多格式上的错误,他都会一一的指出,当然了,我也感到很惭愧,原来自己有这么多的编程的坏习惯。通过这次结对编程,我真的感觉有一个认真负责的队友是多么的重要。

六、总结

   首先,真的很开心,和队友共同完成了这个四则运算的小程序,这一算是我第一次完成一个带有图形化界面的小程序吧。之前真的没有怎么研究过图形化界面方面的知识,看到了同学使用c#完成了一个图形化界面的初始模板,感觉很不错,所以我和队友也准备用c#来完成这次工作。但是因为之前没有了解过c#语言的知识,所以我们在网络上查找了很多材料,并且询问了了解c#语言的同学。我们发现,c#虽然与之前所学的C语言、c++语言有区别,但是他们的本质还是一样的,所以我们学起来也很容易,我们很快就可以进行一些简单的编程了。
   了解了c#的一些基本语句后,我们开始进行了真正的编程工作中,我们首先做出了四则运算的一个图形化的界面,然后我们开始进行四则运算的算法的设计。根据题目的要求,我们把整个程序分成了设置题目数量模块、设置最大数值模块、运算符选择模块、选择括号模块、选择小数模块、文件形式输出模块等。我们一个模块一个模块的进行编程,虽然在这个过程中遇到了很多的问题,但是通过我们的共同努力,克服困难,我们最后还是取的了成功。当然,我们也知道,我们所得到的结果还有很多的不足之处,很多的缺点。如果有时间有能力,我们会把它做的更加完善。
   通过这次结对编程,无论是知识的获得、还是人与人的交流沟通方面,我都学到了很多。
posted @ 2019-05-06 17:09  苡灬後丶  阅读(258)  评论(0编辑  收藏  举报