作业四: 结对编程项目---四则运算
form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 四则运算1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private int t = 20;//计时20s public static int Count = 0; public static int right = 0; System.Media.SoundPlayer s = new System.Media.SoundPlayer(@"D:KUGOUSONGNO.9.wav");//插入音乐 private void timer1_Tick(object sender, EventArgs e)//时间计时器 { if (t <= 0) { timer1.Enabled = false; textBox4.Enabled = false; MessageBox.Show("时间到!"); textBox4.Enabled = false; Form2 frm2 = new Form2(); frm2.ShowDialog(); } t = t - 1; label2.Text = t.ToString(); } private void button6_Click(object sender, EventArgs e)//开始按钮 { label2.Text = t.ToString(); timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); } private void szys() { Random rd = new Random(); int r1, r2; if (textBox4.Text == "" && textBox5.Text == "") { MessageBox.Show("请输入取值范围!"); return; } r1 = rd.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); r2 = rd.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); textBox1.Text = r1.ToString(); textBox1.Text = r2.ToString(); string[] fuhao = new string[] { "+", "-", "×", "÷" }; label3.Text = fuhao[rd.Next(0, 9)]; int result = 0; switch (label3.Text) { case "+": result = int.Parse(textBox1.Text) + int.Parse(textBox1.Text); return; case "-": if (int.Parse(textBox1.Text) >= int.Parse(textBox1.Text)) { result = int.Parse(textBox1.Text) - int.Parse(textBox1.Text); } else { MessageBox.Show("进行下一题!"); } return; case "×": result = int.Parse(textBox1.Text) * int.Parse(textBox1.Text); return; case "÷": if (textBox1.Text == "0") { MessageBox.Show("请回车继续答题!"); } else { result = int.Parse(textBox1.Text) / int.Parse(textBox1.Text); } return; } } private void szysNum()//加减乘除的设置 { Random ran = new Random(); int n1, n2; if (textBox4.Text == "" && textBox5.Text == "") { MessageBox.Show("请输入取值范围!"); return; } n1 = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); n2 = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); textBox2.Text = n1.ToString(); textBox1.Text = n2.ToString(); textBox6.Text = ""; } private void button7_Click(object sender, EventArgs e)//停止 { timer1.Stop(); Form2 frm2 = new Form2(); frm2.ShowDialog(); } private void button1_Click(object sender, EventArgs e) { label9.Text = button1.Text; szysNum(); }//+ private void button2_Click(object sender, EventArgs e) { label9.Text = button2.Text; szysNum(); }//- private void button3_Click(object sender, EventArgs e) { label9.Text = button3.Text; szysNum(); }//* private void button4_Click(object sender, EventArgs e) { label9.Text = button4.Text; szysNum(); }//chu private void textBox3_KeyDown(object sender, KeyEventArgs e) { int result = 0; string s = label10.Text; if (Count == int.Parse(textBox3.Text)) { Form2 frm2 = new Form2();//转到结束界面 frm2.ShowDialog(); } switch (s) { case "+": result = int.Parse(textBox2.Text) + int.Parse(textBox1.Text); break; case "-": if (int.Parse(textBox2.Text) >= int.Parse(textBox1.Text)) { result = int.Parse(textBox2.Text) - int.Parse(textBox1.Text); } else { MessageBox.Show("进行下一题!"); } break; case "×": result = int.Parse(textBox2.Text) * int.Parse(textBox1.Text); break; case "÷": if (textBox1.Text == "0") { MessageBox.Show("请回车继续答题!"); } else { result = int.Parse(textBox2.Text) / int.Parse(textBox1.Text); } break; } if (e.KeyCode == Keys.Enter) { if (textBox6.Text == result.ToString()) { right++; Count++; MessageBox.Show("恭喜回答正确!"); } else { if (textBox1.Text == "0" || int.Parse(textBox2.Text) - int.Parse(textBox1.Text) < 0) { szysNum(); } else { MessageBox.Show("抱歉!"); szysNum(); Count++; } } szysNum(); } } private void button8_Click(object sender, EventArgs e) { Form3 frm3 = new Form3(); frm3.ShowDialog(); } private void button5_Click(object sender, EventArgs e) { if (textBox4.Text == "" && textBox5.Text == "") { MessageBox.Show("请输入取值范围!"); return; } else { for (int i = 0; i < int.Parse(textBox3.Text); i++) { szys(); } } } } }
form3.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 四则运算1 { public partial class Form3 : Form { public Form3() { InitializeComponent(); } private String[] strs = new String[] { "+", "-", "/", "*" }; private Random r3 = new Random(); private void button4_Click(object sender, EventArgs e) { listView1.Items.Add("题目:" + textOne.Text + textC.Text + textTwo.Text + "="); } private void button5_Click(object sender, EventArgs e) { listView1.Items.Clear(); } private void button1_Click(object sender, EventArgs e) { Random r1 = new Random(); int num1 = r1.Next(-10, 10); if (num1 < 0) textOne.Text = "(" + num1.ToString() + ")"; else textOne.Text = num1.ToString(); } private void button3_Click(object sender, EventArgs e) { textC.Text = Getstr(1); } private void button2_Click(object sender, EventArgs e) { Random r2 = new Random(); int num2 = r2.Next(-10, 10); if (num2 < 0) textTwo.Text = "(" + num2.ToString() + ")"; else textTwo.Text = num2.ToString(); } private string Getstr(int num) { string result = ""; for (int i = 0; i < num; i++) { int r = r3.Next(strs.Length); result += strs[r]; } return result; } private void button6_Click(object sender, EventArgs e) { Form1 frm1 = new Form1(); frm1.ShowDialog(); } } }
总结:
(1)我和胡新宇同学130201106 是一组的 博客地址http://www.cnblogs.com/hxy94264/
(2)我们两个做的是四则运算,有题目的范围 运算符的选择计时器到时间的操作 ,只需要在取值范围中轻轻的输入进去自己想要的范围就可以做题了呢,想做多少做多少。不想做了点击退出即可方便快捷,加减乘除做腻了呢可以点击普通版进去做一些带括号的负数的计算题,简单快捷易上手。
(3)在我们两个人做的过程中我主要负责程序界面设计通过从网上搜集资料问同学等等完成作业
(4)优点:代码的复审过程很艰难也发现了一一部分问题认真的代码复审让我们可以进一步的完善此软件,两个人共同完成可以提高效率,减少出错的频率
缺点:俩人想法不一致容易产生争执
(5)一起合作讨论时的照片