封装
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 出题 { class calcuall { Calculator calculator = new Calculator(); private string opreator2; public string Operator2 { set { opreator2 = value; } } public void cal() { if (opreator2 == "+") { calculator.Add(); } if (opreator2 == "-") { calculator.sub(); } if (opreator2 == "/") { calculator.division(); } if (opreator2 == "*") { calculator.multiplication(); } } } }
策略
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 出题 { class Calculator { private int z; private int x; private int y; private string operator1; private int answer; public int X { set { x = value; } } public int Y { set { y = value; } } public string Operator1 { set { operator1 = value; } } public int Answer { get { return answer; } } public void Add() { answer= x + y; } public void sub() { if (x > y) { answer = x - y; } else { z = y; y = x; x = z; answer = x - y; } } public void multiplication() { answer = x * y; } public void division() { if (y == 0) { z = y; y = x; x = z; answer = x / y; } else { answer = x / y; } } } }
from1
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; using System.IO; namespace 出题 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string fnm = @"one"; string fnmm = @"tow"; string fnmn = @"fuhao"; Writeclear write1 = new Writeclear(fnm,fnmm,fnmn); write1.X = textBox1.Text; write1.Y = textBox2.Text; write1.Operator1 = comboBox1.Text; write1.write(); textBox1.Clear(); textBox2.Clear(); } private void button2_Click(object sender, EventArgs e) { Form2 fam = new Form2(); fam.ShowDialog(); } private void button3_Click(object sender, EventArgs e) { string fnm = @"one"; string fnmm = @"tow"; string fnmn = @"fuhao"; Writeclear write1 = new Writeclear(fnm, fnmm, fnmn); write1.clear(); } } }
from2
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; using System.IO; namespace 出题 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } int i=1; public static int count = -1; public static int right = 0; private void timer1_Tick(object sender, EventArgs e) { try { int t = int.Parse(textBox5.Text); if (t <= 0) { timer1.Enabled = false; textBox5.Enabled = false; MessageBox.Show("时间到了!"); Form3 fr3 = new Form3(); fr3.ShowDialog(); } t = t - 1; textBox5.Text = t.ToString(); } catch { } } private void button1_Click(object sender, EventArgs e) { try { string t = textBox5.Text; textBox5.Text = t; timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); } catch { } baaa(); count++; } private void textBox4_KeyDown(object sender, KeyEventArgs e) { Calculator calculator=new Calculator(); calcuall cal=new calcuall(); calculator.X=int.Parse(textBox1.Text); calculator.Y=int.Parse(textBox3.Text); calculator.Operator1=textBox2.Text; cal.Operator2=textBox2.Text; if (e.KeyCode == Keys.Enter) { if (textBox4.Text ==calculator.Answer.ToString() ) { MessageBox.Show("回答正确!"); right++; } else { MessageBox.Show("回答错误!"); } textBox4.Clear(); baaa(); count++; } } private void button3_Click(object sender, EventArgs e) { this.Close(); } private void button2_Click(object sender, EventArgs e) { textBox5.Enabled = false; Form3 fonn = new Form3(); fonn.ShowDialog(); } private void baaa() { string[] line = File.ReadAllLines("one"); if (i < line.Length) { textBox1.Text = line[i]; string[] lines = File.ReadAllLines("tow"); textBox3.Text = lines[i]; string[] lin = File.ReadAllLines("fuhao"); textBox2.Text = lin[i]; } i++; if (i == line.Length + 1) { Form3 fonn = new Form3(); fonn.ShowDialog(); } } } }
from3
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 Form3 : Form { public Form3() { InitializeComponent(); } private void Form3_Load(object sender, EventArgs e) { textBox1.Text = Form2.right.ToString(); textBox2.Text = Form2.count.ToString(); textBox3.Text = ((Form2.right / (double)(Form2.count)) * 100).ToString() + "%"; } } }