c#寫的小學(xué)數(shù)學(xué)二年級(jí)自動(dòng)出題系統(tǒng),實(shí)現(xiàn)自動(dòng)隨機(jī)出題;四則運(yùn)算。對于剛學(xué)C#的朋友掌握光標(biāo)獲取、鎖定光標(biāo),TAB切換、回車鍵綁定、隨機(jī)數(shù)產(chǎn)生、列表框顯示運(yùn)用等有幫助!
51hei.png (6.98 KB, 下載次數(shù): 102)
下載附件
2020-12-13 17:35 上傳
源程序如下:- 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 WindowsFormsApp4
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- int a, b,aaa,bbb,bb;
-
- string op;
- string op1;
- string op2;
-
- int result;
- int result1;
- int result2;
-
-
- Random rnd = new Random();
-
- private void Form1_Load(object sender, EventArgs e)
- {
-
-
- }
-
-
- private void Button1Click(object sender, EventArgs e)
- {
-
- a = rnd.Next(10) + 1;
- b = rnd.Next(10) + 1;
- if (a<=b)
- a=a+b;
-
-
- aaa = rnd.Next(10) + 1;
- bbb = rnd.Next(10) + 1;
- if (aaa<=bbb)
- aaa=aaa+bbb;
- bb = rnd.Next(8) + 1;
- int c = rnd.Next(3);
- int cc = rnd.Next(3);
- int ccc = rnd.Next(2);
- 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;
-
- }
- switch (cc)
-
- {
-
- case 0: op1 = "+"; result1 = aaa + bbb ; break;//OP1表示當(dāng)前運(yùn)算符號(hào)和結(jié)果,運(yùn)算結(jié)果result1等于加數(shù)+加數(shù)
-
- case 1: op1 = "-"; result1 = aaa - bbb ; break;//OP1表示當(dāng)前運(yùn)算符號(hào)和結(jié)果,運(yùn)算結(jié)果result1等于被減數(shù)-減數(shù)
-
- case 2: op1 = "×"; result1 = aaa * bbb ; break;//OP1表示當(dāng)前運(yùn)算符號(hào)和結(jié)果,運(yùn)算結(jié)果result1等于乘數(shù)*乘數(shù)
-
- case 3: op1 = "÷"; result1 = aaa / bbb ; break;//OP1表示當(dāng)前運(yùn)算符號(hào)和結(jié)果,運(yùn)算結(jié)果result1等于除數(shù)/除數(shù)
-
- }
- switch (ccc)
-
- {
-
- case 0: op2 = "+"; result2 = result1 + bb; break;
-
-
-
- case 1: op2 = "×"; result2 = result1 * bb; break;
-
-
-
- }
-
- textBox2.Text = a.ToString();//算式1中的從左邊到右第一個(gè)數(shù)
-
- textBox3.Text = b.ToString();//算式1中的從左邊到右第二個(gè)數(shù)
-
- textBox4.Text = aaa.ToString();//算式2中的從左邊到右第一個(gè)數(shù)
-
- textBox5.Text = bbb.ToString();//算式2中的從左邊到右第二個(gè)數(shù)
- textBox6.Text = bb.ToString();//算式2中的從左邊到右第三個(gè)數(shù)
-
- label2.Text = op;//算式1中的運(yùn)算符號(hào),隨機(jī)產(chǎn)生對應(yīng)的符號(hào)
- label1.Text = op1;//算式2中的運(yùn)算符號(hào),隨機(jī)產(chǎn)生對應(yīng)的符號(hào)
- label6.Text = op2;//算式2中的運(yùn)算符號(hào),隨機(jī)產(chǎn)生對應(yīng)的符號(hào)
- textBox1.Text="";//按鍵后清空文本框的內(nèi)容!
- textBox7.Text="";//按鍵后清空文本框的內(nèi)容!
- textBox1.Focus();
-
- }
-
- private void Button2Click(object sender, EventArgs e)
- {
-
- //if (textBox1.Text =="")
- // MessageBox.Show("請輸入數(shù)字,不能為空");
-
- //else
- // MessageBox.Show("輸入的數(shù)字正確");
-
-
- if (textBox1.Text == "")//判斷是否輸入的用戶名,如果沒有輸入,顯示下面的提示,否則跳到else
- {
- MessageBox.Show("答案不能為空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (textBox7.Text == "")//判斷是否輸入的用戶名,如果沒有輸入,顯示下面的提示,否則跳到else
- {
- MessageBox.Show("答案不能為空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- string str = textBox1.Text;//文本框輸入為等式的結(jié)果,結(jié)果答案輸入處。
- string str1 = textBox7.Text;
-
- double d = double.Parse(str);
- double dd = double.Parse(str1);
- string disp = " " + a + op + b + "=" + str + " ";
- string disp1 = " " + aaa + op1 + bbb + op2 + bb + "=" + str1 + " ";
-
-
-
- if (d == result) // if( Math.Abs(d-result)< 1e-3 )
-
-
- disp += "√ 答案正確 劉穎穎你真棒";
-
- else
-
- disp += "╳ 答案錯(cuò)誤 加油重新列算式運(yùn)算";
- if (dd == result2) // if( Math.Abs(d-result)< 1e-3 )
-
- disp1 += "√ 答案正確 劉穎穎你真棒";
-
- else
- disp1 += "╳ 答案錯(cuò)誤 加油重新列算式運(yùn)算";
-
- lstDisp.Items.Add(disp);
- lstDisp.Items.Add(disp1);
- textBox1.Text="";//清空上一次輸入的結(jié)果!
- textBox7.Text="";//清空上一次輸入的結(jié)果!
-
- }
-
- }
- void TextBox1KeyPress(object sender, KeyPressEventArgs e)
- {
- if(!(char.IsNumber(e.KeyChar))&& e.KeyChar !=(char)8)
- {
- e.Handled = true;//判定為數(shù)字,可以輸入
- }
- }
- void LstDispSelectedIndexChanged(object sender, EventArgs e)
- {
- if (lstDisp.Text.Length >10)
- lstDisp.Text = "";
- }
- void TextBox7KeyPress(object sender, KeyPressEventArgs e)
- {
- if(!(char.IsNumber(e.KeyChar))&& e.KeyChar !=(char)8)
- {
- e.Handled = true;//判定為數(shù)字,可以輸入
- }
- }
- void Button3Click(object sender, EventArgs e)
- {
- lstDisp.Items.Clear();
- }
-
- }
- }
復(fù)制代碼
全部資料51hei下載地址:
運(yùn)算1.4版本.7z
(4.44 MB, 下載次數(shù): 20)
2020-12-13 17:36 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|