一 需求分析
这是一个解决十以内的四则运算并能有效判断出计算的总数,正确数,错误数,正确率的程序。需要输入所弹出数据的计算结果,输出你所做题目的总数,正确数,错误数,正确率。幼儿园学前班是这个软件的最主要消费人群。中国大概有3—4亿户家庭平均有1—2个这样的适龄儿童,如果软件做的做够好的话,也是一个很大的市场需求的。
二实现代码
我用的是windows窗体应用程序实现的。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 四则运算
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public static int count = 0; //定义题目总数,正确数,四则运算的变量
public static int right = 0;
public static int sum ;
private void RandomNum() //定义随机产生随机数的方法
{
Random ran = new Random();
int n1, n2;
n1 = ran.Next(1, 11);
n2 = ran.Next(1, 11);
textBox1.Text = n1.ToString();
textBox2.Text = n2.ToString();
textBox3.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
label2.Text = "加法";
label3.Text = "+";
RandomNum();
}
private void button4_Click(object sender, EventArgs e)
{
label2.Text = "减法";
label3.Text = "—";
RandomNum();
}
private void button5_Click(object sender, EventArgs e)
{
label2.Text = "乘法";
label3.Text = "×";
RandomNum();
}
private void button6_Click(object sender, EventArgs e)
{
label2.Text = "除法";
label3.Text = "÷";
RandomNum();
}
private void button1_Click(object sender, EventArgs e)
{
string m = label3.Text;
switch (m)
{
case "+":
sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
break;
case "—":
sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
break;
case "×":
sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
break;
case "÷":
sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
break;
default:
break;
}
if (textBox3.Text == sum.ToString())
{
right++;
count++;
RandomNum();
}
else
{
count++;
RandomNum();
}
}
private void button2_Click(object sender, EventArgs e)
{
count++;
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
this.Close();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 四则运算
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = Form1.count.ToString();
textBox2.Text = Form1.right.ToString();
textBox4.Text = ((Form1.right / (double)(Form1.count)) * 100).ToString() + "%";
textBox3.Text = ((Form1.count - (double)(Form1.right))).ToString();
}
}
三 总结
做这个程序让我纠结了好半天,里面有些问题程序依然能运行。可算做出来了终于可以舒一口气了,结合我们课本上的再加上自己的思考,对自己水平的提高作用很大。不用在做课本上的项目,有一种创新的快乐。感谢老师为我们创造的这个平台。