这次与王悦生合作编写了小学生四则运算过程,包括整数四则运算部分与真分数四则运算部分,原本是用vc来编程实现的,但通过讨论最后决定了用C++来实现,而最基本的一点就是美观大方,编写也变得轻松了一点,最后将这个软件成功实现了,不过有一点没有做的是关于题目数量的规定,做成了无限出题.
使用时需要注意的是整数答案直接输入就好,而分数答案要输入成a/b的形式,比如:1/2=1/2, 6/3=2,6/10=3/5
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 int ti_shu, result, f1, f2; private void chu_ti() { Random suiji = new Random(); int a = suiji.Next(0, 10); int b = suiji.Next(1, 10); int c = suiji.Next(0, 10); int d = suiji.Next(1, 10); int p = 4; //int p = suiji.Next(0, 7); if (p == 0)//出加法题 { label1.Text = a.ToString() + "+" + b.ToString() + "="; result = a + b; f1 = result; f2 = 1; } if (p == 1) //出减法题 { label1.Text = a.ToString() + "-" + b.ToString() + "+" + c.ToString() + "-" + d.ToString(); result = a - b; f1 = result; f2 = 1; } ti_shu = ti_shu + 1; textBox1.Text = ""; if (p == 2) //出乘法题 { label1.Text = a.ToString() + "*" + b.ToString() + "="; result = a * b; f1 = result; f2 = 1; } if (p == 3) //出除法题 { label1.Text = a.ToString() + "/" + b.ToString() + "="; f1 = a; f2 = b; int g; g = Gcd(f1, f2); if (g>1) { f1 = f1 / g; f2 = f2 / g; } if (f2==1) { result = f1; } } if (p == 4) //出分数加法题 { if (a > b) { int t = a; a = b; b = t; } if (c > d) { int t = c; c = d; d = t; } label1.Text = a.ToString() + "/" + b.ToString() + "+" + c.ToString() + "/" + d.ToString() + "="; f1 = a * d + b * c; f2 = b * d; int g; g = Gcd(f1, f2); f1 = f1 / g; f2 = f2 / g; result = f1 / f2; if (f1 == 0) { result = 0; } if (f2 == 1) { result = f1; } } if (p == 5) //出分数减法题 { if (a > b) { int t = a; a = b; b = t; } if (c > d) { int t = c; c = d; d = t; } label1.Text = a.ToString() + "/" + b.ToString() + "-" + c.ToString() + "/" + d.ToString() + "="; f1 = a * d - b * c; f2 = b * d; int g; g=Gcd(f1, f2); f1 = f1 / g; f2 = f2 / g; result = f1 / f2; if (f1 == 0) { result = 0; } if (f2 == 1) { result = f1; } } if (p == 6) //出分数乘法题 { if (a > b) { int t = a; a = b; b = t; } if (c > d) { int t = c; c = d; d = t; } label1.Text = a.ToString() + "/" + b.ToString() + "*" + c.ToString() + "/" + d.ToString() + "="; f1 = a * c; f2 = b * d; int g; g = Gcd(f1, f2); f1 = f1 / g; f2 = f2 / g; result = f1 / f2; if (f1 == 0) { result = 0; } if (f2 == 1) { result = f1; } } if (p == 7) //出分数除法题 { if (c == 0) { c++; } if (a > b) { int t = a; a = b; b = t; } if (c > d) { int t = c; c = d; d = t; } label1.Text = a.ToString() + "/" + b.ToString() + " " + "/" + " " + c.ToString() + "/" + d.ToString() + "="; f1 = a * d; f2 = b * c; int g; g = Gcd(f1, f2); f1 = f1 / g; f2 = f2 / g; if (f1 == 0) { result = 0; } if (f2 == 1) { result = f1; } //result = f1 / f2; } } private void label1_Click(object sender, EventArgs e) { } int Gcd(int a, int b)//求最大公约数,以便对结果进行约分 { while (a != 0 && b != 0) { if (a > b) a = a % b; else if (a < b) b = b % a; } return (a > b ? a : b); } private void Form1_Load(object sender, EventArgs e) { ti_shu = 0; chu_ti(); } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { string Item; /*if (pp <= 3 || f1 == 0 || f2 == 1) { if (e.KeyChar == 13)//表示按下的回车键 { if (Convert.ToInt16(textBox1.Text) == result) { Item = label1.Text + textBox1.Text + "√"; } else Item = label1.Text + textBox1.Text + "×"; this.listBox1.Items.Add(Item); this.textBox1.Text = ""; chu_ti(); } } else {*/ if (e.KeyChar == 13)//表示按下的回车键 { if (f2==1||f1==0) { if (Convert.ToInt16(textBox1.Text) == result) { Item = label1.Text + textBox1.Text + "√"; this.listBox1.Items.Add(Item); } else { Item = label1.Text + textBox1.Text + "×"; this.listBox1.Items.Add(Item); this.listBox2.Items.Add(Item); } } else { if (Convert.ToString(textBox1.Text) == Convert.ToString(f1) + "/" + Convert.ToString(f2)) { Item = label1.Text + textBox1.Text + "√"; this.listBox1.Items.Add(Item); } else { Item = label1.Text + textBox1.Text + "×"; this.listBox1.Items.Add(Item); this.listBox2.Items.Add(Item); } } this.textBox1.Text = ""; chu_ti(); } } private void button1_Click(object sender, EventArgs e) { Application.Exit(); } } }
软件使用说明书
小学四则运算程序使用说明书
1.1编写目的
实现小学生四则运算在线答题,能够使用户锻炼自己的数学能力
1.2项目背景
石家庄铁道大学16级测绘系 罗玉铭,王悦生编
- 软件概述
2.1目标:实现小学生在线答题
2.2功能:小学生在线答题且提出错题
2.3 性能
.a时间特性:反应速度快
.b灵活性:较为灵活
.c外观:简单清晰
3. 运行环境
3.1硬件
要求低
VS
4. 使用说明
4.1安装和初始化
需安装VS
4.2输入
请输入正确答案(分数答案格式为a/b)
4.2.1数据背景
略
4.2.2数据格式
无
4.2.3输入举例
答案为整数输入x,答案为分数输入a/b,1/2=1/2, 6/3=2,6/10=3/5
4.3输出
√或×
4.4出错和恢复
如出错请重新运行程序
5. 运行说明
5.1运行步骤
无运行步骤,请直接输入答案
5.1.1运行控制
无
5.1.2操作信息
a. 运行目的;小学生在线答题
b. 操作要求;输入数据即可
c. 启动方法;无需操做,打开程序后自动运行
d. 预计运行时间;极短
e. 其他事项。
5.2.3输入/输出文件
无输入输出文件
5.2.4启动或恢复过程
6. 非常规过程
无
7. 操作命令一览表
无
8. 程序文件(或命令文件)和数据文件一览表
计算,输入,退出,储存
这次作业和王悦生的合作让我换了一个想法去编程,确实与人合作和自己编程的一些东西是不一样的,要好好学习,不断提升自己的水平才行