封装、策略

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("回答错误!");
}
}
}

最新文章

  1. MVC 访问IFrame页面Session过期后跳转到登录页面
  2. fzu1342
  3. XCode 7.3.1(dmg) 官方直接下载地址
  4. 阿里云消息队列MQ_HTTP接入 for .NetCore 简单例子
  5. Linux学习笔记(14)文件系统管理
  6. 通过 XtraBackup 实现不停机不锁表搭建主从同步
  7. [每日一题] OCP1z0-047 :2013-08-26 TIMESTAMP WITH LOCAL TIME ZONE....................112
  8. MiZ702学习笔记13——ZYNQ通过AXI-Lite与PL交互
  9. 输出一个等边三角形的字母阵,等边三角形的两腰为字母A,往里靠依次字母大一个(详细题目文章中描述)
  10. qmake使用实践:包含动态库的Qt4工程
  11. (转)AspNetPager查询分页问题(点击页码,不再是查询后的数据集)viewstate解决
  12. 一个简单顺序表的C++实现
  13. IE6,IE7,IE8下报JS错误:expected identifier, string or number的原因及解决的方法
  14. Linux下PS命令详解 (转)
  15. Android + HTML5 混合开发
  16. springCloud系列 Config配置中心
  17. Java的内存泄露
  18. bsdiff差分算法
  19. Android平台如何获得屏幕尺寸?
  20. 如何设计一款优秀的短视频 SDK

热门文章

  1. 第二章 Js语法
  2. windbg调试虚拟机win7系统
  3. C++快速开发样本工程的建立--简介
  4. Keil C51编译报错error C141: syntax error
  5. 大数据入门第二天——基础部分之zookeeper(下)
  6. c++ 绘制方框
  7. 02-web框架
  8. CF1111E Tree 树链剖分,DP
  9. C语言编译过程以及gcc编译参数
  10. [FJOI2015]火星商店问题