基于GUI的四则运算

李志强 201421123028 连永刚 201421123014 林方言 201421123023

coding 地址 https://git.coding.net/lizhiqiang0x01/GUI-sizeyunsuan.git

一、简述题目要求:


1、除了整数之外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24

2、运算符为 +, −, ×, ÷

3、并且要求能处理用户的输入,并判断错误,打分统计正确率

4、要求能处理用户输入的真分数,如 1/2, 5/12 等

5、程序基于GUI 界面

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

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

8、界面支持中文简体/中文繁体/英文,用户选择一种


二、实现步骤:


a、需求分析

写一段程序可以生成GUI界面,在GUI 界面上可以进行中文简体/中文繁体/英文切换,在做题过程中需要计时并显示用户答题时间,在用户输入答案时,需要对输入的参数进行过滤,当用户输入非法文字,例如:“#,@,我不知道”等会被检测到,并给予相应的错误提示,在用户结束答题后,需要显示用户答题后的各种参数并实现可以查看错题库功能。

b、功能设计

逻辑结构图

基本功能

计时功能,切换语言功能,兼容获取分式和整数参数功能,生成真分式题目以及最简分式功能,运算功能,校验答案功能。

扩展功能

过滤非法字符功能,题目进度功能,生成用户错题库功能

高级功能

多级运算功能

c、设计实现

为满足功能需求,下面主要写了八个函数:

public void add();      //加法运算
public void sub(); //减法运算
public void mul(); //乘法运算
public void div(); //除法运算
public void ran(); //生成题目
public void check(); //校验答案
public string StringClear(string ai) //过滤非法字符
public void thread() //计时功能

d、代码说明[source file]

  • 生成窗体功能
        private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "请输入题目数(满分100)";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(, );
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(, );
this.label3.TabIndex = ;
this.label3.Text = "v1.00";
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "开始做题";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(, );
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(, );
this.textBox2.TabIndex = ;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(, );
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(, );
this.radioButton1.TabIndex = ;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "中文";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(, );
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(, );
this.radioButton2.TabIndex = ;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "English";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton3
//
this.radioButton3.AutoSize = true;
this.radioButton3.Location = new System.Drawing.Point(, );
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(, );
this.radioButton3.TabIndex = ;
this.radioButton3.Text = "中文繁體";
this.radioButton3.UseVisualStyleBackColor = true;
this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.radioButton3);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "中文";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout(); }
  • 计时功能
        public void thread()   //创建线程实现计时功能
{
int sec = ;
int min = ;
int hour = ; while (true)
{
sec++;
if (sec >=)
{
min++;
sec =;
if (min >=)
{
hour++;
min =;
}
}
s.label10.Text = hour + ":" + min + ":" + sec;
Thread.Sleep();
if (s.next == ) {
break;
}
} } ThreadStart th = new ThreadStart(thread);
Console.WriteLine("In Main: Creating the Child thread");
Thread the = new Thread(th);
the.Start();
  • 切换语言功能
        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 string StringClear(string ai)
{
bool temp = bolnum(ai);
if (temp == true)
{
return ai;
}
else
{
cro = ;
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 = ; i < temp.Length; i++)
{
byte tempByte = Convert.ToByte(temp[i]);
if ((tempByte > ) && (tempByte < ))
return true;
}
return false;
}
  • 生成用户错题库功能
      FileStream f = new FileStream("cuoti.txt", FileMode.Append, FileAccess.Write);
