结对实验---基于GUI的四则运算
详细代码:https://git.coding.net/wangluo24/NO.2.git
结对伙伴:吕志哲(201421123021)
&本人.许明涛 201421123024
一、题目要求
将第一次作业中的四则运算程序做成GUi界面的形式展示出来,要求在下面的功能需求中实现两个:
- 记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。
- 有计时功能,能显示用户开始答题后的消耗时间。
- 界面支持中文简体/中文繁体/英语,用户可以选择一种
二、实验平台
vs2010
三、设计实现
四则运算程序是C编写的,要使用vs做成GUI,我们先把程序转化成c#来做,c#的GUI制作有些类似于java。针对题目要求,
我们小组完成了要求二和要求三
导向图:
四、部分代码展示
生成题目代码:
Random ran = new Random(); p = ran.Next(10) + 1; q = ran.Next(10) + 1; i = ran.Next(10) + 1; j = ran.Next(10) + 1; x = ran.Next(10) + 1; y = ran.Next(10) + 1; int k = ran.Next(8); while (i > j && x > y) { i = ran.Next(10) + 1; j = ran.Next(10) + 1; x = ran.Next(10) + 1; y = ran.Next(10) + 1; ; } switch (k) { case 0: this.label2.Text = p + " +" + q; z = p + q; b = z.ToString(); break; case 1: this.label2.Text = p + " -" + q; z = p - q; b = z.ToString(); break; case 2: this.label2.Text = p + "x" + q; z = p * q; b = z.ToString(); break; case 3: this.label2.Text = p + "÷" + q; z = p / q; b = z.ToString(); break; ; case 4: f = i * y + j * x; g = j * y; this.label2.Text = i + "/" + j + " +" + x + "/" + y; b = f + "/" + g; break; ; case 5: f = i * y - j * x; g = j * y; this.label2.Text = i + "/" + j + " -" + x + "/" + y; b = f + "/" + g; break; case 6: this.label2.Text = i + "/" + j + " x" + x + "/" + y; f = i * x; g = j * y; b = f + "/" + g; break; case 7: this.label2.Text = i + "/" + j + "÷" + x + "/" + y; f = i * y; g = j * x; b = f + "/" + g; break;
中文/繁体/英文转化:
private void button3_Click(object sender, EventArgs e) { ... if (flag == "11") {dr = MessageBox.Show("题目回答完毕"); MessageBox.Show("总共答错:" + h + "题"+","+"耗时"+sum);} else if (flag == "22") { dr = MessageBox.Show("題目回答完畢"); MessageBox.Show("總共答錯:" + h + "," + "耗時" + sum); } else if ((flag == "33")) { dr = MessageBox.Show("The end"); MessageBox.Show("Total wrong:" + h + "," + "Time consuming" + sum); } private void button2_Click(object sender, EventArgs e) { string c = this.textBox2.Text; if (c == b) { this.label3.Text = "回答正确"; } else { this.label3.Text = "回答错误,正确答案为:" + b; h++; } string w = this.label3.Text; if ((w == "回答正确") &&(flag =="11")) this.label3.Text = "回答正确"; else if((w == "回答错误,正确答案为:" + b) && (flag=="11")) this.label3.Text = "回答错误,正确答案为:" + b; else if((w == "回答正确") && (flag=="22")) this.label3.Text = "回答正確"; else if ((w == "回答错误,正确答案为:" + b) && (flag=="22")) this.label3.Text = "回答錯誤,正確答案為:" + b; else if ((w == "回答正确") && (flag =="33")) this.label3.Text = "Right"; else if ((w == "回答错误,正确答案为:" + b) && (flag =="33")) this.label3.Text = "Wrong,right is:" + b; else this.label3.Text = "null"; } private void Form1_Load(object sender, EventArgs e) { } private void button4_Click(object sender, EventArgs e) { flag = "11"; this.label5.Text="时间"; this.label1.Text="答题数"; this.button1.Text="开始答题"; this.label4.Text="题目"; this.button2.Text="判断"; this.button3.Text = "下一题"; this.label7.Text = "语言"; } private void button5_Click(object sender, EventArgs e) { flag ="22"; this.label5.Text = "時間"; this.label1.Text = "答題數"; this.button1.Text = "開始答題"; this.label4.Text = "題目"; this.button2.Text = "判斷"; this.button3.Text = "下壹題"; this.label7.Text = "語言"; } private void button6_Click(object sender, EventArgs e) { flag = "33"; this.label5.Text = "Time"; this.label1.Text = "Answer number"; this.button1.Text = "Starting to work"; this.label4.Text = "Question"; this.button2.Text = "Judge"; this.button3.Text = "Next question"; this.label7.Text = "Language";
计时功能:
Timer time = new Timer(); Stopwatch sw= new Stopwatch(); TimeSpan ts; private void button1_Click(object sender, EventArgs e) { time.Tick += new EventHandler(timer1_Tick); time.Interval = 1; sw.Start(); time.Start(); ..} private void button3_Click(object sender, EventArgs e) { m--; if (m == 0) { sw.Stop(); time.Stop(); string sum = this.label6.Text; this.label6.Text = string.Format("{0}:{1}:{2}:{3}", 0, 0, 0, 0); ... } private void timer1_Tick(object sender, EventArgs e) { ts = sw.Elapsed; this.label6.Text = string.Format("{0}:{1}:{2}:{3}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); }
五、GUI测试
三种语言转化
以英文为例做题:
题目做完后:
显示做题时间:
六、PSP表格
PSP2.1 |
Personal Software Process Stages |
Estimated time(h) |
actual time(h) |
Planning |
计划 |
1 |
1.2 |
· Estimate |
估计这个任务需要多少时间 |
10 |
18 |
Development |
开发 |
8 |
12 |
· Analysis |
需求分析 (包括学习新技术) |
1 |
2 |
· Design Spec |
生成设计文档 |
0.5 |
0.5 |
· Design Review |
设计复审 |
0.5 |
0.6 |
· Coding Standard |
代码规范 |
0.5 |
0.3 |
· Design |
具体设计 |
1.5 |
1.5 |
· Coding |
具体编码 |
6 |
7.5 |
· Code Review |
代码复审 |
0.5 |
0.8 |
· Test |
测试(自我测试,修改代码,提交修改) |
1.5 |
1.6 |
Reporting |
报告 |
1 |
1 |
· |
测试报告 |
0.5 |
0.5 |
· |
计算工作量 |
1 |
1 |
· |
并提出过程改进计划 |
1 |
1
|
七、总结
这次的实验对我们还是有点挑战的,之前的代码用的是C,而对C怎么做GUI还不太熟悉,查看了很多网上成品的用VS做的图形界面,最后决定用C#制作
在做之前对于c#也不是很了解,所以在开始的时候有点无从下手,需要一步一步查阅,随着逐渐了解,发现c#和java有很多共通之处,GUi的制作也是根据要求
在做好的各个控件下进行编程,过程有些崎岖,但经过两个人共同的努力,还是成功制作出来了,虽然界面不大美观==!,,但是这次还是很有收获的。
汉堡包式评价,
(先来一片面包):这次我两之前编程都是用的C,所以我们就如何用C程序做gui商讨了一下,因为此前都没做过,也有想过重新做一个熟悉的java的四则运算程序
最后还是决定先尝试看看
(在把肉放上):我的队友对于java制作GUI相对来说还是比较熟悉的,他对于编程的整体的思路还是很明确的,他做事情比较执着,一个模块没搞明白,会专注于那个模块,这样有助于增加思考时间,提高思维能力,然而相对的效率就不是那么迅速了。
(再来一片面包):在我编程相应功能的时候,我有什么想不通的东西,就会问他,编程的时候总会有你怎么都觉得对但怎么都不对的时候,所谓旁观者清,有个伙伴帮你指导,效率可不是1+1=2那么简单,像这样结对编程比一个人顺利很多。