软件基础课程设计报告C语言(MFC)计算器设计_第1页
软件基础课程设计报告C语言(MFC)计算器设计_第2页
软件基础课程设计报告C语言(MFC)计算器设计_第3页
软件基础课程设计报告C语言(MFC)计算器设计_第4页
软件基础课程设计报告C语言(MFC)计算器设计_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、软件基础课程设计报告 一、需求分析系统目标:设计的计算器至少能够进行简单的四则运算和求倒数求反以及开方运算。主体功能:程序能实现:加,减,乘,除,开方,倒数等运算功能;还要实现数据的输入,输出,计算,显示及程序退出等功能。另外还可以实现多种科学计算的功能,如:三角函数的计算,弧度与角度间的转换,对数指数的计算等。开发环境:操作系统:windows xp编程环境:microsoftvisualc+6.0 二、功能说明(1)包含的功能有:加、减、乘、除运算,开方、求倒数、三角函数、弧度与角度间的转换、对数指数的计算等功能。(2)计算器上数字09为一个控件数组,加、减、乘、除为一个控件数组,其余为单

2、一的控件。(3)给对话框添加菜单。(4)计算功能基本上是用系统内部函数。(5)程序可以能自动判断输入数据的正确性,保证不出现多于一个小数点、以0开头等不正常现象。(6)“ce”按钮可以清除所有已输入的数据从头计算,“back”按钮可以实现退位功能。(7)能够显示时间、日期。三、详细设计(1)流程图创建工程(创建一个对话框应用程序)设计对话框界面设置各控件属性为编辑框连接成员变量为类添加数据成员,初始化构造函数。为所有按钮添加事件对类添加成员函数(更新编辑框)并进行实现实现对各按钮事件的实现(2)编辑资源(3)效果图四、程序附录计算器dlg.cpp :#include stdafx.h#incl

3、ude 计算器.h#include 计算器dlg.h#include math.h#includefirstdlg.h#include #define pi 3.14;#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ caboutdlg dialog used for app aboutclass caboutdlg : public cdialogpublic:caboutdlg();/ dialog data/afx_data(caboutdlg)enum idd

4、 = idd_aboutbox ;/afx_data/ classwizard generated virtual function overrides/afx_virtual(caboutdlg)protected:virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv support/afx_virtual/ implementationprotected:/afx_msg(caboutdlg)/afx_msgdeclare_message_map();caboutdlg:caboutdlg() : cdialog(cabout

5、dlg:idd)/afx_data_init(caboutdlg)/afx_data_initvoid caboutdlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);/afx_data_map(caboutdlg)/afx_data_mapbegin_message_map(caboutdlg, cdialog)/afx_msg_map(caboutdlg)/ no message handlers/afx_msg_mapend_message_map()/ cmydlg dialogcmydlg:cmydlg(

6、cwnd* pparent /*=null*/): cdialog(cmydlg:idd, pparent)/afx_data_init(cmydlg)m_result = 0.0;/afx_data_init/ note that loadicon does not require a subsequent destroyicon in win32m_hicon = afxgetapp()-loadicon(idr_mainframe);void cmydlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);/afx

7、_data_map(cmydlg)ddx_control(pdx, idc_edit1, m_edit);ddx_text(pdx, idc_edit1, m_result);/afx_data_mapbegin_message_map(cmydlg, cdialog)/afx_msg_map(cmydlg)on_wm_syscommand()on_wm_paint()on_wm_querydragicon()on_bn_clicked(idc_num0, onnum0)on_bn_clicked(idc_num1, onnum1)on_bn_clicked(idc_num2, onnum2)

