




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
院 系:计 算 机 学 院实验课程:计算机基础实验实验项目:程序设计入门基础指导老师:杨志强 开课时间:2010 2011年度第 2学期专 业:计算机类班 级: 10本4学 生:杨晓添学 号:20102100114华南师范大学教务处1. 题目:简单计算器2. 实验目的:模仿日常生活中所用的计算器,自行设计一个简单的计算器程序,实现简单的计算功能。3. 实验主要硬件软件环境:Window 7Visual C+ 6.04. 实验内容:(1) 体系设计:程序是一个简单的计算器,能正确输入数据,能实现加、减、乘、除等算术运算,能进行简单三角运算,运算结果能正确显示,可以清楚数据等。(2) 设计思路:1) 先在Visual C+ 6.0中建立一个MFC工程文件,名为calculator.2) 在对话框中添加适当的编辑框、按钮、静态文件、复选框和单选框3) 设计按钮,并修改其相应的ID与Caption.4) 选择和设置各控件的单击鼠标事件。5) 为编辑框添加double类型的关联变量m_edit1.6) 在calculatorDlg.h中添加math.h头文件,然后添加public成员。7) 打开calculatorDlg.cpp文件,在构造函数中,进行成员初始化和完善各控件的响应函数代码。(3) 程序清单:程序代码如下:/ calculator_1Dlg.cpp : implementation file/#include stdafx.h#include calculator_1.h#include calculator_1Dlg.h#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 = 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(CAboutDlg: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()/ CCalculator_1Dlg dialogCCalculator_1Dlg:CCalculator_1Dlg(CWnd* pParent /*=NULL*/): CDialog(CCalculator_1Dlg:IDD, pParent)/AFX_DATA_INIT(CCalculator_1Dlg)m_edit1 = 0.0;/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);tempvalue=0;result=0;sort=0;append=0;void CCalculator_1Dlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CCalculator_1Dlg)DDX_Text(pDX, IDC_EDIT1, m_edit1);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CCalculator_1Dlg, CDialog)/AFX_MSG_MAP(CCalculator_1Dlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_BN_CLICKED(IDC_BUTTON3, OnButton3)ON_BN_CLICKED(IDC_BUTTON4_plus, OnBUTTON4plus)ON_BN_CLICKED(IDC_BUTTON5_4, OnButton54)ON_BN_CLICKED(IDC_BUTTON6_5, OnButton65)ON_BN_CLICKED(IDC_BUTTON7_6, OnButton76)ON_BN_CLICKED(IDC_BUTTON8_minus, OnBUTTON8minus)ON_BN_CLICKED(IDC_BUTTON12_multi, OnBUTTON12multi)ON_BN_CLICKED(IDC_BUTTON16_div, OnBUTTON16div)ON_BN_CLICKED(IDC_BUTTON9_7, OnButton97)ON_BN_CLICKED(IDC_BUTTON10_8, OnButton108)ON_BN_CLICKED(IDC_BUTTON11_9, OnButton119)ON_BN_CLICKED(IDC_BUTTON13_zero, OnBUTTON13zero)ON_BN_CLICKED(IDC_BUTTON14_equal, OnBUTTON14equal)ON_BN_CLICKED(IDC_RADIO1_sin, OnRADIO1sin)ON_BN_CLICKED(IDC_RADIO2_cos, OnRADIO2cos)ON_BN_CLICKED(IDC_RADIO3_tan, OnRADIO3tan)ON_BN_CLICKED(IDC_RADIO5_log10, OnRADIO5log10)ON_BN_CLICKED(IDC_BUTTON15_clean, OnBUTTON15clean)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CCalculator_1Dlg message handlersBOOL CCalculator_1Dlg:OnInitDialog()CDialog:OnInitDialog();/ 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 automatically/ 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 herereturn TRUE; / return TRUE unless you set the focus to a controlvoid CCalculator_1Dlg: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 applications using the document/view model,/ this is automatically done for you by the framework.void CCalculator_1Dlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(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 user drags/ the minimized window.HCURSOR CCalculator_1Dlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;void CCalculator_1Dlg:OnButton1() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+1;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnButton2() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+2;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnButton3() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+3;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnBUTTON4plus() / TODO: Add your control notification handler code heresort=1;tempvalue=result;m_edit1=0;append=1;void CCalculator_1Dlg:OnButton54() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+4;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnButton65() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+5;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnButton76() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+6;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnBUTTON8minus() / TODO: Add your control notification handler code heresort=2;tempvalue=result;m_edit1=0;append=1;void CCalculator_1Dlg:OnBUTTON12multi() / TODO: Add your control notification handler code heresort=3;tempvalue=result;m_edit1=0;append=1;void CCalculator_1Dlg:OnBUTTON16div() / TODO: Add your control notification handler code heresort=4;tempvalue=result;m_edit1=0;append=1;void CCalculator_1Dlg:OnButton97() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+7;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnButton108() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+8;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnButton119() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+9;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnBUTTON13zero() / TODO: Add your control notification handler code hereif(append=1) result=0;result=result*10+0;m_edit1=result;append=0;UpdateData(FALSE);void CCalculator_1Dlg:OnBUTTON14equal() / TODO: Add your control notification handler code hereswitch(sort)case 1:result=result+tempvalue;break; case 2:result=tempvalue-result;break;case 3:result=tempvalue*result;break;case 4:result=tempvalue/result;break;m_edit1=result;UpdateData(FALSE);void CCalculat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年生物化学模拟习题(含参考答案)
- 消控员证书题目及答案
- 2025房屋租赁合同的基本协议
- 曹阳二中分班考试试卷及答案
- 2025港口物流运输合同
- 藏医解剖技术考试题库及答案
- 2025终止的工程承包合同
- 仓管员的入职考试题目及答案
- 2025年基层眼科试题及答案解析
- 2025建筑工程合同样本
- 河南省开封市西北片区2023-2024学年九年级英语第一学期期末达标检测模拟试题含解析
- ISO9001-2015-质量管理体系过程关系图
- 数字经济前沿八讲
- 数字经济概论-完整全套教学课件
- 《数字媒体基础与实践》数字媒体技术概述
- 直接抒情与间接抒情
- 中电联理论试卷A(无答案)
- 红岩优秀读后感800字5篇
- GB/T 2679.7-2005纸板戳穿强度的测定
- 文化政策与法规(第一课)
- 色彩基础知识ppt
评论
0/150
提交评论