• 运用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实现出来了。。

  • 相关阅读:
    es6 --- var const let
    HTTP -- 请求/响应 结构
    点击下载文件
    计算机当前时间
    js -- img 随着鼠标滚轮的变化变化
    vue --- 全局守卫
    vue -- 路由懒加载
    vuex -- 状态管理
    js对数组进行操作
    高性能网站建设
  • 原文地址:https://www.cnblogs.com/harlem/p/5083647.html
Copyright © 2020-2023  润新知