coding地址 https://git.coding.net/lizhiqiang0x01/GUI-sizeyunsuan.git
*强 201421123028 连永刚 201421123014
一、题目要求:
1、除了整数之外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24
2、运算符为 +, −, ×, ÷
3、并且要求能处理用户的输入,并判断错误,打分统计正确率
4、要求能处理用户输入的真分数,如 1/2, 5/12 等
5、程序基于GUI 界面
6、记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算
7、有计时功能,能显示用户开始答题后的消耗时间
8、界面支持中文简体/中文繁体/英文,用户选择一种
二、实现步骤:
编写一个程序可在GUI 界面上可以进行中文简体/中文繁体/英文切换,对加减乘除运算优化升级和代码的重构,实现多级运算,在答题过程中需要计时并显示用户答题时间,在用户输入答案时,需要对输入的参数进行过滤,答题结束时用户可显示答题后的各种参数并实现可以查看错题库功能。
三、部分代码展示:
语言切换
private void radioButton2_CheckedChanged(object sender, EventArgs e) //切换成英文
{
this.label1.Text = "Please enter the subject number";
this.button1.Text = "start";
s.label8.Text = "Time";
s.label1.Text = "Schedule";
s.button1.Text = "NEXT";
this.Text = "English";
s.Text = "English";
} private void radioButton1_CheckedChanged(object sender, EventArgs e) //切换成中文简体
{
this.label1.Text = "请输入题目数(满分100)";
this.button1.Text = "开始做题";
s.label8.Text = "时间";
s.label1.Text = "题目进度";
s.button1.Text = "下一题";
this.Text = "中文";
s.Text = "中文";
} private void radioButton3_CheckedChanged(object sender, EventArgs e) //切换成中文繁体
{
this.label1.Text = "請輸入題目數(滿分100)";
this.button1.Text = "開始做題";
s.label8.Text = "時間";
s.label1.Text = "題目進度";
s.button1.Text = "下壹題";
this.Text = "中文繁體";
s.Text = "中文繁體";
}
检验答案
public void check()
{
int w = 1; for (int i = 2; i < 100; i++)
{
if (r1 % i == 0 && r2 % i == 0)
{
w = i;
}
}
r1 = r1 / w; r2 = r2 / w;
if (r2 < 0)
{
r2 = -r2;
r1 = -r1;
}
ai = StringClear(this.textBox1.Text);
if (cro != 1)
{
if (r2 == 1)
au = this.r1.ToString();
if (r2 != 1)
au = r1 + "/" + r2;
if (ai == au)
{
n1++;
}
if (ai != au)
{
FileStream f = new FileStream("cuoti.txt", FileMode.Append, FileAccess.Write);
StreamWriter fi = new StreamWriter(f);
fs = "你的答案:" + this.label12.Text + this.label13.Text + this.label14.Text + this.label2.Text + this.label4.Text + this.label5.Text + this.label15.Text + this.label9.Text + ai + " 正确答案:" + au + " " + "\r\n";
fi.Write(fs);
fi.Flush();
fi.Close();
f.Close();
if (this.Text == "中文")
{
MessageBox.Show("回答错误!正确答案:" + au);
}
else if (this.Text == "English")
{
MessageBox.Show("Wrong answer!The correct answer:" + au);
}
else
{
MessageBox.Show("回答錯誤!正確答案:" + au);
}
}
}
}
多级运算
public void select()
{
int l1, l2;
Random ra = new Random();
int x = ra.Next(0, 4);
switch (x)
{
case 0: add(); break;
case 1: sub(); break;
case 2: mul(); break;
case 3: div(); break;
}
int y = ra.Next(0, 5);
switch (y)
{
case 0:
if (q6 == 1) this.label12.Text = q5.ToString();
else this.label12.Text = q5 + "/" + q6;
this.label13.Text = "+";
this.label14.Text = "";
this.label15.Text = "";
l1 = r1;l2=r2;
r1 = l1 * q6 + l2 * q5;
r2 = l2 * q6;
break;
case 1:
if (q6 == 1) this.label12.Text = q5.ToString();
else this.label12.Text = q5 + "/" + q6;
this.label13.Text = "-";
this.label14.Text = "(";
this.label15.Text = ")";
l1 = r1;l2=r2;
r1 = l1 * q5 - l2 * q6;
r2 = l2 * q6;
break;
case 2:
if (q6 == 1) this.label12.Text = q5.ToString();
else this.label12.Text = q5 + "/" + q6;
this.label13.Text = "×";
this.label14.Text = "(";
this.label15.Text = ")";
l1 = r1;l2=r2;
r1 = l1 * q5;
r2 = l2 * q6;
break;
case 3:
if (q6 == 1) this.label12.Text = q5.ToString();
else this.label12.Text = q5 + "/" + q6;
this.label13.Text = "÷";
this.label14.Text = "(";
this.label15.Text = ")";
l1 = r1;l2=r2;
this.r1 = this.q5 * l2;
this.r2 = this.q6 * l1;
break;
case 4:
this.label12.Text = "";
this.label13.Text = "";
this.label14.Text = "";
this.label15.Text = "";
break;
}
}
过滤非法字符
public string StringClear(string ai)
{
bool temp = bolnum(ai);
if (temp == true)
{
return ai;
}
else
{
cro = 1;
if (this.Text == "中文")
{
MessageBox.Show("输入错误,请正确输入字符!例如:12,1/2");
}
else if (this.Text == "English")
{
MessageBox.Show("Input error, please correct input character! For example:12,1/2");
}
else
{
MessageBox.Show("輸入錯誤,請正確輸入字符!例如:12,1/2");
}
this.textBox1.Text = "";
return "";
}
} public bool bolnum(string temp) //若为非法字符,返回false
{
for (int i = 0; i < temp.Length; i++)
{
byte tempByte = Convert.ToByte(temp[i]);
if ((tempByte > 46) && (tempByte < 58))
return true;
}
return false;
}
功能展示
四、PSP:
PSP2.1 | Personal Software Process Stages | Estimated time(h) | actual time(h) |
Planning | 计划 | 1 | 1.5 |
· Estimate | 估计这个任务需要多少时间 | 24 | 40 |
Development | 开发 | 24 | 34 |
· Analysis | 需求分析 (包括学习新技术) | 1 | 1.2 |
· Design Spec | 生成设计文档 | 7 | 10 |
· Design Review | 设计复审 | 0.5 | 0.5 |
· Coding Standard | 代码规范 | 0.5 | 0.8 |
· Design | 具体设计 | 1.5 | 1.5 |
· Coding | 具体编码 | 20 | 30 |
· Code Review | 代码复审 | 10 | 15 |
· Test | 测试(自我测试,修改代码,提交修改) | 1 | 3 |
Reporting | 报告 | 20 | 25 |
· | 测试报告 | 1 | 1.5 |
· | 计算工作量 | 0.5 | 1 |
· | 并提出过程改进计划 | 2 | 4 |
五、总结:
通过这几天的共同努力,从此次的项目中收货颇多,学习别人的长处从而发现自己的短板,同时对于自己很不擅长的GUI从中也学习到了很多知识。
q1.期间在实现加减乘除多级运算功能时,由于没有对变量的规范化,使得在引用变量中造成混淆出现BUG
定义新的变量使问题得以解决
q2.由于在校验过程中,忽视了负号会出现在分母中这种情况,在检查函数中添加
使得问题迎刃而解
我们发现问题,找出问题,共同解决问题