结对实验--基于GUI的四则运算

详细代码地址:https://git.coding.net/lz201421/GUIsizeyunsuan.git

成员:201421123021 吕志哲

         201421123024  许明涛

一、题目需求

       将第一次作业中的四则运算程序做成GUi界面的形式展示出来,要求在下面的功能需求中实现两个:

      1、记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。

      2、有计时功能,能显示用户开始答题后的消耗时间。

      3、界面支持中文简体/中文繁体/英语,用户可以选择一种

二、实验平台

vs2010

三、设计实现

    将C语言编写的四则运算代码通过c#做成GUI界面,主要完成题目要求的第二、第三点,具体逻辑导向如下:

四、主题代码展示

生成题目部分:

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);
}

 

五、程序结果展示:

语言:

中文简体

 

中文繁体:

英文:

以英文界面答题:

题目做完:

错题数与耗时显示:

六、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形式,是很不容易的,对于c#并未接触过只能上网查阅资料。幸好c#的GUI编程于java有很多相通之处,所以能够靠自己理解完成这次的编程。虽然还存在些问题但毕竟是通过两个人的努力几乎做出来了,还是很有收获的,对以后的编程也提供了宝贵经验。

 

汉堡包式评价,

(先来一片面包):我和队员两个对编程都不是很擅长,所以我们在完成任务的过程中也遇到了许多的难题,因为我们懂的编程语言不是很多,所以我们就用类似java的c#来做本次的GUI。

(在把肉放上):我的队友有第一次做实验的经验,所以对于c++会比较熟悉,更重要的是他实践动手的能力很强,脑子也很灵活,遇到难题很懂得变通的方法,但他编程逻辑不够严密,所以做出来的结果在顺序上会有点偏差,比如遇到过没输入得数就会比较对错,这点上还有值得磨炼的地方。

(再来一片面包):在我编程时候,我有什么不会的东西,就会先问他,有个思想灵活的伙伴指导,编程往往能事半功倍。

 

posted @ 2017-03-15 00:40  双口  阅读(189)  评论(2编辑  收藏  举报