您的位置:首页 > 编程语言

结对编程

2015-10-18 13:57 211 查看
需求分析:
1.对产品功能性的需求:要求编写一个能对0-10之间的随机整数进行四则运算的“软件”,程序能接收用户输入的整数答案,并判断对错。程序结束时,统计出答对答错的题目数量。
2.对产品开发过程的需求:1)处理用户的错误输入,比如输入字母或符号等,处理除法运算中分母为0的情况,处理结果为负数的情况,保证是小学水平不出现负数,比如不能出现5-8=-3这种情况;2)用户可以设定倒计时;3)用户可以设定随机整数的范围和题目数量;4)用户可以选择哪种计算类型,比如加减乘除,或可选择软件随机生成四则运算中的一种。
3.非功能性需求:可以同时使用,没有冲突。
4.综合需求:这是一个较为简单的四则运算,用C#很快就能做出来。

具体设计思路:
1.先创建一个Windows窗体。
2.添加所需控件,修改相应的属性值。
3.对控件编写代码,使之实现相应的功能。
4.设计出一个四则运算雏形后再根据需求完善代码,添加增量。
5.进行测试分析。
6.对程序进行PSP耗时分析。

代码实现:
Form1代码:
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 calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int Count = 0;
public static int right = 1;
public static int sum;
private int t = 60;

private void js()
{
Random un = new Random();
int a, b;
a = un.Next(1, 11);
b = un.Next(1, 11);
textBox1.Text = a.ToString();
textBox2.Text = b.ToString();
textBox3.Text = "";

}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "+";
}

private void button2_Click(object sender, EventArgs e)
{
label1.Text = "-";
}

private void button3_Click(object sender, EventArgs e)
{
label1.Text = "*";
}

private void button4_Click(object sender, EventArgs e)
{
label1.Text = "/";
}

private void button5_Click(object sender, EventArgs e)
{
if (textBox3.Text == sum.ToString())
{

Count++;
right++;
js();
}
else
{
Count++;
js();
}
label4.Text = t.ToString();
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Start();
RandomNum();

}

private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (label1.Text == "+")
sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
else if (label1.Text == "-")
sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
else if (label1.Text == "*")
sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
else sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
}

private void button6_Click(object sender, EventArgs e)
{

if (textBox3.Text == sum.ToString())
{

Count++;
right++;
js();
}
else
{
if (int.Parse(textBox1.Text) - int.Parse(textBox2.Text) < 0)
{
MessageBox.Show("结果不能为负!");
}
Count++;
js();
}
;
}
private void RandomNum()
{
Random ran = new Random();

}

private void button7_Click(object sender, EventArgs e)
{
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();

}

private void timer1_Tick(object sender, EventArgs e)
{
if (t <= 0)
{
timer1.Enabled = false;
textBox3.Enabled = false;
MessageBox.Show("时间到!");
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
t = t - 1;
label4.Text = t.ToString();
}
}
}
Form2代码:
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 calculator
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = Form1.Count.ToString();
textBox2.Text = Form1.right.ToString();
textBox3.Text = ((Form1.right / (double)(Form1.Count)) * 100).ToString() + "%";
}

}
}











由于能力有限,老师要求的增量并没有做完,我做出来的增量有:

1.用户可以设定倒计时;
2.处理结果为负数的情况
3.用户可以选择哪种计算类型,比如加减乘除,或可选择软件随机生成四则运算中的一种。
可能做出来的并不完整,但我和同伴已努力在做了。

PSP耗时分析

Personal Software Process StagesTime(h) Senior StudentTime(h) SDE
Planning计划106
.Estimate.估计这个任务需要多少时间306
Development开发5015
.Analysis.需求分析86
.Design Spec.生成设计文档105
.Design Review.设计复审(和同事审核设计文档)54
.Coding Standard.代码规范(为目前的开发制定合适的规范)33
.Design.具体设计2010
.Coding.具体编码2411
Code Review.代码复审78
总结:

通过这次结对编程,我觉得两个人一块做比一个人做更有思路,可以相互讨论,比较有意思。以后我们会更加努力的!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: