四则运算GUI

一、题目描述

我们在个人作业1中,用各种语言实现了一个命令行的四则运算小程序。进一步,本次要求把这个程序做成GUI(可以是Windows PC 上的,也可以是Mac、Linux,web,手机上的),成为一个有基本功能、一定价值的程序。实现了以下三种功能:

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

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

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

二、队伍成员

201421123110 杨海亮

201421123112 余昕宇

三、功能设计

1.基本功能,包括整数与真分数的四则运算、判断对错和正确率显示。

2.新增功能,包括计时器、语言切换和把以前的对错数量保存并在此基础上增量计算。

四、思维导图

五、代码实现

计时器


void Cnew1Dlg::OnTimer(UINT_PTR nIDEvent)

{

         // TODO: Add your message handler code here and/or call default

         static UINT mm =0;

         static UINT ss =0;

         static UINT ms =0;

         CString str2;

         switch (nIDEvent)

         {

         case 1:

                   ms++;

                   if (ms== 60) {ms=0; ss++;}

                   if (ss==60) {ss=0; mm++;}

                   str2.Format(_T("%02i:%02i:%02i"),mm,ss,ms);

                   m_tiii.SetWindowTextW(str2);

                   break;

         }

 

         CDialogEx::OnTimer(nIDEvent);

}

        SetTimer(1,1000,NULL);//放在触发按钮函数内

为了实现把以前的对错数量保存并在此基础上增量计算,我们采用了文件读写的方式,每运行一次运算都会将对错数量写入文件,计算或重启程序时再从文件中读取相应值赋给对错总量,并在界面上直观体现出来。


    写入文件

    char C1[100],C2[100];

    itoa(count2,C1,10);

    itoa(count3,C2,10);

    CFile file(_T("CFile.txt"),CFile::modeCreate|CFile::modeWrite);

   //构造CFile对象

    CFile file1(_T("CFile1.txt"),CFile::modeCreate|CFile::modeWrite);

    file.Write(C1,strlen(C1)*sizeof(char));//写入数据到文件

    file.Close();//关闭CFile对象。

    file1.Write(C2,strlen(C2)*sizeof(char));//写入数据到文件

    file1.Close();//关闭CFile对象。


    读文件

    file.Open(_T("CFile.txt"),CFile::modeRead);//构造CFile对象

    file1.Open(_T("CFile1.txt"),CFile::modeRead);//构造CFile对象

    char FileContent[100],FileContent1[100];

    CString C4(""),C5(""),C6("");

    string a1="",a2="";

    memset(FileContent,0,100);//初始化FileContent

    memset(FileContent1,0,100);//初始化FileContent

    file.Read(FileContent,100);//读入数据

    file.Close();//关闭文件对象

    file1.Read(FileContent1,100);//读入数据

    file1.Close();//关闭文件对象

    a1=FileContent;

    C4=a1.c_str();

    count2=atoi(a1.c_str());

    a2=FileContent1;

    C5=a2.c_str();

    count3=atoi(a2.c_str());

    GetDlgItem(IDC_STA7)->SetWindowTextW(C4);

    GetDlgItem(IDC_STA8)->SetWindowTextW(C5);

语言切换,现在只能做到切换界面文字,不能将程序中的文字一起切换,仍需进一步研究。


         m_combo.AddString(_T("简体"));  //m_combo为变量名

         m_combo.AddString(_T("繁體")); 

         m_combo.AddString(_T("English"));

         m_combo.SetCurSel(2);


void Cnew1Dlg::OnCbnSelchangeCombo1()

{

         CString strweb,strweb1("简体"),strweb2("繁體"),strweb3("English");

        CString jianti1("下一题");//这里只列出了一个,其他的以此类推。

         CString fanti1("下一題");

         CString en1("next");

         int nSel;

         nSel = m_combo.GetCurSel();  

        m_combo.GetLBText(nSel,strweb);

         if(strweb.Compare(strweb1)==0)

         {

                    SetDlgItemText(IDC_BUTTON1,jianti1);

         }

         else if(strweb.Compare(strweb2)==0)

         {

                   SetDlgItemText(IDC_BUTTON1,fanti1);

                   SetDlgItemText(IDC_STA18,fanti14);

 

         }

         else if(strweb.Compare(strweb3)==0)

         {

                   SetDlgItemText(IDC_BUTTON1,en1);

        }

六、运行截图

初始默认中文简体

几次计算后截图

退出重进,对错题数在以前的基础上增量运算

切换为中文繁体

切换为英文

七、总结
1、MFC控件ID使用时出现未定义,需要进入Resoure.h 对相同控件数值进行修改
2、二人结对编程能使功能实现与错误修改有更高的效率
3、尝试学习新的知识,实现更多功能
码市地址:https://git.coding.net/yhlms/gui-szys.git

PSP2.1 Personal Software Process Stages Time (%) Senior Student(/hour) Time (%)(/hour)
· Planning 计划 2 1.5
· Estimate 估计这个任务需要多少时间 37 40
· Analysis 需求分析 (包括学习新技术) 1 1
· Coding Standard 代码规范 0.5 0.5
· Design 具体设计 1.5 1
· Coding 具体编码 30 35
· Test 测试(自我测试,修改代码,提交修改) 1 1
Reporting 报告 1 1
posted @ 2017-03-15 10:03  Gn1  阅读(322)  评论(2编辑  收藏  举报