• 自动出题判分——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)
            {   //随机产生AB
                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、运行成果图:

  • 相关阅读:
    Multi-Sensor, Multi- Network Positioning
    基于智能手机的3D地图导航
    2010上海世博会三维导航地图
    hdu 5452(树链刨分)
    蓝桥杯危险系数
    蓝桥杯横向打印二叉树(中序+先序遍历)
    蓝桥杯幸运数(线段树)
    hdu 5185(DP)
    2014江西理工大学C语言程序设计竞赛高级组题解
    uva 12730(期望经典)
  • 原文地址:https://www.cnblogs.com/lwbjyp/p/6880108.html
Copyright © 2020-2023  润新知