




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、/ CKcalculateDlg.cpp : implementation file/#include "stdafx.h"#include "math.h"#include "CKcalculate.h"#include "CKcalculateDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/double m_first;/存儲一次運(yùn)算的第一個(gè)操作數(shù)及一次運(yùn)算的結(jié)果/ dou
2、ble m_second; /存儲一次運(yùn)算的第二個(gè)操作數(shù)/CString m_operator;/存儲運(yùn)算符/double m_coff;/存儲小數(shù)點(diǎn)的系數(shù)權(quán)值/ CAboutDlg dialog used for App About/class CAboutDlg : public CDialogpublic:CAboutDlg();/ Dialog Data/AFX_DATA(CAboutDlg)enum IDD = IDD_ABOUTBOX ;/AFX_DATA/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(C
3、AboutDlg)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
4、* 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()/ CCKcalculateDlg dialogCCKcalculateDlg:CCKcalculateDlg(CWnd* pParent /*=NULL*/): CDialog(CCKcalculateDlg:IDD, pParent)
5、/void UpdateDisplay(double);/void Calculate(void);/AFX_DATA_INIT(CCKcalculateDlg)/isXdeY=false;m_display = _T("");m_first=0.0;m_second=0.0;m_operator=_T("+");m_coff=0;m_display=_T("0.0");/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win
6、32m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);void CCKcalculateDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CCKcalculateDlg)DDX_Text(pDX, IDC_DISPLAY, m_display);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CCKcalculateDlg, CDialog)/AFX_MSG_MAP(CCKcalculateDlg)ON_WM_SYSCOM
7、MAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON0, OnButton0)ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_BN_CLICKED(IDC_BUTTON3, OnButton3)ON_BN_CLICKED(IDC_BUTTON4, OnButton4)ON_BN_CLICKED(IDC_BUTTON5, OnButton5)ON_BN_CLICKED(IDC_BUTTON6, OnButton6)O
8、N_BN_CLICKED(IDC_BUTTON7, OnButton7)ON_BN_CLICKED(IDC_BUTTON8, OnButton8)ON_BN_CLICKED(IDC_BUTTON9, OnButton9)ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)ON_BN_CLICKED(IDC_BUTTON_MINUS, OnButtonMinus)ON_BN_CLICKED(IDC_BUTTON_MUTIPLY, OnButtonMutiply)ON_BN_CLICKED(IDC_BUTTON_DIV, OnButtonDiv)ON_BN_CLIC
9、KED(IDC_BUTTON_SIGH, OnButtonSigh)ON_BN_CLICKED(IDC_BUTTON_POINT, OnButtonPoint)ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)ON_BN_CLICKED(IDC_BUTTON_SQRT, OnButtonSqrt)ON_BN_CLICKED(IDC_BUTTON_RECI, OnButtonReci)ON_BN_CLICKED(IDC_BUTTON_EQUAL, OnButtonEqual)ON_BN_CLICKED(IDC_BUTTON_SIN, OnButtonSi
10、n)ON_BN_CLICKED(IDC_BUTTON_COS, OnButtonCos)ON_BN_CLICKED(IDC_BUTTON_LOG, OnButtonLog)ON_BN_CLICKED(IDC_BUTTON_XDEY, OnButtonXdeY)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CCKcalculateDlg message handlers/BOOL CCKcalculateDlg:OnInitDialog()CDialog:OnInitDialog();/ Add "About." menu item to system men
11、u./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL)CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()pSysMenu->Appen
12、dMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the application's main window is not a SetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small icon/ TODO: Add extra ini
13、tialization herereturn TRUE; / return TRUE unless you set the focus to a controlvoid CCKcalculateDlg: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, yo
14、u 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 CCKcalculateDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(),
15、 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();
16、/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CCKcalculateDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;/按鍵代碼/void CCKcalculateDlg:OnButton0() / TODO: Add your control notification handler code hereonButtonN(0);void CCKcalculateDlg:OnButto
17、n1() / TODO: Add your control notification handler code hereonButtonN(1);void CCKcalculateDlg:OnButton2() / TODO: Add your control notification handler code hereonButtonN(2);void CCKcalculateDlg:OnButton3() / TODO: Add your control notification handler code hereonButtonN(3);void CCKcalculateDlg:OnBu
18、tton4() / TODO: Add your control notification handler code hereonButtonN(4);void CCKcalculateDlg:OnButton5() / TODO: Add your control notification handler code hereonButtonN(5);void CCKcalculateDlg:OnButton6() / TODO: Add your control notification handler code hereonButtonN(6);void CCKcalculateDlg:O
19、nButton7() / TODO: Add your control notification handler code hereonButtonN(7);void CCKcalculateDlg:OnButton8() / TODO: Add your control notification handler code hereonButtonN(8);void CCKcalculateDlg:OnButton9() / TODO: Add your control notification handler code hereonButtonN(9);/計(jì)算按鍵代碼/void CCKcal
20、culateDlg:OnButtonAdd() / TODO: Add your control notification handler code hereCalculate();m_operator="+"void CCKcalculateDlg:OnButtonMinus() / TODO: Add your control notification handler code hereCalculate();m_operator="-"void CCKcalculateDlg:OnButtonMutiply() / TODO: Add your c
21、ontrol notification handler code hereCalculate();m_operator="*"void CCKcalculateDlg:OnButtonDiv() / TODO: Add your control notification handler code hereCalculate();m_operator="/"void CCKcalculateDlg:OnButtonSigh() / TODO: Add your control notification handler code herem_second=-
22、m_second; UpdateDisplay(m_second);void CCKcalculateDlg:OnButtonPoint() / TODO: Add your control notification handler code herem_coff =0.1;void CCKcalculateDlg:OnButtonClear() / TODO: Add your control notification handler code herem_first=0.0;m_second=0.0;m_operator="+"m_coff = 1.0;UpdateDi
23、splay(0.0);void CCKcalculateDlg:OnButtonSqrt() / TODO: Add your control notification handler code hereif( m_second=0 )m_first=sqrt(m_first);UpdateDisplay(m_first);else m_second=sqrt(m_second);UpdateDisplay(m_second); void CCKcalculateDlg:OnButtonReci() / TODO: Add your control notification handler c
24、ode hereif( fabs(m_second ) < 0.000001 && fabs( m_first )<0.000001)m_display="除數(shù)不能為零"UpdateDisplay(false);return;if( fabs(m_second ) < 0.000001)m_first=1.0/m_first;UpdateDisplay(m_first);elsem_second=1.0/m_second;UpdateDisplay(m_second);void CCKcalculateDlg:OnButtonEqual()
25、 / TODO: Add your control notification handler code hereXdeY();Calculate();void CCKcalculateDlg:UpdateDisplay(double ck)m_display.Format(_T("%f"),ck);int i=m_display.GetLength();/格式化輸出,將輸出結(jié)果后的零截去while(m_display.GetAt(i-1)='0') m_display.Delete(i-1,1);i-;/更新編輯框變量m_displayUpdateData(
26、false); void CCKcalculateDlg:Calculate(void)/將前一次數(shù)據(jù)與當(dāng)前數(shù)據(jù)進(jìn)行運(yùn)算,作為下次的第一操作數(shù),并在編輯框顯示switch(m_operator.GetAt(0)case '+': m_first+=m_second;break;case '-': m_first-=m_second;break;case '*': m_first*=m_second;break;case '/':if( fabs(m_second ) <= 0.000001)m_display="除
27、數(shù)不能為0"UpdateData(false);return;m_first/=m_second;break;m_second=0.0;m_coff=1.0;m_operator=_T("+");/更新編輯框顯示內(nèi)容UpdateDisplay(m_first);void CCKcalculateDlg:onButtonN(int n)if(m_coff=1.0)/作為整數(shù)輸入數(shù)字時(shí)m_second=m_second*10+n;else/作為小數(shù)輸入數(shù)字m_second=m_second+n*m_coff;m_coff*=0.1; /更新編輯框的數(shù)字顯示Update
28、Display(m_second);void CCKcalculateDlg:OnButtonSin() / TODO: Add your control notification handler code herem_second=m_second*m_PI/180;m_second=sin(m_second);UpdateDisplay(m_second);void CCKcalculateDlg:OnButtonCos() / TODO: Add your control notification handler code herem_second=m_second*m_PI/180;m
29、_second=cos(m_second);UpdateDisplay(m_second);void CCKcalculateDlg:OnButtonLog() / TODO: Add your control notification handler code herem_second=log10(m_second);UpdateDisplay(m_second);void CCKcalculateDlg:OnButtonXdeY() / TODO: Add your control notification handler code heretemp=m_second;m_second=0
30、.0; UpdateDisplay(m_second); isXdeY=true;void CCKcalculateDlg:XdeY()if(isXdeY)m_second=m_second;m_second=pow(temp,m_second);/以下是CKcalculateDlg.h代碼/ /CKcalculateDlg.h : header file/#if !defined(AFX_CKCALCULATEDLG_H_8DEB211E_CFCF_44C8_895C_BEF4E77EBE6C_INCLUDED_)#define AFX_CKCALCULATEDLG_H_8DEB211E_C
31、FCF_44C8_895C_BEF4E77EBE6C_INCLUDED_#if _MSC_VER > 1000#pragma once#endif / _MSC_VER > 1000/ CCKcalculateDlg dialogclass CCKcalculateDlg : public CDialog / Constructionpublic:void XdeY(void);bool isXdeY;double temp;double m_PI;void onButtonN(int n);void UpdateDisplay(double ck);void Calculate(
32、);CCKcalculateDlg(CWnd* pParent = NULL);/ standard constructor/ Dialog Data/AFX_DATA(CCKcalculateDlg)enum IDD = IDD_CKCALCULATE_DIALOG ;CStringm_display;/AFX_DATAdouble m_first;/存儲一次運(yùn)算的第一個(gè)操作數(shù)及一次運(yùn)算的結(jié)果double m_second;/存儲一次運(yùn)算的第二個(gè)操作數(shù)CString m_operator;/存儲運(yùn)算符double m_coff;/存儲小數(shù)點(diǎn)的系數(shù)權(quán)值/ ClassWizard generated virtual function overrides/ AFX_VIRTUAL(CCKcalculateDlg)protected:virtual void DoDataExchange(CDataExchange* pDX);/ DDX/DDV support/AFX_VIRTUAL/ Implementationprotecte
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年福建省事業(yè)單位勞動合同書
- 超市食品百貨員工培訓(xùn)
- 銀行操作風(fēng)險(xiǎn)與內(nèi)部控制
- 2025華瑞機(jī)械制造公司應(yīng)急預(yù)案合同
- 酒店保潔保安培訓(xùn)課件
- 口腔護(hù)理操作及并發(fā)癥
- 2025年份2月份腦波控制技術(shù)抵押借款動態(tài)利率調(diào)整協(xié)議
- 舊空調(diào)安裝合同范本
- 石灰運(yùn)輸銷售合同范本
- 冷庫承包的合同二零二五年
- 全國戒毒醫(yī)療機(jī)構(gòu)名單
- ICU 呼吸機(jī)相關(guān)性肺炎預(yù)防措施執(zhí)行核查表
- 汽車吊檢測保養(yǎng)記錄
- LOTO上鎖掛牌培訓(xùn)資料課件
- 市政工程安全臺賬表
- DB63-T 1800-2020鹽湖鹵水礦堤壩工程施工技術(shù)規(guī)范
- 航天模型的設(shè)計(jì)、制作與比賽課件
- 公路工程施工現(xiàn)場安全檢查手冊
- 高考倒計(jì)時(shí)60天課件
- 幼兒園繪本故事:《十二生肖》 課件
- 公司組織架構(gòu)圖(可編輯模版)
評論
0/150
提交評論