首页 > 代码库 > 自动出题判分——c#学习实践

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

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#学习实践