软件工程第二次结对编程
Posted 公怅一叶舟的博客主页
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件工程第二次结对编程相关的知识,希望对你有一定的参考价值。
题目
我们在刚开始上课的时候介绍过一个小学四则运算自动生成程序的例子,请实现它,要求:
能够自动生成四则运算练习题
可以定制题目数量
用户可以选择运算符
用户设置最大数(如十以内、百以内等)
用户选择是否有括号、是否有小数
用户选择输出方式(如输出到文件、打印机等)
最好能提供图形用户界面(根据自己能力选做,以完成上述功能为主)
结对编程角色
驾驶员
爆个照
开发环境
系统:WindowsXP
软件:VS2010
语言:C#
项目地址
Coding.net地址:https://git.coding.net/zhangyazhou/Four_operations.git
项目介绍
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.Windows.Forms;
namespace 运算
{
public partial class Form1 : Form
{
public double Answer1(double[] n, char[] c, int model)
{
double da_an = 0;
if (model == 1)
{
switch (c[0])
{
case ‘+‘:
da_an = n[0] + n[1];
break;
case ‘-‘:
da_an = n[0] - n[1];
break;
case ‘*‘:
da_an = n[0] * n[1];
break;
case ‘/‘:
da_an = n[0] / n[1];
break;
}
switch (c[1])
{
case ‘+‘:
da_an = da_an + n[2];
break;
case ‘-‘:
da_an = da_an - n[2];
break;
case ‘*‘:
da_an = da_an * n[2];
break;
case ‘/‘:
da_an = da_an / n[2];
break;
}
}
if (model == 2)
{
switch (c[1])
{
case ‘+‘:
da_an = n[1] + n[2];
break;
case ‘-‘:
da_an = n[1] - n[2];
break;
case ‘*‘:
da_an = n[1] * n[2];
break;
case ‘/‘:
da_an = n[1] / n[2];
break;
}
switch (c[0])
{
case ‘+‘:
da_an = n[0] + da_an;
break;
case ‘-‘:
da_an = n[0] - da_an;
break;
case ‘*‘:
da_an = n[0] * da_an;
break;
case ‘/‘:
da_an = n[0] / da_an;
break;
}
}
if (model == 3)
{
if (c[1] == ‘+‘ || c[1] == ‘-‘)
{
switch (c[0])
{
case ‘+‘:
da_an = n[0] + n[1];
break;
case ‘-‘:
da_an = n[0] - n[1];
break;
case ‘*‘:
da_an = n[0] * n[1];
break;
case ‘/‘:
da_an = n[0] / n[1];
break;
}
switch (c[1])
{
case ‘+‘:
da_an = da_an + n[2];
break;
case ‘-‘:
da_an = da_an - n[2];
break;
case ‘*‘:
da_an = da_an * n[2];
break;
case ‘/‘:
da_an = da_an / n[2];
break;
}
}
else if (c[0] == ‘+‘ || c[1] == ‘-‘)
{
switch (c[1])
{
case ‘+‘:
da_an = n[1] + n[2];
break;
case ‘-‘:
da_an = n[1] - n[2];
break;
case ‘*‘:
da_an = n[1] * n[2];
break;
case ‘/‘:
da_an = n[1] / n[2];
break;
}
switch (c[0])
{
case ‘+‘:
da_an = n[0] + da_an;
break;
case ‘-‘:
da_an = n[0] - da_an;
break;
case ‘*‘:
da_an = n[0] * da_an;
break;
case ‘/‘:
da_an = n[0] / da_an;
break;
}
}
else
{
switch (c[0])
{
case ‘*‘:
da_an = n[0] * n[1];
break;
case ‘/‘:
da_an = (double)n[0] / n[1];
break;
}
switch (c[1])
{
case ‘*‘:
da_an = n[2] * da_an;
break;
case ‘/‘:
da_an = da_an / n[2];
break;
}
}
}
return da_an;
}
public double Answer2(int num1,int num2,int num3,char[] c,int model)
{
double da_an = 0;
if (model == 1)
{
switch (c[0])
{
case ‘+‘:
da_an = num1 + num2;
break;
case ‘-‘:
da_an = num1 - num2;
break;
case ‘*‘:
da_an = num1 * num2;
break;
case ‘/‘:
da_an = num1 / num2;
break;
}
switch (c[1])
{
case ‘+‘:
da_an = da_an + num3;
break;
case ‘-‘:
da_an = da_an - num3;
break;
case ‘*‘:
da_an = da_an * num3;
break;
case ‘/‘:
da_an = (double)da_an / num3;
break;
}
}
if (model == 2)
{
switch (c[1])
{
case ‘+‘:
da_an = num2 + num3;
break;
case ‘-‘:
da_an = num2 - num3;
break;
case ‘*‘:
da_an = num2 * num3;
break;
case ‘/‘:
da_an =(double) num2 / num3;
break;
}
switch (c[0])
{
case ‘+‘:
da_an = num1 + da_an;
break;
case ‘-‘:
da_an = num1 - da_an;
break;
case ‘*‘:
da_an = num1 * da_an;
break;
case ‘/‘:
da_an = (double)num1 / da_an;
break;
}
}
if (model == 3)
{
if (c[1] == ‘+‘ || c[1] == ‘-‘)
{
switch (c[0])
{
case ‘+‘:
da_an = num1 + num2;
break;
case ‘-‘:
da_an = num1 - num2;
break;
case ‘*‘:
da_an = num1 * num2;
break;
case ‘/‘:
da_an = (double)num1 / num2;
break;
}
switch (c[1])
{
case ‘+‘:
da_an = da_an + num3;
break;
case ‘-‘:
da_an = da_an - num3;
break;
case ‘*‘:
da_an = da_an * num3;
break;
case ‘/‘:
da_an = (double)da_an / num3;
break;
}
}
else if (c[0] == ‘+‘ || c[1] == ‘-‘)
{
switch (c[1])
{
case ‘+‘:
da_an = num2 + num3;
break;
case ‘-‘:
da_an = num2 - num3;
break;
case ‘*‘:
da_an = num2 * num3;
break;
case ‘/‘:
da_an = (double)num2 / num3;
break;
}
switch (c[0])
{
case ‘+‘:
da_an = num1 + da_an;
break;
case ‘-‘:
da_an = num1 - da_an;
break;
case ‘*‘:
da_an = num1 * da_an;
break;
case ‘/‘:
da_an = (double)num1 / da_an;
break;
}
}
else
{
switch (c[0])
{
case ‘*‘:
da_an = num1 * num2;
break;
case ‘/‘:
da_an = (double)num1 /num2;
break;
}
switch (c[1])
{
case ‘*‘:
da_an = num3 * da_an;
break;
case ‘/‘:
da_an = (double)da_an/num3;
break;
}
}
}
return da_an;
}
public void ProductNum(int MaxNum, int MinNum,int num)
{
int jia_fa = 0;
int jian_fa = 0;
int cheng_fa = 0;
int chu_fa = 0;
int shu_dian = 0;
int kuo_hao = 0;
if (checkBox1.CheckState == CheckState.Checked)
{
jia_fa = 1;
}
if (checkBox2.CheckState == CheckState.Checked)
{
jian_fa = 2;
}
if (checkBox3.CheckState == CheckState.Checked)
{
cheng_fa = 3;
}
if (checkBox4.CheckState == CheckState.Checked)
{
chu_fa = 4;
}
if (checkBox6.CheckState == CheckState.Checked)
{
shu_dian = 1;
}
if (checkBox5.CheckState == CheckState.Checked)
{
kuo_hao = 1;
}
Random r = new Random();
for (int i = 0; i < num; i++)
{
double[] n = new double[10];
int pan_duan2 = r.Next(0, 2);//选择括号
int num1 = r.Next(MinNum, MaxNum);
int num2 = r.Next(MinNum, MaxNum);
int num3 = r.Next(MinNum, MaxNum);
double small_num1 = (r.Next(0, 99)) * 0.01;
double small_num2 = (r.Next(0, 99)) * 0.01;
double small_num3 = (r.Next(0, 99)) * 0.01;
char[] c = new char[5];
for (int j = 0; j <= 1; )
{
int pan_duan = r.Next(1, 5);//选择运算符号,范围1-4
if (pan_duan == jia_fa)
{
c[j] = ‘+‘;
j++;
}
if (pan_duan == jian_fa)
{
c[j] = ‘-‘;
j++;
}
if (pan_duan == cheng_fa)
{
c[j] = ‘*‘;
j++;
}
if (pan_duan == chu_fa)
{
c[j] = ‘/‘;
j++;
}
}
string a;
string b;
if (shu_dian == 1)
{
int model = -1;
n[0] = (double)num1 + small_num1;
n[1] = (double)num2 + small_num2;
n[2] = (double)num3 + small_num3;
if (pan_duan2 == 1 && kuo_hao == 1)
{
a = ‘(‘ + Convert.ToString(i + 1) + ‘)‘ + " " + ‘(‘ + Convert.ToString(n[0]) + c[0] + Convert.ToString(n[1]) + ‘)‘ + c[1] + Convert.ToString(n[2]) + ‘=‘ + "\r\n";
model = 1;
}
else if (pan_duan2 == 0 && kuo_hao == 1)
{
a = ‘(‘ + Convert.ToString(i + 1) + ‘)‘ + " " + Convert.ToString(n[0]) + c[0] + ‘(‘ + Convert.ToString(n[1]) + c[1] + Convert.ToString(n[2]) + ‘)‘ + ‘=‘ + "\r\n";
model = 2;
}
else
{
a = ‘(‘ + Convert.ToString(i + 1) + ‘)‘ + " " + Convert.ToString(n[0]) + c[0] + Convert.ToString(n[1]) + c[1] + Convert.ToString(n[2]) + ‘=‘ + "\r\n";
model = 3;
}
double da_an = Answer1(n, c, model);
b = ‘(‘ + Convert.ToString(i + 1) + ‘)‘ + " " + Convert.ToString(da_an) + "\r\n";
}
else
{
int model = 0;
if (pan_duan2 == 1 && kuo_hao == 1)
{
model = 1;
a = ‘(‘ + Convert.ToString(i + 1) + ‘)‘ + " " + ‘(‘ + Convert.ToString(num1) + c[0] + Convert.ToString(num2) + ‘)‘ + c[1] + Convert.ToString(num3) + ‘=‘ + "\r\n";
}
else if (pan_duan2 == 0 && kuo_hao == 1)
{
model = 2;
a = ‘(‘ + Convert.ToString(i + 1) + ‘)‘ + " " + Convert.ToString(num1) + c[0] + ‘(‘ + Convert.ToString(num2) + c[1] + Convert.ToString(num3) + ‘)‘ + ‘=‘ + "\r\n";
}
else
{
model = 3;
a = ‘(‘+Convert.ToString(i+1)+‘)‘+" "+Convert.ToString(num1) + c[0] + Convert.ToString(num2) + c[1] + Convert.ToString(num3) + ‘=‘ + "\r\n";
}
double da_an = Answer2(num1,num2,num3, c, model);
b = ‘(‘ + Convert.ToString(i + 1) + ‘)‘ + " " + Convert.ToString(da_an) + "\r\n";
}
textBox5.Text += b;
textBox4.Text += a;
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int MaxNum = Convert.ToInt32(textBox2.Text);
int MinNum = Convert.ToInt32(textBox1.Text);
int num = Convert.ToInt32(textBox3.Text);
ProductNum(MaxNum, MinNum,num);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
总结
1、通过这次结对编程,让我更加理解团队合作的重要性,极限编程确实激发人的潜力,人与人之间的合作不是一件简单的事情——尤其当我们都早已习惯了独自工作的时候。实施结对编程技术将给软件项目的开发工作带来好处,只是这些好处必须经过缜密的思考和计划才能真正体现出来。而另一方面,两个人可能会发现虽然结对编程里没有什么技能的转移,但是让他们在不同的抽象层次解决同一个问题会让他们更快地找到解决方案,而且错误更少。
2、对于领航者(武福林同学),在这次结对编程过程中起了很大作用,如果没有他时时刻刻的盯着屏幕,纠正错误,这次结对编程也没有那么顺利完成。其实我打算用两三天的,最后只用了一下午就搞定了,对于这次合作,我是非常满意的。
3、最后,我十分感谢武福林同学,没有他孜孜不倦的态度,我不知道要犯多少错误,而且通过这次,我越来越喜欢结对编程,希望以后有更多的机会这样操作。
以上是关于软件工程第二次结对编程的主要内容,如果未能解决你的问题,请参考以下文章