计应191(西)杜旭晖

 

 

小学一年级100以内的加减法

1、计划:用c#编写一个小学生100以内加减法口算题卡。

2、开发:

需求分析:作为一名一年级小学生的舅舅,我希望开发出一个口算题卡软件,让我的外甥能在上面练习口算题,能够自动生成100以内的正整数加减法运算,以便减轻我姐姐的工作负担。

难点:自动出10道题,并且可以显示答案。


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 shuxueti
{
public partial class Form1 : Form
{
int[] jieguo = new int[10];//存储结果
public DateTime Frist { get; set; }//计算时间
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.listBox1.DataSource = Data();
this.lbtime.Text = "所用时间";
}
private List<String> Data()
{
List<string> st = new List<string>();
string s="";
Random ran = new Random();
// int[] jieguo = new int[10];
//int a = ran.Next(100);
//int b = ran.Next(100);
//int c = ran.Next(1, 3);
//TextBox t = new TextBox();
//t.Name = "自定义";
//this.Controls.Add(t);
//t.Location = new Point(11, 11);
for (int i = 0; i < 10; i++)
{
int a = ran.Next(100);
int b = ran.Next(100);
int c = ran.Next(1, 3);
switch (c)
{
case 1:
if ((a + b) > 100)
{
if (a > b)
{
s = a + "-" + b + "=";jieguo[i] = a - b;
}
else
{
s = b + "-" + a + "="; jieguo[i] = b-a;
}
}
else
{
s = a + "+" + b + "="; jieguo[i] = a + b;
}
break;
case 2:
if (a < b)
{
s= b + "-" + a + "="; jieguo[i] = b-a;
}
else
{
s = a + "-" + b + "="; jieguo[i] = a - b;
}
break;
}
st.Add (s);
}
return st;
}

private void btsumbit_Click(object sender, EventArgs e)
{
double reald = 0;
if (txb1.Text == jieguo[0].ToString())
{
this.lb1.Text = "√";
reald++;
}
else
{
this.lb1.Text = "×";
}
if (txb2.Text == jieguo[1].ToString())
{
this.lb2.Text = "√";
reald++;
}
else
{
this.lb2.Text = "×";
}
if (txb3.Text == jieguo[2].ToString())
{
this.lb3.Text = "√";
reald++;
}
else
{
this.lb3.Text = "×";
}
if (txb4.Text == jieguo[3].ToString())
{
this.lb4.Text = "√";
reald++;
}
else
{
this.lb4.Text = "×";
}
if (txb5.Text == jieguo[4].ToString())
{
this.lb5.Text = "√";
reald++;
}
else
{
this.lb5.Text = "×";
}
if (txb6.Text == jieguo[5].ToString())
{
this.lb6.Text = "√";
reald++;
}
else
{
this.lb6.Text = "×";
}
if (txb7.Text == jieguo[6].ToString())
{
this.lb7.Text = "√";
reald++;
}
else
{
this.lb7.Text = "×";
}
if (txb8.Text == jieguo[7].ToString())
{
this.lb8.Text = "√";
reald++;
}
else
{
this.lb8.Text = "×";
}
if (txb9.Text == jieguo[8].ToString())
{
this.lb9.Text = "√";
reald++;
}
else
{
this.lb9.Text = "×";
}
if (txb10.Text == jieguo[9].ToString())
{
this.lb10.Text = "√";
reald++;
}
else
{
this.lb10.Text = "×";
}
//double z = reald / 10;
this.lbcr.Text = "正确率"+(reald / 10).ToString("P");

DateTime last =DateTime.Now;
TimeSpan cha = last - Frist;
this.lbtime.Text ="所用时间" +cha.Seconds.ToString()+"秒";
}

private void txb1_KeyPress(object sender, KeyPressEventArgs e)
{
//IsNumber的作用是判断输入案件是否为数字
//(char)8是退格键值,可以允许用户敲退格键对输入的数字进行修改
//针对其他按键输入则提示错误不允许输入到文本框
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;//经判断为数字,可以输入
}
}

private void txb2_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb3_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb4_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb5_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb6_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb7_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb8_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb9_KeyPress(object sender, KeyPressEventArgs e)
{

if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void txb10_KeyPress(object sender, KeyPressEventArgs e)
{

if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}

private void button1_Click(object sender, EventArgs e)
{
this.listBox1.DataSource = Data();
this.txb1.Text = "";
this.txb2.Text = "";
this.txb3.Text = "";
this.txb4.Text = "";
this.txb5.Text = "";
this.txb6.Text = "";
this.txb7.Text = "";
this.txb8.Text = "";
this.txb9.Text = "";
this.txb10.Text = "";
this.lb1.Text = "";
this.lb2.Text = "";
this.lb3.Text = "";
this.lb4.Text = "";
this.lb5.Text = "";
this.lb6.Text = "";
this.lb7.Text = "";
this.lb8.Text = "";
this.lb9.Text = "";
this.lb10.Text = "";
this.lbcr.Text = "正确率";
this.lbtime.Text = "所用时间";

}

private void txb1_TextChanged(object sender, EventArgs e)
{
Frist = DateTime.Now;
}
}
}

posted @ 2021-05-31 22:41  计应191西一组  阅读(70)  评论(0)    收藏  举报