ASP.NET上实现
2015-12-06 18:52
591 查看
ASP.NET上实现
fengzhuang.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class fengzhuang
{
private double a = 0;
private double b = 0;
public double A
{
get { return a; }
set { a = value; }
}
public double B
{
get { return b; }
set { b = value; }
}
public virtual double GetResult()
{
double result = 0;
return result;
}
}
class Add :fengzhuang
{
public override double GetResult()
{
double result = 0;
result = A + B;
return result;
}
}
class Sub : fengzhuang
{
public override double GetResult()
{
double result = 0;
result = A - B;
return result;
}
}
class Mul : fengzhuang
{
public override double GetResult()
{
double result = 0;
result = A * B;
return result;
}
}
class Div :fengzhuang
{
public override double GetResult()
{
double result = 0;
if (B == 0)
throw new Exception("除数不能为0");
result = A / B;
return result;
}
}
public class Factory
{
public static fengzhuang Cal(string operate)
{
fengzhuang oper = null;
switch (operate)
{
case "+":
oper = new Add();
break;
case "-":
oper = new Sub();
break;
case "*":
oper = new Mul();
break;
case "/":
oper = new Div();
break;
}
return oper;
}
}
具体代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Cal_Click(object sender, EventArgs e)
{
Calculator oper;
string strOperate = DropDownList1.SelectedItem.ToString();
oper = Factory.Cal(strOperate);
oper.A = Convert.ToDouble(TextBox1.Text);
oper.B = Convert.ToDouble(TextBox2.Text);
string answer = Convert.ToString(oper.GetResult());
string result = TextBox1.Text + DropDownList1.SelectedItem.ToString() + TextBox2.Text;
if (TextBox3.Text == answer)
{
Response.Write("<script>alert('回答正确!')</script>");
ListBox1.Items.Add(result + "=" + TextBox3.Text.Trim());
}
else
{
Response.Write("<script>alert('答题错误!')</script>");
ListBox1.Items.Add(result + "=" + TextBox3.Text.Trim() );
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
fengzhuang.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class fengzhuang
{
private double a = 0;
private double b = 0;
public double A
{
get { return a; }
set { a = value; }
}
public double B
{
get { return b; }
set { b = value; }
}
public virtual double GetResult()
{
double result = 0;
return result;
}
}
class Add :fengzhuang
{
public override double GetResult()
{
double result = 0;
result = A + B;
return result;
}
}
class Sub : fengzhuang
{
public override double GetResult()
{
double result = 0;
result = A - B;
return result;
}
}
class Mul : fengzhuang
{
public override double GetResult()
{
double result = 0;
result = A * B;
return result;
}
}
class Div :fengzhuang
{
public override double GetResult()
{
double result = 0;
if (B == 0)
throw new Exception("除数不能为0");
result = A / B;
return result;
}
}
public class Factory
{
public static fengzhuang Cal(string operate)
{
fengzhuang oper = null;
switch (operate)
{
case "+":
oper = new Add();
break;
case "-":
oper = new Sub();
break;
case "*":
oper = new Mul();
break;
case "/":
oper = new Div();
break;
}
return oper;
}
}
具体代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Cal_Click(object sender, EventArgs e)
{
Calculator oper;
string strOperate = DropDownList1.SelectedItem.ToString();
oper = Factory.Cal(strOperate);
oper.A = Convert.ToDouble(TextBox1.Text);
oper.B = Convert.ToDouble(TextBox2.Text);
string answer = Convert.ToString(oper.GetResult());
string result = TextBox1.Text + DropDownList1.SelectedItem.ToString() + TextBox2.Text;
if (TextBox3.Text == answer)
{
Response.Write("<script>alert('回答正确!')</script>");
ListBox1.Items.Add(result + "=" + TextBox3.Text.Trim());
}
else
{
Response.Write("<script>alert('答题错误!')</script>");
ListBox1.Items.Add(result + "=" + TextBox3.Text.Trim() );
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
相关文章推荐
- ASP.NET WebForm 的CheckBoxList控件通过js获取Value值问题
- asp.net
- ASP.NET MVC- 视图
- 老陈 ASP.NET封装
- C++调用Asprise OCR识别图片
- C#Aspose生成word
- asp+access错误
- MVC + 三层 + ASP.NET 简单登陆验证
- Go语言和ASP.NET的一般处理程序在处理WEB请求时的速度比较
- 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
- ASP.NET 最全的POST提交数据和接收数据
- CasperJS学习笔记--命令行参数
- ROS Tutorials to Start Working with Arduino and Raspberry Pi
- 自定义ASP.NET MVC Html辅助方法
- asp.net获取当前网址url的各种属性(文件名、参数、域名 等)的代码
- ASP.NET MVC – 关于Action返回结果类型的事儿(上)
- ASP.NET MVC – 关于Action返回结果类型的事儿(上)
- raspberry pi 内核(Kernel)的交叉编译
- Aspire Project
- IIS处理Asp.net请求