ASP. NET implementation + code encapsulation + Policy mode

Source: Internet
Author: User

Design interface:

Test interface:

Code:

Using system;using system.collections.generic;using system.linq;using system.web; <summary>///class2 Summary description///</summary> public interface itaxstragety {int Calcul (int A, in     T 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-A;         }} 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 (); All             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 code:

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 ("writ            Er.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 ()//method of writing the question {TextBox1.text = "";            TextBox2.Text = "";        Textbox5.text = "";            } protected void Button2_Click (object sender, EventArgs e) {if (Button2.text = = "Show Answer")                {textbox7.visible = true;            Button2.text = "Hide Answer";                } else if (Button2.text = = "Hide Answer") {textbox7.visible = false;             Button2.text = "show Answer"; }} protected void Button3_Click (object sender, EventArgs e) {string[] ll = new STRING[10            0];            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 (' answer correct ') </script>"); } else if (textbox11.text! = sum.            ToString ()) {Response.Write ("<script>alert (' answer error ') </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++; }    }

Policy Encapsulation Code

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-A;                               }} class Sheng:itaxstragety {public int Calcul (int a, int b) {return a *b; }} class Chu:itaxstragety {public int Calcul (int a, int b) {retur        n 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 (); Sql                                         Calcul (C,n);                 } if (m== "/") {chu pp = new Chu (); Pp.                           Calcul (C,n); }                   }    }}

  

ASP. NET implementation + code encapsulation + Policy mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.