码迷,mamicode.com
首页 > Web开发 > 详细

运用ASP.NET实现

时间:2015-12-28 22:00:00      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

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

运用ASP.NET实现

标签:

原文地址:http://www.cnblogs.com/harlem/p/5083647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!