设计思路:

用ASP.net设计,调用策略模式。在第一个数和第二个数的文本框中输入数值,单击录题按钮,数值保存在n1,n2文档中,把要做的题都保存完后,单击开始按钮,开始做题,做完单击判断按钮,进行判断,进入下一题,同时提示回答是否正确。如果在时间内做完题就单击结束按钮,弹出对话框“答题结束” 总计,正确的个数及正确率显示出来。

页面设计代码如下:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO; public partial class one : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
public static int Count = ;//总计的个数
public static int right = ;//正确的个数
int n = ; protected void Button8_Click(object sender, EventArgs e)
{
fh.Text="+";
fh.Visible = true;
}
protected void Button9_Click(object sender, EventArgs e)
{
fh.Text = "-";
fh.Visible = true;
}
protected void Button10_Click(object sender, EventArgs e)
{
fh.Text = "*";
fh.Visible = true;
}
protected void Button11_Click(object sender, EventArgs e)
{
fh.Text = "/";
fh.Visible = true;
}
//以上四个分别是+,-,*,/的单击事件
protected void luti_Click(object sender, EventArgs e)//录题事件
{
StreamWriter n1 = File.AppendText("n1.txt");//第一个数存入第一文档
n1.WriteLine(No1.Text);
n1.Close();
StreamWriter n2 = File.AppendText("n2.txt");//第二个数存入第二个文档
n2.WriteLine(fh.Text);
n2.Close();
StreamWriter n3 = File.AppendText("n3.txt");//结果存入第三个文档
n3.WriteLine(No2.Text);
n3.Close();
No1.Text = "";//清空数一,数二,结果
No2.Text="";
No3.Text="";
Response.Write("录题成功");
}
protected void ready_Click(object sender, EventArgs e)//开始的单击事件
{ string[] n1 = new string[];
n1 = File.ReadAllLines("n1.txt");//数值一的文档
No1.Text = n1[n];
string[] n2 = new string[];
n2 = File.ReadAllLines("n2.txt");
fh.Text = n2[n];
string[] n3 = new string[];
n3 = File.ReadAllLines("n3.txt");
No2.Text = n3[n];
n++; }
protected void over_Click(object sender, EventArgs e)
{ No3.Enabled = false;
Response.Write("运算结束!");
all.Text = Count.ToString();//题目总数
rt.Text = right.ToString();//正确的个数
rt1.Text = ((right / (double)(Count)) * ).ToString() + "%";//正确率
}
protected void ifright_Click(object sender, EventArgs e)
{
Class1.mark mark = null;
double a = Convert.ToDouble(No1.Text);//第一个数赋值
double b = Convert.ToDouble(No2.Text);//第二个数赋值
string c = fh.Text;//运算符号
switch (c)
{
case "+":
mark = new Class1.mark(new Class1.add());//调用策略模式
break;
case "-":
mark = new Class1.mark(new Class1.sub());
break;
case "*":
mark = new Class1.mark(new Class1.mul());
break;
case "/":
mark = new Class1.mark(new Class1.div());
break; default:
break;
}
string result = mark.Call(a, b,c).ToString();
if (No3.Text == result.ToString())
{
Response.Write("回答正确!下一题请按开始按钮!");
right++;
Count++;
} else
{ Response.Write("回答错误!下一题请按开始按钮!");
Count++; }
//清空
No3.Style.Clear();
}
}

策略模式代码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
///Class1 的摘要说明
/// </summary>
public class Class1
{ //定义一个接口
public interface Calculator
{
double Call(double a, double b);//定义一个方法用于计算
}
private double a;
private double b;//定义变量
public class add : Calculator
{
public double Call(double a, double b)
{
double result;
result = a + b;
return result;
}
}
public class sub : Calculator
{
public double Call(double a, double b)
{
double result;
result = a - b;
return result;
}
}
public class mul : Calculator
{
public double Call(double a, double b)
{
double result;
result = a * b;
return result;
}
}
public class div : Calculator
{
public double Call(double a, double b)
{
double result;
result = a / b;
return result;
}
}
public class mark
{
private Calculator calculate; public mark(Calculator calculate)
{
this.calculate = calculate;
}
public double Call(double a, double b, string m)
{
return this.calculate.Call(a, b);
}
}
}

运行后的图片:

