结对编程项目---四则运算(代码)
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 WindowsFormsApplication2 { public partial class Form1 : Form { int n1, n2; Random ran; Form2 form2; public Form1() { InitializeComponent(); ran = new Random(); form2 = new Form2(); } private void button1_Click(object sender, EventArgs e) { n1 = ran.Next(int.Parse(textBox1.Text), int.Parse(textBox2.Text)); n2 = ran.Next(int.Parse(textBox1.Text), int.Parse(textBox2.Text)); form2.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { this.Dispose(); } private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (checkBox2.CheckState == CheckState.Checked) { button1.Text = "确定 selection is: " + checkBox2.Checked.ToString(); form2.setflag(1); } } private void checkBox3_CheckedChanged(object sender, EventArgs e) { if (checkBox3.CheckState == CheckState.Checked) form2.setflag(0); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex == 0) { form2.setnum(10); } else form2.setnum(20); } private void checkBox4_CheckedChanged(object sender, EventArgs e) { } private void checkBox1_CheckedChanged(object sender, EventArgs e) { form2.fenshu = !form2.fenshu; } private void textBox1_TextChanged(object sender, EventArgs e) { } } }
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 WindowsFormsApplication2 { public partial class Form2 : Form { int flag; int num,pos; double[] ans; double[] input; public bool fenshu; public Form2() { InitializeComponent(); flag = 0; num = 1; ans = new double[20]; input = new double[20]; fenshu = false; } public void setflag(int t) { flag = t; } public void setnum(int t) { num = t; } private void button1_Click(object sender, EventArgs e) { int yes = 0, no = 0; for (int i = 0; i < num; i++) { if (ans[i] == input[i]) yes++; else no++; } Form3 form = new Form3(yes,no); form.Show(); } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void button3_Click(object sender, EventArgs e) { Application.Exit(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button4_Click(object sender, EventArgs e) { listBox1.Items.Clear(); Random 局部_随机数 = new Random(); for (int i = 0; i < num; i++) { int 局部_加数 = 局部_随机数.Next(-100, 100); int 局部_被加数 = 局部_随机数.Next(-100, 100); char op; String t = ""; if (flag == 1) { op = '*'; ans[i]= 局部_加数 * 局部_被加数; t = "" + 局部_加数 + op + 局部_被加数 + "= "; } else { op = '/'; ans[i] = 局部_加数 * 1.0 / 局部_被加数; t="" + 局部_加数 + op + 局部_被加数 + "= "; } if (fenshu) { int temp1,temp2; temp1 = 局部_随机数.Next(99)+1; temp2 = 局部_随机数.Next(99)+1; t = "" + (局部_加数 * temp1) + "/" + temp1 + op + (局部_加数 * temp2) + "/" + temp2; } listBox1.Items.Add(t); } pos = 0; } private void button5_Click(object sender, EventArgs e) { if (pos < num) { input[pos++] = Double.Parse(textBox1.Text); textBox1.Text = ""; } else { textBox1.Text = "over"; } } } }
form3
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 WindowsFormsApplication2 { public partial class Form3 : Form { public Form3(int yes,int no) { InitializeComponent(); textBox1.Text = "" + (yes + no); textBox2.Text = "" + yes; textBox3.Text = "" + no; } private void Form3_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Application.Exit(); } private void textBox1_TextChanged(object sender, EventArgs e) { } } }