web窗体之四则运算

1,计算方法:

 

namespace ASP.NET
{
    public class JiSuan
    {
        public int S;
        public int Result
        {
            get { return S; }


        }

       
        public  int  Max(int x, int y, char a)
        {
            if (a == '+')
            {
                return S = x + y;
            }
            else if (a == '-')
            {
                if (x > y)
                {
                    return S = x - y;
                }
                
            }
            else if (a == '/')
            {
                if (y == 0 || y < 0)
                {
                    return S = x / y;
                }
               
            }
            else if (a == '*')
            {
                return S = x * y;

            }
            return S;


        }
    }

2,方法调用:

 

public partial class 新文件夹1_FZ : System.Web.UI.Page
{
    public static int Count = 0;
    public static int right = 0;
    //JiSuan JS = new JiSuan();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        int a = int.Parse(TextBox1.Text.Trim());
        int b = int.Parse(TextBox3.Text.Trim());
        //int H = int.Parse(TextBox4.Text.Trim());
        Char c = Convert.ToChar(TextBox2.Text.Trim());
        JiSuan JS = new JiSuan();
        JS.Max(a,b,c);
        if (JS.Result == int.Parse(TextBox4.Text.Trim()))
        {
            Count++;
            right++;
           Label2.Text=("回答正确!");
        }

        else 
        {
            Count++;
            Label2.Text = ("回答错误!");
        }
       

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox5.Text = Count.ToString();
        TextBox6.Text = right.ToString();
        TextBox7.Text = ((right / (double)Count) * 100).ToString() + "%";
    }
}

3,源代码:

<body>
    <form id="form1" runat="server">
    <div align="center">    
        <asp:Label ID="Label2" runat="server" Font-Size="X-Large" Text="判断正误!"></asp:Label>
        <br />        <br />        <br />
        <asp:TextBox ID="TextBox1" runat="server" BackColor="#FF99FF" 
            Font-Size="XX-Large" Height="43px" Width="174px"></asp:TextBox>
  
        <asp:TextBox ID="TextBox2" runat="server" BackColor="#FF99FF" 
            Font-Size="XX-Large" Height="40px" Width="43px"></asp:TextBox>
  
        <asp:TextBox ID="TextBox3" runat="server" BackColor="#FF66FF" 
            Font-Size="XX-Large" Height="41px" Width="160px"></asp:TextBox>
  
        <asp:Label ID="Label1" runat="server" BackColor="#FF99FF" Font-Size="XX-Large" 
            Text="="></asp:Label>
  
        <asp:TextBox ID="TextBox4" runat="server" BackColor="#FF66FF" 
            Font-Size="XX-Large" Height="41px" Width="153px"></asp:TextBox>    
    </div>
    <table>
      <tr align="center">
        <td class="style3" align="right">
    <asp:Button ID="Button1" runat="server" BackColor="#FF99FF" Font-Size="Large" 
        Height="30px" οnclick="Button1_Click" Text="确定" Width="75px" />
        </td>
        <td class="style4" align="center">
  
        <asp:Button ID="Button2" runat="server" BackColor="#FF99FF" BorderColor="White" 
        Font-Size="Large" Height="28px" οnclick="Button2_Click" Text="完成" 
        Width="65px" />
        </td>
        
       </tr>
     </table>
 <table class="style1">
        <tr>
            <td class="style2">
                    
                总数:
            </td>
            <td class="style2">
                    
                <asp:TextBox ID="TextBox5" runat="server" BackColor="#FFCC99"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                正确</td>
            <td>
                <asp:TextBox ID="TextBox6" runat="server" BackColor="#FFCC99"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                正确率:</td>
            <td>
                <asp:TextBox ID="TextBox7" runat="server" BackColor="#FFCC99"></asp:TextBox>
            </td>
        </tr>
    </table>
    </form>
</body>

 

转载于:https://www.cnblogs.com/12345-xyy/p/4998742.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值