计算器基于C++MFC实现.doc

上传人:仙人指路1688 文档编号:2387615 上传时间:2023-02-17 格式:DOC 页数:17 大小:239.50KB
返回 下载 相关 举报
计算器基于C++MFC实现.doc_第1页
第1页 / 共17页
计算器基于C++MFC实现.doc_第2页
第2页 / 共17页
计算器基于C++MFC实现.doc_第3页
第3页 / 共17页
计算器基于C++MFC实现.doc_第4页
第4页 / 共17页
计算器基于C++MFC实现.doc_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《计算器基于C++MFC实现.doc》由会员分享,可在线阅读,更多相关《计算器基于C++MFC实现.doc(17页珍藏版)》请在三一办公上搜索。

1、课程实验报告课程名称C+面向对象程序设计班级XXXXX实验日期2015-05-19姓名XXX学号XXXXX实验成绩实验名称 C+简单程序设计实验目的及要求1. 学习使用Visual C+的MFC开发程序的步骤。2. 综合运用所学的类、继承和多态的知识开发程序。3. 进一步熟练掌握程序调试方法。实验环境 Microsoft Visual C+实验内容1. 利用MFC的向导创建基于对话框的应用程序,添加按钮、编辑框等控件。2. 实现算数“加、减、乘、除”的运算。算法描述及实验步骤设计步骤:(1) 打开Microsoft Visual C+ 6.0,在文件中点击新建,在弹出框内选择MFC AppWi

2、zardexe工程,输入工程名JISUANQI并在其所在的位置点击确定。(2) 将弹出MFC AppWizard-step1对话框,选择基本对话框点击完成。(3) 基于对话窗口的程序框架建立成功。界面设计:(1) 创建控件:在Resource View选项卡中打开Dialog资源组,双击IDD_JISUANQI,在右边的窗口中显示待编辑的对话框。开始摆放控件,包括编辑框和按钮的创建。(2) 在对话框编辑窗口上合适的位置按下鼠标左键并拖动鼠标画出一个大小合适的编辑框。在编辑框上单击鼠标右键,在弹出的快捷菜单中选择属性选项,此时弹出Edit属性对话框。(3) 在对话框上的合适的位置上按下鼠标左键并

3、拖动鼠标画出一个大小合适的下压式按钮。在按钮上单击鼠标右键,在弹出的快捷菜单中选择属性选项,此时也会弹出 push button对话框。 标题 ID 说明 编辑框 ID_Edit 结果显示 按钮 ID_Button0 0 按钮 ID_Button1 1 按钮 ID_Button2 2 按钮 ID_Button3 3 按钮 ID_Button4 4 按钮 ID_Button5 5 按钮 ID_Button6 6 按钮 ID_Button7 7 按钮 ID_Button8 8 按钮 ID_Button9 9 按钮 ID_ButtonJIA + 按钮 ID_ButtonJIAN - 按钮 ID_Bu

4、ttonCHENG * 按钮 ID_ButtonCHU / 按钮 ID_Buttonequal = 按钮 ID_Buttonc 0链接代码和变量:(1) 给编辑框连接变量。在编辑框上单击鼠标右键,在弹出的菜单中选择ClassWizard菜单项,弹出MFC ClassWizard对话框选择Member Variables选项卡。(2) 在Control IDs列表框中选择IDC_Edit,单击Add Variables按钮,在弹出的对话框中链接变量m_NUM。变量类型设定为double型。m_NUM属性设置:给X按钮链接代码。在X按钮上单击鼠标右键,选择ClassWizard菜单项,在弹出的对话

5、框中选择Message Maps选项卡,然后在Object IDs列表框中选择BN_CLICKED项,即单击按钮事件。菜单设计:(1)选择插入/资源命令,将显示插入资源对话框。选择Menu,点击新建即可。(2)Resource View选项卡中打开Menu资源组,双击IDR_MENU1,然后给菜单添加相应的标题,并把每个菜单对应的ID值与相应的按钮一致。(3)在对话框的任何一个空白域单击鼠标右键,然后在弹出的快捷菜单中选择Properties命令,弹出Dialog Properties对话框,在对话框中的菜单组合框中选择IDR_MENU1。结构图:调试过程及实验结果1. 初始化状态: 2. 加

6、法运算: 3. 乘法运算: 4. 清零运算: 总结 通过此次试验极大的锻炼了编码能力,巩固了之前所学的知识。实验过程中出现了些许问题,所幸都可以解决,并为以后的实验提供了经验。附录#include stdafx.h#include JISUANQI.h#include JISUANQIDlg.h#includemath.hbool ele2;int addt;int i;int dint;bool ele;double num1;double num2;class CAboutDlg : public CDialogpublic:CAboutDlg();enum IDD = IDD_ABOUT

