分析:

          程序要求:

                     1、自动生成题目

                     2、判断答案正确与否

                     3、可以控制生成题目数量实现步骤

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
public abstract class Calculator
 {
 public abstract double Cal(double a, double b);
 }
 public class Add : Calculator //派生类Add继承抽象类Calculator
 {
 public override double Cal(double a, double b)//并重写了抽象方法Cal
 {
 double result = 0;
 result = a + b;
 return result;
 }
 }
 public class Sub : Calculator
 {
 public override double Cal(double a, double b)
 {
 double result = 0;
 result = a - b;
 return result;
 }
 }
 public class Mul : Calculator
 {
 public override double Cal(double a, double b)
 {
 double result = 0;
 result = a * b;
 return result;
 }
 }
 public class Div : Calculator
 {
 public override double Cal(double a, double b)
 {
 double result = 0;
 result = a / b;
 return result;
 }
 }
 public class Context //上下文
 {
 private Calculator calculate = null;//实例化一个基类的引用对象
 public Context(Calculator _cal)//_cal为派生类的一个对象
 {
 this.calculate = _cal; //把派生类的对象赋给基类的引用对象
 }
 public double Cal(double a, double b, String symbol)
 {
 return this.calculate.Cal(a, b);//返回计算结果
 }
 }
index.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 index : System.Web.UI.Page
 {
 protected void Page_Load(object sender, EventArgs e)
 {
 //界面加载
 }
 protected void Cal_Click(object sender, EventArgs e)
 {
string symbol = DropDownList1.SelectedItem.ToString();
 double a = Convert.ToDouble(TextBox1.Text);
 double b = Convert.ToDouble(TextBox2.Text);
 Context contex = null;
 if (DropDownList1.SelectedIndex == 1)
 {
 contex = new Context(new Add()); //加法策略
 }
 else if (DropDownList1.SelectedIndex == 2)
 {
 contex = new Context(new Sub()); //减法策略
 }
 else if (DropDownList1.SelectedIndex == 3) //若为乘号
 {
 contex = new Context(new Mul()); //乘法策略
 }
 else if (DropDownList1.SelectedIndex == 4) //若为乘号
 {
 contex = new Context(new Div()); //除法策略
 }
 string answer = contex.Cal(a, b, symbol).ToString(); //用answer来存计算出来的答案,此时已经计算出a,b两个数的运算结果。

 string result = TextBox1.Text + DropDownList1.SelectedItem.ToString() + TextBox2.Text;//把运算式子存在result里面
 if (TextBox3.Text == answer) //如果输入答案与计算出的answer相等
 {
 Response.Write("<script>alert('回答正确!')</script>"); //弹出回答正确
 ListBox1.Items.Add(result + "=" + TextBox3.Text.Trim() + "√");//并把运算式子存在listbox里
 }

 else //如果答错
 {
 Response.Write("<script>alert('答题错误!')</script>"); //弹出答题错误
 ListBox1.Items.Add(result + "=" + TextBox3.Text.Trim() + "×");//同样把运算式子放在listbox
 }
TextBox1.Text = "";//把文本框清空,进行下一次出题
 TextBox2.Text = "";
 TextBox3.Text = "";
 }
 }