Implement the package of Calculator code in ASP.

Source: Internet
Author: User

first, the specific code

Default2.aspx.cs

 Public Partial classchapter1_default2:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {          }    intA =0; Private intT;  Public Static intCount=0;  Public Static  intright=0; protected voidButton1_Click (Objectsender, EventArgs e) {        intA =int.        Parse (TextBox1.Text.Trim ()); intb =int.        Parse (TextBox3.Text.Trim ()); Char C=Convert.tochar (TextBox2.Text.Trim ()); Lei Con=NewLei (); Con.        Max (A, B, c); if(Con. Answer = =int. Parse (TextBox4.Text.Trim ())) {Label1.Text=("Congratulations, little one! Answer right! "); Label1.forecolor=Color.Blue; Right++; }        Else{Label1.Text= ("answer the wrong, continue to refuel! Kids"); Label1.forecolor=color.red; }           }      protected voidButton2_Click (Objectsender, EventArgs e) {Count++; StreamWriter baocun1= File.appendtext ("C:\\baocun1.txt"); Baocun1.        WriteLine (TextBox1.Text); Baocun1.        Close (); StreamWriter baocun2= File.appendtext ("C:\\baocun2.txt"); Baocun2.        WriteLine (TextBox2.Text); Baocun2.        Close (); StreamWriter Baocun3= File.appendtext ("C:\\baocun3.txt"); Baocun3.        WriteLine (TextBox3.Text); Baocun3.        Close (); LISTBOX1.ITEMS.ADD (TextBox1.Text+ TextBox2.Text + TextBox3.Text +"="); TextBox1.Text=""; TextBox2.Text=""; TextBox3.Text=""; }    protected voidButton3_Click (Objectsender, EventArgs e) {Textbox1.backcolor=Color.yellow; Textbox2.backcolor=Color.yellow; Textbox3.backcolor=Color.yellow; Textbox4.backcolor=Color.yellow; Textbox1.enabled=false; Textbox2.enabled=false; Textbox3.enabled=false; string[] m =New string[ -]; M= File.ReadAllLines ("C:\\baocun1.txt"); TextBox1.Text=M[a]; string[] n =New string[ -]; N= File.ReadAllLines ("C:\\baocun2.txt"); TextBox2.Text=N[a]; string[] v =New string[ -]; V= File.ReadAllLines ("C:\\baocun3.txt"); TextBox3.Text=V[a]; A++; }    protected voidButton4_Click (Objectsender, EventArgs e) {TextBox1.Text=""; TextBox2.Text=""; TextBox3.Text=""; Textbox4.text=""; Label1.Text=""; }    protected voidButton5_click (Objectsender, EventArgs e) {Label6.text="Total"; Label7.text="correct"; Label8.text="correct rate"; Label3.text=count.tostring (); Label4.text=Right .        ToString (); Label5.text= ((Right/(Double) (Count)) * -). ToString () +"%"; }       }

Encapsulation Code:

Class code to be written in App_Code.

 Public classlei{ Public intSum;  Public intAnswer {Get{returnSum;} }         Public intMax (intN1,intN2,CharYunsuanfu) {            if(Yunsuanfu = ='+')            {                returnSum = n1 +N2; }            Else if(Yunsuanfu = ='-')            {                                   returnSum = N1-N2; }            Else if(Yunsuanfu = ='/')            {                                   returnSum = n1/N2; }            Else if(Yunsuanfu = ='*')            {                returnSum = N1 *N2; }            returnSum; }    }    
second, the test

Implement the package of Calculator code in ASP.

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.