码迷,mamicode.com
首页 > Windows程序 > 详细

自动出题判分——c#学习实践

时间:2017-05-19 21:12:41      阅读:1726      评论:0      收藏:0      [点我收藏+]

标签:task   switch   ==   eric   namespace   http   public   rand   images   

1、程序功能自动出题—(程序随意给出10以内加减乘除)并且判断结果正确与否,正确打对勾,错误打错号。

2、设计界面:

技术分享

3、代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace text01
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int a, b;
        string op;
        int result;

        Random rnd = new Random();

        private void btnNew_Click(object sender, EventArgs e)
        {   //随机产生A\B
            a = rnd.Next(9) + 1;
            b = rnd.Next(9) + 1;
            int c = rnd.Next(4);
            switch (c)//运算符由随机给出的数字对应给出
            {
                case 0: op = "+"; result = a + b; break;
                case 1: op = "-"; result = a - b; break;
                case 2: op = "*"; result = a * b; break;
                case 3: op = "/"; result = a / b; break;
            }
            lblA.Text = a.ToString();
            lblB.Text = b.ToString();
            lblOp.Text = op;
            txtAnswer.Text = "";

        }

        private void btnJudge_Click(object sender, EventArgs e)
        {
            string str = txtAnswer.Text;
            double d = double.Parse(str);
            string disp = "" + a + op + b + "=" + str + " ";
            if (d == result) // if( Math.Abs(d-result)< 1e-3 )
                disp += "";
            else
                disp += "X";

            lstDisp.Items.Add(disp);
        }


    }
}

4、运行成果图:

技术分享

 

自动出题判分——c#学习实践

标签:task   switch   ==   eric   namespace   http   public   rand   images   

原文地址:http://www.cnblogs.com/lwbjyp/p/6880108.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!