8、on_bn_clicked(idc_num3, onnum3)on_bn_clicked(idc_num4, onnum4)on_bn_clicked(idc_num5, onnum5)on_bn_clicked(idc_num6, onnum6)on_bn_clicked(idc_num7, onnum7)on_bn_clicked(idc_num8, onnum8)on_bn_clicked(idc_num9, onnum9)on_bn_clicked(idc_dot, ondot)on_bn_clicked(idc_ce, once)on_bn_clicked(idc_jia, onji

9、a)on_bn_clicked(idc_jian, onjian)on_bn_clicked(idc_cheng, oncheng)on_bn_clicked(idc_chu, onchu)on_bn_clicked(idc_dengyu, ondengyu)on_bn_clicked(idc_daoshu, ondaoshu)on_bn_clicked(idc_zhengfu, onzhengfu)on_bn_clicked(idc_backspace, onbackspace)on_bn_clicked(idc_ln, onln)on_bn_clicked(idc_log, onlog)o

10、n_bn_clicked(idc_radio2, onradio2)on_bn_clicked(idc_radio1, onradio1)on_bn_clicked(idc_sqrt, onsqrt)on_bn_clicked(idc_sin, onsin)on_bn_clicked(idc_cos, oncos)on_bn_clicked(idc_tan, ontan)on_bn_clicked(idc_pingfang, onpingfang)on_bn_clicked(idc_lifang, onlifang)on_bn_clicked(idc_mi, onmi)on_bn_clicke

11、d(idc_exp, onexp)on_bn_clicked(idc_10demi, on10demi)on_bn_clicked(idc_jiecheng, onjiecheng)on_command(id_time, ontime)on_command(id_date, ondate)on_command(id_exit, onexit)on_command(id_help, onhelp)/afx_msg_mapend_message_map()/ cmydlg message handlersbool cmydlg:oninitdialog()cdialog:oninitdialog(

12、);/ add about. menu item to system menu./ idm_aboutbox must be in the system command range.assert(idm_aboutbox & 0xfff0) = idm_aboutbox);assert(idm_aboutbox appendmenu(mf_separator);psysmenu-appendmenu(mf_string, idm_aboutbox, straboutmenu);/ set the icon for this dialog. the framework does this aut

13、omatically/ when the applications main window is not a dialogseticon(m_hicon, true);/ set big iconseticon(m_hicon, false);/ set small icon/ todo: add extra initialization herecheckradiobutton(idc_radio1,idc_radio2,idc_radio1);updatedata(false); quan2=1; dotflag=0; numflag=0; return true; / return tr

14、ue unless you set the focus to a controlvoid cmydlg:onsyscommand(uint nid, lparam lparam)if (nid & 0xfff0) = idm_aboutbox)caboutdlg dlgabout;dlgabout.domodal();elsecdialog:onsyscommand(nid, lparam);/ if you add a minimize button to your dialog, you will need the code below/ to draw the icon. for mfc

15、 applications using the document/view model,/ this is automatically done for you by the framework.void cmydlg:onpaint() if (isiconic()cpaintdc dc(this); / device context for paintingsendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0);/ center icon in client rectangleint cxicon = getsystemmet

16、rics(sm_cxicon);int cyicon = getsystemmetrics(sm_cyicon);crect rect;getclientrect(&rect);int x = (rect.width() - cxicon + 1) / 2;int y = (rect.height() - cyicon + 1) / 2;/ draw the icondc.drawicon(x, y, m_hicon);elsecdialog:onpaint();/ the system calls this to obtain the cursor to display while the

17、user drags/ the minimized window.hcursor cmydlg:onquerydragicon()return (hcursor) m_hicon;void cmydlg:onnum0() updatedata();if(dotflag)quan2*=10;m_result+=0/(double)quan2;elseif(numflag)m_result=m_result*10+0;else m_result=0; numflag=1;updatedata(false);void cmydlg:onnum1() updatedata();if(dotflag)q

18、uan2*=10;m_result+=1/(double)quan2;elseif(numflag)m_result=m_result*10+1;else m_result=1; numflag=1;updatedata(false);void cmydlg:onnum2() updatedata();if(dotflag)quan2*=10;m_result+=2/(double)quan2;elseif(numflag)m_result=m_result*10+2;else m_result=2; numflag=1;updatedata(false);void cmydlg:onnum3