7、BOX ;protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV supportprotected:DECLARE_MESSAGE_MAP();BOOL CJISUANQIDlg:OnInitDialog()OnBUTTONc();CDialog:OnInitDialog();ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING

8、, IDM_ABOUTBOX, strAboutMenu);SetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small iconreturn TRUE; / return TRUE unless you set the focus to a controlvoid CJISUANQIDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();els

9、eCDialog:OnSysCommand(nID, lParam);void CJISUANQIDlg:OnPaint()if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);int cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);in

10、t x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;dc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();void CJISUANQIDlg:OnButton0()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM*10+0;else m_NUM=m_NUM*10-0;if(ele=TRUE) num1=0

11、; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton1()/ TODO: Add your control notification handler code hereint i;if(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM*10+1;else m_NUM=m_NUM*10-1;if(ele=T

12、RUE) num1=1; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton2()/ TODO: Add your control notification handler code hereint i;if(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM*10+2;else m_NUM=m_NUM*10

13、-2;if(ele=TRUE) num1=2; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton3()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM*10+3;else m_NUM=m_N

14、UM*10-3;if(ele=TRUE) num1=3; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton4()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM*10+4;else m_NU

15、M=m_NUM*10-4;if(ele=TRUE) num1=4; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton5()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM*10+5;else

16、 m_NUM=m_NUM*10-5;if(ele=TRUE) num1=5; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton6()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM*10+6

17、;else m_NUM=m_NUM*10-6;if(ele=TRUE) num1=6; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton7()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m_NUM=m_NUM

18、*10+7;else m_NUM=m_NUM*10-7;if(ele=TRUE) num1=7; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton8()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m_NUM=

19、m_NUM*10+8;else m_NUM=m_NUM*10-8;if(ele=TRUE) num1=8; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButton9()/ TODO: Add your control notification handler code hereif(addt=0)num2=0;if(ele2=TRUE)m

20、_NUM=m_NUM*10+9;else m_NUM=m_NUM*1019;if(ele=TRUE) num1=9; dint=dint+; for(i=0;idint;i+) num1=num1/10; if(ele2=TRUE) m_NUM=(m_NUM-1)/10+num1; else m_NUM=(m_NUM+1)/10-num1; UpdateData(FALSE);void CJISUANQIDlg:OnButtonPoint()/ TODO: Add your control notification handler code herevoid CJISUANQIDlg:OnBu

21、ttonEqual()/ TODO: Add your control notification handler code hereswitch(addt) case 0: UpdateData(FALSE); break; case 1: m_NUM=num2+m_NUM; UpdateData(FALSE); break; case 2: m_NUM=num2-m_NUM; UpdateData(FALSE); break; case 3: m_NUM=num2*m_NUM; UpdateData(FALSE); break; case 4: m_NUM=num2/m_NUM; Updat

22、eData(FALSE); break;num2=m_NUM;m_NUM=0;num1=0;dint=0;ele=FALSE;addt=0;ele2=TRUE;void CJISUANQIDlg:OnButtonJia()/ TODO: Add your control notification handler code hereif(addt!=0) OnButtonEqual(); if(num2=0) num2=m_NUM; m_NUM=0; ele=FALSE; ele2=TRUE; dint=0; addt=1;void CJISUANQIDlg:OnButtonJian()/ TO

23、DO: Add your control notification handler code hereif(addt!=0) OnButtonEqual(); if(num2=0) num2=m_NUM; m_NUM=0; ele=FALSE; ele2=TRUE; dint=0; addt=2;void CJISUANQIDlg:OnButtonCheng()/ TODO: Add your control notification handler code hereif(addt!=0) OnButtonEqual(); if(num2=0) num2=m_NUM; m_NUM=0; el

24、e=FALSE; ele2=TRUE; dint=0; addt=3;void CJISUANQIDlg:OnButtonChu()/ TODO: Add your control notification handler code hereif(addt!=0) OnButtonEqual(); if(num2=0) num2=m_NUM; m_NUM=0; ele=FALSE; ele2=TRUE; dint=0; addt=4;void CJISUANQIDlg:OnBUTTONc()/ TODO: Add your control notification handler code herem_NUM=0;num1=0;num2=0;dint=0;addt=0;ele=FALSE;ele2=TRUE;UpdateData(FALSE);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号