ASP.net之策略模式的更多相关文章

  1. ASP.NET四则运算--策略模式

    在ASP.NET中实现四则运算,同样使用了类的封装,以及策略模式.只不过是把封装的类.前台代码以及后台的代码分离开来,但同样是要达到功能的实现. Calculator.cs using System; ...

  2. 封装,策略模式,Asp换脸

    1.简单封装 1>计算类 using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  3. 计算器软件的代码实现 (策略模式+asp.net)

    一 策略模式代码的编写 using System; using System.Collections.Generic; using System.Linq; using System.Web; /// ...

  4. 策略模式,ASP.NET实现

    策略模式,ASP.NET实现 using System; using System.Collections.Generic; using System.Linq; using System.Web; ...

  5. 计算器软件实现系列(五)策略模式+asp.net

    一 策略模式代码的编写 using System; using System.Collections.Generic; using System.Linq; using System.Web; /// ...

  6. asp.net core 集成JWT(二)token的强制失效,基于策略模式细化api权限

    [前言] 上一篇我们介绍了什么是JWT,以及如何在asp.net core api项目中集成JWT权限认证.传送门:https://www.cnblogs.com/7tiny/p/11012035.h ...

  7. ASP.NET MVC 学习笔记-2.Razor语法 ASP.NET MVC 学习笔记-1.ASP.NET MVC 基础 反射的具体应用 策略模式的具体应用 责任链模式的具体应用 ServiceStack.Redis订阅发布服务的调用 C#读取XML文件的基类实现

    ASP.NET MVC 学习笔记-2.Razor语法   1.         表达式 表达式必须跟在“@”符号之后, 2.         代码块 代码块必须位于“@{}”中,并且每行代码必须以“: ...

  8. asp.net—策略模式

    一.什么是策略模式 定义:定义一系列算法,把一个个算法封装成独立类并实现同一个接口,使得它们之间可以相互替换. 二.怎么使用策略模式 首先模拟一个场景:有一个用户想买车.  可以有多种方式买车: (1 ...

  9. 设计模式:策略模式(Strategy)

    定   义:它定义了算法家族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化, 不会影响到使用算法的客户. 示例:商场收银系统,实现正常收费.满300返100.打8折.......等不同收费 ...

随机推荐

  1. Redis基本信息

    1.Windows安装地址 https://github.com/MSOpenTech/redis/releases 2.命令行方式运行 执行redis-cli.exe 3.待续

  2. 病毒四度升级:安天AVL Team揭露一例跨期两年的电信诈骗进化史

    自2014年9月起,安天AVL移动安全团队持续检测到一类基于Android移动平台的间谍类病毒,病毒样本大多伪装成名为"最高人民检察院"的应用.经过反编译逆向分析以及长期的跟踪调查 ...

  3. jsp include flush true

    设置flush为true,就是说,如果你的缓冲区的内容很多了,就将数据读出,以免数据泄漏,造成错误服务器端页面缓冲,大致的意思是,在将生成的HTML代码送到客户端前,先在服务器端内存中保留,因为解释J ...

  4. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  5. 使用手机展示axure

    UC浏览器全屏,去地址栏 发布axure选项设置一下:参考http://sowm.cn/yixieshi/article/A752C3309457FBE32A99CA3A6A50B993.html 启 ...

  6. Drools 查询学习

    Drools 查询学习查询以 query 关键字开始,以 end 关键字结束,在 package 当中一个查询要有唯一的名称,查询的内容就是查询的条件部分,条件部分内容的写法与规则的 LHS 部分写法 ...

  7. TMS320F28027/26/23/22/21/20芯片解密单片机破解原理!

    TMS320F28027/26/23/22/21/20芯片解密单片机破解 TMS320F2802系列芯片解密型号: TMS320F28027F.TMS320F280270.TMS320F28027.T ...

  8. DNS枚举工具DNSenum

    DNS枚举工具DNSenum   DNSenum是一款非常强大的域名信息收集工具.它能够通过谷歌或者字典文件猜测可能存在的域名,并对一个网段进行反向查询.它不仅可以查询网站的主机地址信息.域名服务器. ...

  9. 城管停车执法打印APP 移动云POS 现场打印告知单-执法平台+智能POS客户端系统

    市城管局城管支队工作人员使用最新配备的城管执法手持终端对便道违法停放车辆进行拍照取证. 城管执法手持终端具备拍照.现场打印.无线传输等功能,执法人员只要在该终端登录,即可随时实现对违停车辆的拍照取证. ...

  10. js转换数据库中DateTime字段类型

    在程序中,从数据库中读取到的日期时间类型数据一般是这种格式:"/Date(1355109408000+0800)/" 要经过js函数处理变为格式:'2012-12-10 11:05 ...