StreamWriter fi = new StreamWriter(f);
fs = "你的答案:" + this.label2.Text + this.label4.Text + this.label5.Text + this.label9.Text + ai + " 正确答案:" + au + " " + "\r\n";
fi.Write(fs);
fi.Flush();
fi.Close();
f.Close();
  • 多级运算功能
        public void select()
{
int l1, l2;
Random ra = new Random();
int x = ra.Next(, );
switch (x) //产生一级运算
{
case : add(); break;
case : sub(); break;
case : mul(); break;
case : div(); break;
}
int y = ra.Next(, );
switch (y) //产生二级运算
{
case :
if (q6 == ) 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 :
if (q6 == ) 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 :
if (q6 == ) 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 :
if (q6 == ) 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 :
this.label12.Text = "";
this.label13.Text = "";
this.label14.Text = "";
this.label15.Text = "";
break;
}
}
  • 校验答案功能
        public void check()
{
int w = ;
for (int i = ; i < ; i++)
{
if (r1 % i == && r2 % i == )
{
w = i;
}
}
r1 = r1 / w; r2 = r2 / w;
ai = StringClear(this.textBox1.Text);
if (cro != )
{
if (r2 == )
au = this.r1.ToString();
if (r2 != )
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.label2.Text + this.label4.Text + this.label5.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);
}
}
}
}

e、测试运行

1.首页(中文)及过滤错误字符:

2.检查答案,得出成绩报告单:

3.查看错题及其他语言的部分截图:

4、多级运算高级功能

GIF过程浏览


三、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


四、总结


      先来一片面包:队友之前作业都是用c++写的,都对c#比较熟悉,代码以我的为基础进行GUI转换。

      再把肉放上:首先我们设计了一套流程图,根据流程图具体分析问题,发现问题,解决问题,问题的解决方法都在博客上做了总结,我们共同编写生成题目功能,实现动态计时功能,错题库功能,语言切换功能,字符过滤功能,对话框的弹出功能,在代码复审期间我们做了加减乘除运算优化升级和代码的重构,代码格式的规范,碰到难点,便和队友lianyg(连永刚)Dialect(林方言)探讨,共同解决,连永刚同学缺点是做事慢了一点,优点持之以恒,最终找到解决方法,林方言同学缺点是对代码语法不是太熟悉,不过他确实挺好问,理解能力好。

      然后再来一片面包:经过了两天的共同奋斗,从刚开始对GUI的一无所知,到将四个GUI窗体灵活调用,最终能实现所有功能,并让界面最大程度简洁化,提高界面整洁度。

由于要用C#做成GUI界面,并且内容新加了其他功能,下面总结一下这次我们所遇到难点

问题一:如何产生GUI界面

解决该问提主要是借助于VS2013平台可自动生成窗体控件,然后阅读自动生成的源码,从中学习并加以利用。

问题二:计时功能

由于要计时功能,使时间在窗体上动态变化,这就意味这要使用线程,从而可以保证主线程可以继续监听消息。

问题三:过滤功能

在用户输入答案,如果输入非法字符就会被过滤并得到提示,在这里主要是将用户输入的值转化成 char ,然后将其与 ASCII 值进行对比,从而实现此功能。

   We are a team and we work as a team!

   

