标签:
需求分析 :
0到10的整数(随机生成)运算。
思路
代码:
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 简易计算器 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static int Count = 0; public static int right = 0; private void textBox3_KeyDown(object sender, KeyEventArgs e) { int sum; string a = label1.Text; switch (a) { case "+": sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text); break; case "-": sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text); break; case "*": sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text); break; default: sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text); break; } if (e.KeyCode == Keys.Enter) { if (textBox3.Text == sum.ToString()) right++; RandomNum(); } } private void button2_Click(object sender, EventArgs e) { textBox3.Enabled = true; Form2 frm2 = new Form2(); frm2.ShowDialog(); } 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) { label1.Text = "*"; } private void button6_Click(object sender, EventArgs e) { label1.Text = "/"; } private void button1_Click_1(object sender, EventArgs e) { RandomNum(); } private void RandomNum() { Random random = new Random(); int number1, number2; number1 = random.Next(1, 11); number2 = random.Next(1, 11); textBox1.Text = number1.ToString(); textBox2.Text = number2.ToString(); textBox3.Text = ""; Count++; } } }
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 简易计算器 { 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() + "%"; } } }
结果:
PSP耗时分析:
总结:忙了好久,貌似晚了!!不过好歹做出来了,一直也没怎么好好听过课,也有朋友的帮忙,总的感觉还是听有趣的。再接再厉吧。
标签:
原文地址:http://www.cnblogs.com/lmyblogs/p/4858024.html