19、() updatedata();if(dotflag)quan2*=10;m_result+=3/(double)quan2;elseif(numflag)m_result=m_result*10+3;else m_result=3; numflag=1;updatedata(false);void cmydlg:onnum4() updatedata();if(dotflag)quan2*=10;m_result+=4/(double)quan2;elseif(numflag)m_result=m_result*10+4;else m_result=4; numflag=1;updateda

20、ta(false);void cmydlg:onnum5() updatedata();if(dotflag)quan2*=10;m_result+=5/(double)quan2;elseif(numflag)m_result=m_result*10+5;else m_result=5; numflag=1;updatedata(false);void cmydlg:onnum6() updatedata();if(dotflag)quan2*=10;m_result+=6/(double)quan2;elseif(numflag)m_result=m_result*10+6;else m_

21、result=6; numflag=1;updatedata(false);void cmydlg:onnum7() updatedata();if(dotflag)quan2*=10;m_result+=7/(double)quan2;elseif(numflag)m_result=m_result*10+7;else m_result=7; numflag=1;updatedata(false);void cmydlg:onnum8() updatedata();if(dotflag)quan2*=10;m_result+=8/(double)quan2;elseif(numflag)m_

22、result=m_result*10+8;else m_result=8; numflag=1;updatedata(false);void cmydlg:onnum9() updatedata();if(dotflag)quan2*=10;m_result+=9/(double)quan2;elseif(numflag)m_result=m_result*10+9;else m_result=9; numflag=1;updatedata(false);void cmydlg:ondot() updatedata();dotflag=1;m_result+=0.0;updatedata(fa

23、lse);void cmydlg:once() updatedata();m_edit.setsel(0,-1);m_edit.replacesel();m_result=0;num1=0;num2=0;numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:onjia() updatedata();num1=m_result;cal=+;numflag=0;dotflag=0;quan2=1;void cmydlg:onjian() updatedata();num1=m_result;cal=-;numflag=0;dotflag

24、=0;quan2=1;void cmydlg:oncheng() updatedata();num1=m_result;cal=*;numflag=0;dotflag=0;quan2=1;void cmydlg:onchu() updatedata();num1=m_result;cal=/;numflag=0;dotflag=0;quan2=1;void cmydlg:ondengyu() updatedata();num2=m_result;switch(cal)case+:m_result=num1+num2;break;case-:m_result=num1-num2;break;ca

25、se*:m_result=num1*num2;break;case/:m_result=num1/num2;break;casex:m_result=pow(num1,num2);break;numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:ondaoshu() updatedata();m_result=1/m_result;numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:onzhengfu() updatedata();m_result=0-m_result

26、;updatedata(false);void cmydlg:onbackspace() updatedata();static int dotquan=quan2;long temp;if(dotflag&numflag)if(dotquan=10)temp=(long)(m_result*dotquan);m_result=(double)(temp/10);dotquan/=10;m_result=m_result/dotquan;else/updatedata();if(numflag&m_result)m_result=(long)m_result/10;updatedata(fal

27、se);void cmydlg:onln() updatedata();m_result=log(m_result);numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:onlog() updatedata();m_result=log(m_result)/log(10);numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:onradio2() m_isdegree=1;i=1;updatedata(true);void cmydlg:onradio1() m_isd

28、egree=0;i=(2*3.1415926)/360;updatedata(false);void cmydlg:onsqrt()updatedata(); if(m_result0)messagebox(输入无效!);return;m_result = sqrt(m_result);updatedata(false);void cmydlg:onsin() m_result=sin(m_result*i);updatedata(false);void cmydlg:oncos() m_result=cos(m_result*i);updatedata(false);void cmydlg:ontan() m_

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论