标签:
设计界面:
测试界面:
代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> ///Class2 的摘要说明 /// </summary> public interface ITaxStragety { int Calcul(int a, int b); } class Class2 : ITaxStragety { public int Calcul(int a, int b) { return a + b; } } class sub : ITaxStragety { public int Calcul(int a, int b) { return a - b; } } class sheng : ITaxStragety { public int Calcul(int a, int b) { return a * b; } } class chu : ITaxStragety { public int Calcul(int a, int b) { return a / b; } } public class tiaoyong { public int num1 = 0; public int num2 = 0; public void yunsuan(string str) { if (str == "+") { Class2 cl = new Class2(); cl.Calcul(num1, num2); } if (str == "-") { sub su = new sub(); su.Calcul(num1, num2); } if (str == "*") { sheng sh= new sheng(); sh.Calcul(num1, num2); } if (str == "/") { chu ch = new chu(); ch.Calcul(num1, num2); } } }
web代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class _Default : System.Web.UI.Page { int count = 0; protected void Page_Load(object sender, EventArgs e) { } string path = "E:\rtf"; public static int sum; int i = 1; protected void Button1_Click(object sender, EventArgs e) { StreamWriter writer = File.AppendText("writer.txt"); writer.WriteLine(TextBox1.Text); writer.Close(); StreamWriter writer1 = File.AppendText("writer.txt1"); writer1.WriteLine(TextBox5.Text); writer1.Close(); StreamWriter writer2 = File.AppendText("writer.txt2"); writer2.WriteLine(TextBox2.Text); writer2.Close(); TextBox6.Text += TextBox1.Text + TextBox5.Text + TextBox2.Text + "\r\n"; string f = TextBox5.Text; switch (f) { case "+": sum = int.Parse(TextBox1.Text) + int.Parse(TextBox2.Text); TextBox7.Text += sum + "\r\n"; shizi(); break; case "-": sum = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text); shizi(); TextBox7.Text += sum + "\r\n"; break; case "*": sum = int.Parse(TextBox1.Text) * int.Parse(TextBox2.Text); shizi(); TextBox7.Text += sum + "\r\n"; break; case "/": sum = int.Parse(TextBox1.Text) / int.Parse(TextBox2.Text); shizi(); TextBox7.Text += sum + "\r\n"; break; default: break; } } public void shizi() //编写试题的方法 { TextBox1.Text = ""; TextBox2.Text = ""; TextBox5.Text = ""; } protected void Button2_Click(object sender, EventArgs e) { if (Button2.Text == "显示答案") { TextBox7.Visible = true; Button2.Text = "隐藏答案"; } else if (Button2.Text == "隐藏答案") { TextBox7.Visible = false; Button2.Text = "显示答案"; } } protected void Button3_Click(object sender, EventArgs e) { string[] ll = new string[100]; ll = File.ReadAllLines("writer.txt"); TextBox8.Text = ll[0]; string[] lli = new string[100]; lli = File.ReadAllLines("writer.txt1"); TextBox9.Text = lli[0]; string[] llp = new string[100]; llp = File.ReadAllLines("writer.txt2"); TextBox10.Text = llp[0]; } protected void Button4_Click(object sender, EventArgs e) { File.WriteAllText("writer.txt", string.Empty); File.WriteAllText("writer1.txt", string.Empty); File.WriteAllText("writer2.txt", string.Empty); } protected void Button5_Click(object sender, EventArgs e) { tiaoyong ti =new tiaoyong(); ti.num1=int.Parse(TextBox1.Text); ti.num2=int.Parse(TextBox2.Text); string st=TextBox5.Text; ti.yunsuan(st); //TextBox7 = Convert.ToString(mm.c); // daan.Text += sum + "\r\n"; // tiaoyong // ee.c = int.Parse(left.Text); // ee.n = int.Parse(right.Text); // string a = Convert.ToString(mm.m); // ee.yunsuan(a); //string m = TextBox5.Text; //switch (m) //{ // 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; // case "/": // sum = int.Parse(TextBox1.Text) / int.Parse(TextBox2.Text); // break; // default: // break; //} if (TextBox11.Text == sum.ToString()) { Response.Write("<script>alert(‘回答正确‘)</script>"); } else if (TextBox11.Text != sum.ToString()) { Response.Write("<script>alert(‘回答错误‘)</script>"); } TextBox11.Text = ""; string[] ll = new string[100]; ll = File.ReadAllLines("writer.txt"); TextBox8.Text = ll[i]; string[] lli = new string[100]; lli = File.ReadAllLines("writer1.txt"); TextBox9.Text = lli[i]; string[] llp = new string[100]; llp = File.ReadAllLines("writer2.txt"); TextBox10.Text = llp[i]; i++; } }
策略封装代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace shuxuefudao { public interface ITaxStragety { int Calcul(int a,int b); } class Class2 : ITaxStragety { public int Calcul(int a, int b) { return a + b; } } class sub : ITaxStragety { public int Calcul(int a, int b) { return a - b; } } class sheng : ITaxStragety { public int Calcul(int a, int b) { return a *b; } } class chu : ITaxStragety { public int Calcul(int a, int b ) { return a / b; } } class tiaoyong { public int c=0; public int n=0; public void yunsuan(string m) { if(m=="+") { Class2 ss = new Class2(); ss.Calcul(c,n); } if(m=="-") { sub ww = new sub(); ww.Calcul(c,n); } if(m=="*") { sheng qq = new sheng(); qq.Calcul(c,n); } if(m=="/") { chu pp = new chu(); pp.Calcul(c,n); } } } }
标签:
原文地址:http://www.cnblogs.com/lydz/p/5058106.html