• 运用ASP.NET实现


    calation.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    ///Calation 的摘要说明
    /// </summary>
    public class Calation
    {
    	public Calation()
    	{
    		//
    		//TODO: 在此处添加构造函数逻辑
    		//
    	}
    }
         interface ODD
        {
            int members(int a, int b);
    
        }
        class Class2 : ODD
        {
    
            public int members(int a, int b)
            {
                return a + b;
            }
    
        }
        class sub : ODD
        {
            public int members(int a, int b)
            {
                return a - b;
            }
    
        }
        class Mul : ODD
        {
            public int members(int a, int b)
            {
                return a * b;
    
            }
    
        }
        class Div : ODD
        {
            public int members(int a, int b)
            {
                return a / b;
    
            }
        }
    
       public class suanfa
        {
            private ODD jisuan;
            public void math(string TR)
            {
                switch (TR)
                {
                    case "+":
                        jisuan = new Class2();
                        break;
                    case "-":
                        jisuan = new sub();
                        break;
                    case "*":
                        jisuan = new Mul();
                        break;
                    case "/":
                        jisuan = new Div();
                        break;
                }
    
            }
            public int clation(int a, int b)
            {
                return jisuan.members(a, b);
            }
        }
    

     Default.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rando();
            }
    
        }
        public void rando()
        {
            Random an = new Random();
            int a=an .Next(0,100);
            int b=an.Next(0,100);
            TextBox1.Text = a.ToString();
            TextBox3.Text = b.ToString();
            
            string [] ann=new string[]{"+","-","*","/"};
    
            TextBox2.Text = ann[new Random().Next(0, 4)];
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(TextBox1.Text);
            int b = Convert.ToInt32(TextBox3.Text);
            suanfa suanfa1 = new suanfa();
            suanfa1.math(TextBox2.Text);
            int answer = suanfa1.clation(a, b);
            if (answer.ToString() == TextBox4.Text)
            {
                Response.Write("回答正确!");
            }
            else
            {
                Response.Write("回答错误!");
                Response.Write(answer.ToString());
            }
            TextBox4.Text = "";
            rando();
        }
    }
    

      测试截图:

    虽然界面简单 但还是用asp实现出来了。。

  • 相关阅读:
    面向对象
    通信编程
    系统编程和单片机编程思维的改变
    代码是设计出来的
    好的代码设计
    通信传输协议数据包的独门绝技使用-----------共用体的使用
    $|^|z||/a|/l
    eubacteria|endosymbiosis|基因转移
    ctDNA|endosymbiosis
    mtDNA|ctDNA|cpDNA|
  • 原文地址:https://www.cnblogs.com/harlem/p/5083647.html
Copyright © 2020-2023  润新知