基于GUI的四则运算的更多相关文章

  1. 结队编程--基于GUI的四则运算

    coding地址 https://git.coding.net/lizhiqiang0x01/GUI-sizeyunsuan.git 李志强 201421123028 连永刚 201421123014 ...

  2. 结对作业--基于GUI的四则运算生成器

    组员:201421123015 陈麟凤 201421123019 张志杰 201421123020 黄海鸿 coding 地址 :https://coding.net/u/zhang1995/p/wo ...

  3. 结队编程-基于gui的四则运算生成器

    成员:卢少锐 201421123027.刘存201421033023 coding.net地址 1.需求分析:除了实现四则运算的功能外,还添加了计时器功能和语言选择功能 2.程序设计:这次作业是基于上 ...

  4. 结对作业(1)----基于GUI的四则运算

    小伙伴:201421123031 余洋 201421123044  潘志坚  题目要求: 我们在个人作业1中,用各种语言实现了一个命令行的四则运算小程序.进一步,本次要求把这个程序做成GUI(可以是W ...

  5. 结对作业-基于GUI的四则运算

    一.需求分析 1.题目要求: 我们在个人作业1中,用各种语言实现了一个命令行的四则运算小程序.进一步,本次要求把这个程序做成GUI(可以是Windows PC 上的,也可以是Mac.Linux,web ...

  6. 结对作业:基于GUI实现四则运算

    1)Coding.Net项目地址:https://git.coding.net/day_light/GUIszysLL.git 2)在开始实现程序之前,在下述PSP表格记录下你估计将在程序的各个模块的 ...

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

    详细代码:https://git.coding.net/wangluo24/NO.2.git 结对伙伴:吕志哲(201421123021) &本人.许明涛 201421123024 一.题目要 ...

  8. 结对编程1 (四则运算基于GUI)

    https://git.coding.net/Luo_yujie/sizeyunsuan.app.git 201421123034 201421123032 1. 需求分析 这次作业新引用了语言选择, ...

  9. 结对作业1----基于GUI的四则运算生成器

    组员:201421123015 陈麟凤 201421123019 张志杰 201421123020 黄海鸿 coding 地址:代码点这里 需求分析: 1.除了整数的四则运算还要支持分数的四则运算: ...

随机推荐

  1. 填涂颜色 洛谷 p1162

    题目描述 由数字0 组成的方阵中,有一任意形状闭合圈,闭合圈由数字1构成,围圈时只走上下左右4个方向.现要求把闭合圈内的所有空间都填写成2.例如:6X6的方阵(n=6),涂色前和涂色后的方阵如下: 0 ...

  2. 【机器学习笔记之五】用ARIMA模型做需求预测用ARIMA模型做需求预测

    本文结构: 时间序列分析? 什么是ARIMA? ARIMA数学模型? input,output 是什么? 怎么用?-代码实例 常见问题? 时间序列分析? 时间序列,就是按时间顺序排列的,随时间变化的数 ...

  3. ES6 浅谈let与const 块级作用域之封闭空间(闭包)

    ES6新增了 let const 命令,用来声明变量.它的用法类似于 var  ,但是所声明的变量,只在 let const 命令所在的代码块内有效.  var const 不允许重复声明 用处: 可 ...

  4. 关于JS中利用for循环解决实际问题的逻辑操作

    第一部分 <script>        //        <!--折纸:折多少次和珠穆朗玛峰一样高//1.一张纸的厚度是0.0001米,将纸对折,对折多少次厚度超过珠峰高度884 ...

  5. 设计模式(4)建造者模式/生成器模式(Builder)

    设计模式(0)简单工厂模式 设计模式(1)单例模式(Singleton) 设计模式(2)工厂方法模式(Factory Method) 设计模式(3)抽象工厂模式(Abstract Factory) 源 ...

  6. 解决若要安装 Microsoft Office 2010,需要MSXML 版本 6.10.1129的问题

    单击 开始单击 运行键入 注册表编辑器然后单击 确定. 找到HKEY_CLASSES_ROOT\TypeLib\{F5078F18-C551-11D3-89B9-0000F81FE221}\6.0\0 ...

  7. Android笔记: 实现手机震动效果

    1.震动是系统的服务,首先需添加震动权限 <uses-permission android:name="android.permission.VIBRATE" /> 2 ...

  8. H5输入框实时记录文字个数

    需求: 移动端用户反馈功能,有的用户反馈功能是有字数限制的,比如限制为200字 解决方法: 在项目中我们使用的Vue框架,所以可以直接进行绑定,代码如下 <section class=" ...

  9. java实现邮箱找密码

    SMTP,POP3,IMAP POP3 POP3是Post Office Protocol 3的简称,即邮局协议的第3个版本,它规定怎样将个人计算机连接到Internet的邮件服务器和下载电子邮件的电 ...

  10. 设置input框文字垂直居中和宽度

    input { solid #999;height:22px; background:#ffffff; line-height:22px; margin:0px; padding:0px;/*表单输入 ...