封装,策略,Asp换脸

封装、策略

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 算
{
    public interface Isuan
    {
         int calculate(int a, int b);
    }
    public  class add : Isuan
    {
        public int calculate(int a,int b)
        {
            return a + b;
        }
    }
    public class sub : Isuan
    {
        public int calculate(int a, int b)
        {
            return a - b;
        }
    }
    public class mal : Isuan
    {
        public int calculate(int a, int b)
        {
            return a * b;
        }
    }
    public class div : Isuan
    {
        public int calculate(int a, int b)
        {
            return a / b;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace 算
{
    class fuhao
    {
        private Isuan fh;
        public fuhao(string a)
        {
            switch(a)
            {
                case"+":
                    fh = new add();
                    break;
                case "-":
                    fh = new sub();
                    break;
                case "*":
                    fh = new mal();
                    break;
                case "/":
                    fh = new div();
                    break;
            }
        }
        public int jisuan(int a, int b)
        {
            return fh.calculate(a, b);
        }

    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace 算
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private int An;
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {            fuhao clacuter = new fuhao(comboBox1.Text);            An = clacuter.jisuan(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
            if (textBox3.Text == An.ToString())
            {
                MessageBox.Show("回答正确!");
            }
            else
            {
                MessageBox.Show("回答错误!");
            }
            textBox1.Clear();
            textBox2.Clear();
            comboBox1.Text = "";
            textBox3.Clear();
        }

        private void textBox3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                fuhao clacuter = new fuhao(comboBox1.Text);
                An = clacuter.jisuan(int.Parse(textBox1.Text), int.Parse(textBox2.Text));

                if (textBox3.Text == An.ToString())
                {
                    MessageBox.Show("回答正确!");
                }
                else
                {
                    MessageBox.Show("回答错误!");
                }
                textBox1.Clear();
                textBox2.Clear();
                comboBox1.Text = "";
                textBox3.Clear();
            }
        }
    }
}


asp换脸

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///fuhao 的摘要说明
/// </summary>
public class fuhao
{
    private Isuan s;
    public fuhao(string a)
    {
        switch (a)
        {
            case"+":
                s = new add();
                break;
            case "-":
                s = new sub();
                break;
            case "*":
                s = new cml();
                break;
            case "/":
                s = new div();
                break;
        }
    }
    public int suan(int a, int b)
    {
        return s.cla(a,b);
    }

}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///suan 的摘要说明
/// </summary>

     public interface Isuan
    {
         int cla(int a, int b);
    }
    public class add:Isuan
    {
        public int cla(int a, int b)
        {
            return a + b;
        }
    }
    public class sub:Isuan
    {
        public int cla(int a, int b)
        {
            return a - b;
        }
    }
    public class cml:Isuan
    {
        public int cla(int a, int b)
        {
            return a * b;
        }
    }
    public class div:Isuan
    {
        public int cla(int a, int b)
        {
            return a / b;
        }
    }
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
{
    private int An;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        fuhao b = new fuhao(TextBox2.Text);
        An=b.suan(int.Parse(TextBox1.Text),int.Parse(TextBox3.Text));
        if (TextBox4.Text == An.ToString())
        {
            Response.Write("回答正确!");
        }
        else
        {
            Response.Write("回答错误!");
        }
    }
}

时间: 2024-08-10 04:09:05

封装,策略,Asp换脸的相关文章

Angular2-三种样式封装策略的区别

Angular2有三种样式封装方式,分别是None.Native.Emulated. 可用元数据"encapsulation"配置,配置方式如下: encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.Emulated encapsulation: ViewEncapsulation.Native 三者有什么区别呢? None: 使用None策略,组件配置的样式没做任何封装:它会直接在文档树种插入&

自己封装的ASP.NET的MYSQL的数据库操作类

/** * 作者:牛腩 * 创建时间:2010年3月7日17时35分 * 类说明:对MYSQL数据库的操作类 */ using System; using System.Data; using MySql.Data.MySqlClient; namespace Niunan.BYLW.Utility { /// <summary>对MYSQL数据库的操作类 /// /// </summary> public class MYSQLHelper { private MySqlConn

asp.net实现运算+代码封装+策略模式

设计界面: 测试界面: 代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> ///Class2 的摘要说明 /// </summary> public interface ITaxStragety { int Calcul(int a, int b); } class Class2 : ITaxStragety { public

简易计算器(代码+封装+策略模式)

具体设计思路:1.先创建一个Windows窗体.2.添加所需控件,修改相应的属性值.3.对控件编写代码,使之实现相应的功能.4.设计出一个四则运算雏形后再根据需求完善代码.5.进行测试分析.6.对程序进行PSP耗时分析. 运行结果: 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using Sys

计算器简单封装和ASP.net

封装: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 计算器 { class Richnone { public string fuhao;//计算符号 public double result;//计算结果 private double x;//第一个数 public double X { get { return x; } set { x = va

四则运算《《《代码封装 策略模式

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace sum 7 { 8 class Class1 9 { 10 public interface Calculator //声明计算接口 11 { 12 double Cal(double x, double y); 13 } 14 private double x; //定义x变量:

ASP.NET内置对象(转)

asp.net学习笔记,在网上找了比较全的总结.转自:http://www.cnblogs.com/MyBeN/archive/2011/03/23/1992591.html ASP.NET中常用的内置对象(一) ASP.NET中常用的内置对象及功能说明如下所示:对 象 名 功  能  说  明Page 用于操作整个页面Response 用于向浏览器输出信息Request 用于获取来自浏览器的信息Server                    提供服务器端的一些属性和方法Applicatio

asp.net内置对象

转:http://www.cnblogs.com/MyBeN/archive/2011/03/23/1992591.html (1)简述ASP.NET内置对象. 答:ASP.NET提供了内置对象有Page.Request.Response.Application.Session.Server.Mail和Cookies.这些对象使用户更容易收集通过浏览器请求发送的信息.响应浏览器以及存储用户信息,以实现其他特定的状态管理和页面信息的传递. (2)简述Response对象. 答:Response对象

【LabVIEW技巧】策略模式

前言 在之前的文章中,我们提到了如何学习OOP以及对应的简单工厂模式,由于时间比较长,我们先回顾一下之前讲到的一些内容,然后继续了解策略模式. 为什么学习OOP 在测控系统的软件开发过程中,我们LabVIEW工程师一直认为程序完成功能就可以了,但是随着程序的越来越复杂,我们发现很多情况下成型系统到后期无法添加功能或很难添加功能. 是什么阻碍了我们软件系统的开发?为什么在需求沟通不明确的前期,我们无法开发软件:在需求明确的后期,又无法对软件进行灵活修改. 如果大家仔细分析中国的四大发明,就会发现活