zoukankan      html  css  js  c++  java
  • 结对编程

    需求分析:
    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 Stages Time(h) Senior Student Time(h) SDE
    Planning 计划 10 6
      .Estimate   .估计这个任务需要多少时间 30 6
    Development 开发 50 15
      .Analysis   .需求分析 8 6
      .Design Spec   .生成设计文档 10 5
      .Design Review   .设计复审(和同事审核设计文档) 5 4
      .Coding Standard   .代码规范(为目前的开发制定合适的规范) 3 3
      .Design   .具体设计 20 10
      .Coding   .具体编码 24 11
    Code Review   .代码复审 7 8

    ime


    结对编程总结:从老师发布作业开始我和同伴就已经在思考此次作业的思路,结对编程确实是比较好的一种编程方式,一个人写程序难免会有想不到的一些地方,两个人在一起可以取长补短,为程序的写成提供了更方便的力量。我在此次结对编程中获益颇多。

  • 相关阅读:
    UITabbarItem只显示图标
    [转]translatesAutoresizingMaskIntoConstraints详解
    [转载]podfile语法
    获取数组NSArray元素的className
    HTTP的FormData和Payload的传输格式
    WCDB错误"No matching constructor for initialization of 'WCTColumnBinding'"
    UIStakView的添加与移除
    为什么说Python采用的是基于值的内存管理模式?
    PostgreSQL数据库
    标准库 time
  • 原文地址:https://www.cnblogs.com/gyhlkq/p/4889230.html
Copyright © 2011-2022 走看看