四则运算扩展
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 static int Count, right,z;
public int t = 60;
public static char a;
public static int i = 1, j = 10;
public Form1()
{
InitializeComponent();
}
private void jisuan()
{
Random ran = new Random();
int n1, n2;
n1 = ran.Next(i, j);
n2 = ran.Next(i, j);
textBox6.Text = n1.ToString();
textBox7.Text = n2.ToString();
textBox8.Text = "";
}
private void jianfa()
{
Random ran = new Random();
int n1, n2;
n1 = ran.Next(i, j);
n2 = ran.Next(n1, j);
textBox6.Text = n2.ToString();
textBox7.Text = n1.ToString();
textBox8.Text = "";
}
private void timer1_Tick(object sender, EventArgs e)
{
if (t == 0)
{
timer1.Enabled = false;
label12.Text = t.ToString();
textBox8.Enabled = false;
MessageBox.Show("时间到了!");
}
t = t - 1;
label12.Text = t.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
textBox1.Text = "+";
}
if (textBox1.Text == "-")
jianfa();
else
jisuan();
if (textBox12.Text == "")
{
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Start();
}
else
{
z = int.Parse(textBox12.Text);
}
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
t = int.Parse(textBox2.Text);
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
i = int.Parse(textBox3.Text);
}
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
j = int.Parse(textBox4.Text);
}
private void panduan(int sd)
{
try
{
int s = int.Parse(textBox8.Text);
if (s == sd)
{
right++;
Count++;
}
else
Count++;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
if (z == Count)
{
textBox8.Enabled = false;
MessageBox.Show("计算结束!");
}
textBox9.Text = Count.ToString();
textBox10.Text = right.ToString();
textBox11.Text = ((right / (double)Count) * 100).ToString() + "%";
if (textBox1.Text == "-")
jianfa();
else
jisuan();
}
private void textBox8_KeyDown(object sender, KeyEventArgs e)
{
int sr;
if (textBox1.Text == "+")
{
sr = int.Parse(textBox6.Text) + int.Parse(textBox7.Text);
if (e.KeyCode == Keys.Enter)
{
panduan(sr);
}
}
else if (textBox1.Text == "-")
{
sr = int.Parse(textBox6.Text) - int.Parse(textBox7.Text);
if (e.KeyCode == Keys.Enter)
{
panduan(sr);
}
}
if (textBox1.Text == "*")
{
sr = int.Parse(textBox6.Text) * int.Parse(textBox7.Text);
if (e.KeyCode == Keys.Enter)
{
panduan(sr);
}
}
}
}
}
运算图片如下:
结对编程合作人:和彦鹏
需求分析:
psp | 计划耗时 | 实际耗时 |
估计用时 | 4 | 6 |
需求分析 | 0.5 | 0.5 |
生成文档 | 0.5 | 0.5 |
设计复审 | 0.5 | 1 |
具体设计 | 1 | 1.5 |
具体编码 | 1 | 1.5 |
事后总结 | 0.5 | 0.5 |
运用窗体应用程序,用textBox控件来接收用户的输入,来实现用户的不同需求,来实现用户最大的利益化。
由于除法的设计比较有难度,经过几次努力仍没用按照老师的要求做出来,证明,自身努力不够,知识有限。所以,以后我会更加努力学习。望老师理解。
和和彦鹏同学结对编程以后,我感觉到了我自身的不足。还有许多知识需要学习。例如:keyDown事件,等专业知识。