b2c信息网

您现在的位置是:首页 > 昨日新闻 > 正文

昨日新闻

cmfc计算器源码(mfc简易计算器代码)

hacker2022-06-09 20:36:25昨日新闻33
本文目录一览:1、MFC简单计算器代码2、

本文目录一览:

MFC 简单计算器代码

class CCalculatorDlg : public CDialog

{

// Construction

public:

void SaveValue1();

CCalculatorDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data

//{{AFX_DATA(CCalculatorDlg)

enum { IDD = IDD_CALCULATOR_DIALOG };

CEdit m_edit;span style="white-space:pre" /span//显示使用一个编辑框

CString m_str;span style="white-space:pre" /span//编辑框内的字符串

//输入的2个值

double m_fNumber1;

double m_fNumber2;

//保存计算符号类型 0='+',1='-',2='*',3='/'

int m_iSign;

//计算

void Calculator();

//}}AFX_DATA

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CCalculatorDlg)

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL

// Implementation

protected:

HICON m_hIcon;

// Generated message map functions

//{{AFX_MSG(CCalculatorDlg)

virtual BOOL OnInitDialog();

afx_msg void OnSysCommand(UINT nID, LPARAM lParam);

afx_msg void OnPaint();

afx_msg HCURSOR OnQueryDragIcon();

afx_msg void OnMyAbout();

afx_msg void OnButtonBack();

afx_msg void OnButtonClear();

afx_msg void OnButton1();

afx_msg void OnButton2();

afx_msg void OnButton3();

afx_msg void OnButton4();

afx_msg void OnButton5();

afx_msg void OnButton6();

afx_msg void OnButton7();

afx_msg void OnButton8();

afx_msg void OnButton9();

afx_msg void OnButton0();

afx_msg void OnButtonDian();

afx_msg void OnButtonJia();

afx_msg void OnButtonJian();

afx_msg void OnButtonCheng();

afx_msg void OnButtonChu();

afx_msg void OnButtonDeng();

afx_msg void OnButtonPingFang();

afx_msg void OnButtonKaiFang();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CalculatorDlg.cpp文件中:

[cpp] view plain copy

void CCalculatorDlg::OnButtonBack()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

//移除最右边一个字符

if (!m_str.IsEmpty())

{

m_str = m_str.Left(m_str.GetLength()-1);

}

UpdateData(FALSE);

}

void CCalculatorDlg::OnButtonClear()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = "";

m_fNumber1 = 0.0f;

m_fNumber2 = 0.0f;

m_iSign = 0;

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton1()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "1";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton2()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "2";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton3()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "3";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton4()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "4";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton5()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "5";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton6()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "6";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton7()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "7";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton8()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "8";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton9()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "9";

UpdateData(FALSE);

}

void CCalculatorDlg::OnButton0()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_str = m_str + "0";

UpdateData(FALSE);

}

//小数点按钮

void CCalculatorDlg::OnButtonDian()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

//如果没有小数点,则加上一个小数点,如果已有小数点就忽略此次的小数点,保证最多只有1个

if (-1 == m_str.Find('.'))

{

m_str = m_str + ".";

}

UpdateData(FALSE);

}

void CCalculatorDlg::OnButtonJia()

{

// TODO: Add your control notification handler code here

SaveValue1();

m_iSign = 0;

}

void CCalculatorDlg::OnButtonJian()

{

// TODO: Add your control notification handler code here

SaveValue1();

m_iSign = 1;

}

void CCalculatorDlg::OnButtonCheng()

{

// TODO: Add your control notification handler code here

SaveValue1();

m_iSign = 2;

}

void CCalculatorDlg::OnButtonChu()

{

// TODO: Add your control notification handler code here

SaveValue1();

m_iSign = 3;

}

void CCalculatorDlg::OnButtonDeng()

{

// TODO: Add your control notification handler code here

Calculator();

}

void CCalculatorDlg::SaveValue1()

{

UpdateData(TRUE);

m_fNumber1 = atof(m_str);

m_str = "";

UpdateData(FALSE);

}

void CCalculatorDlg::Calculator()

{

UpdateData(TRUE);

m_fNumber2 = atof(m_str);

double f = 0.0f;

switch (m_iSign)

{

//加

case 0:

f = m_fNumber1 + m_fNumber2;

break;

//减

case 1:

f = m_fNumber1 - m_fNumber2;

break;

//乘

case 2:

f = m_fNumber1 * m_fNumber2;

break;

//除

case 3:

if (m_fNumber2 == 0.0f)

{

f = m_fNumber1;

}

else

{

f = m_fNumber1 / m_fNumber2;

}

break;

//平方

case 4:

f = m_fNumber2 * m_fNumber2;

break;

//开方

case 5:

f = sqrt(m_fNumber2);

break;

default:

break;

}

//如果浮点数其实是个整数

if(f - int(f) = 1e-5)

{

m_str.Format("%d",(int)f);

}

else

{

m_str.Format("%f",f);

}

UpdateData(FALSE);

m_fNumber1 = f;

m_fNumber2 = 0.0f;

}

void CCalculatorDlg::OnButtonPingFang()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_fNumber1 = atof(m_str);

double f = m_fNumber1 * m_fNumber1;

//如果浮点数其实是个整数

if(f - int(f) = 1e-5)

{

m_str.Format("%d",(int)f);

}

else

{

m_str.Format("%f",f);

}

UpdateData(FALSE);

m_fNumber1 = f;

m_fNumber2 = 0.0f;

m_iSign = 4;

}

void CCalculatorDlg::OnButtonKaiFang()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

m_fNumber1 = atof(m_str);

double f = sqrt(m_fNumber1);

//如果浮点数其实是个整数

if(f - int(f) = 1e-5)

{

m_str.Format("%d",(int)f);

}

else

{

m_str.Format("%f",f);

}

UpdateData(FALSE);

m_fNumber1 = f;

m_fNumber2 = 0.0f;

m_iSign = 5;

}

求用MFC编写的计算器的源代码,请发到我邮箱heyanhong6688@163.com,非常感谢

在MFC

AppWized(exe)项目下做。界面自己做

1.在对话框的头文件CalculatorDlg.h中添加#includemath.h

2.为CCalculatorDlg类添加成员数据和成员函数

double

number1,number2;

int

NumberState,OperationState;

void

cal();

并在CCalculatorDlg类的构造函数中增加NumberState=1;

3.添加消息按钮afx_msg

void

OnNumberKey(UINT

nID);

afx_msg

void

OnOperationKey(UINT

nID);

4.在CalculatorDlg.cpp文件中BEGIN_MESSAGE_MAP(CMy1Dlg,

CDialog)和END_MESSAGE_MAP()间添加代码

ON_COMMAND_RANGE(IDC_NUMBER1,IDC_NUMBER10,OnNumberKey)

ON_COMMAND_RANGE(IDC_NUMBER11,IDC_NUMBER20,OnOperationKey)

5.为成员函数OnNumberKey和OnOperationKey添加代码

void

CCalculatorDlg::OnNumberKey(UINT

nID)

{

int

n=0;

switch(nID)

{

case

IDC_NUMBER1:n=1;break;

case

IDC_NUMBER2:n=2;break;

case

IDC_NUMBER3:n=3;break;

case

IDC_NUMBER4:n=4;break;

case

IDC_NUMBER5:n=5;break;

case

IDC_NUMBER6:n=6;break;

case

IDC_NUMBER7:n=7;break;

case

IDC_NUMBER8:n=8;break;

case

IDC_NUMBER9:n=9;break;

case

IDC_NUMBER10:n=0;break;

}

if(NumberState==1)

{

m_result=m_result*10+n;

number1=m_result;

UpdateData(FALSE);

//

更新编辑框中的值

}

else

{

m_result=m_result*10+n;

number2=m_result;

UpdateData(FALSE);

}

}

void

CCalculatorDlg::OnOperationKey(UINT

nID)

{

switch(nID)

{

case

IDC_NUMBER13:

//

"/"按钮

OperationState=1;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case

IDC_NUMBER14:

//

"*"按钮

OperationState=2;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case

IDC_NUMBER15:

//

"+"按钮

OperationState=3;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case

IDC_NUMBER16:

//

"-"按钮

OperationState=4;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case

IDC_NUMBER17:

//

"C"按钮,撤消用,不需要可以删除

number1=number2=m_result=0;

UpdateData(FALSE);

NumberState=1;

break;

case

IDC_NUMBER20:

//

"="按钮

cal();

//

调用cal成员函数

break;

}

}

6.为成员函数cal()添加代码

void

CCalculatorDlg::cal()

{

switch(OperationState)

{

case

1:

m_result=(double)number1/number2;

UpdateData(FALSE);

//

更新编辑框中的结果

number1=m_result;

//

把此次的运算结果作为下一次运算的第一个操作数

NumberState=2;

//

下次输入的数作为第二个操作数

break;

case

2:

m_result=number1*number2;

UpdateData(FALSE);

//

更新编辑框中的结果

number1=m_result;

NumberState=2;

break;

case

3:

m_result=number1+number2;

UpdateData(FALSE);

//

更新编辑框中的结果

number1=m_result;

NumberState=2;

break;

case

4:

m_result=number1-number2;

UpdateData(FALSE);

//

更新编辑框中的结果

number1=m_result;

NumberState=2;

break;

}

OperationState=0;

}

注意按钮的ID号要和程序中的ID号相同!!!!要不然会有的按钮点击没反应……

c语言的mfc怎么编程计算器,急用,有详细步骤截图代码。谢谢。帮帮忙。

#include stdio.h

void main(){

int a , b;

char cOperator;

int x;

printf("请输入两个整数的运算式:\n");

scanf("%d%c%d",a,cOperator,b);

if(cOperator=='+')x=(a + b);

else if(cOperator=='-')x=(a - b);

else if(cOperator=='*')x=(a * b);

else if(cOperator=='/')x=(a / b);

else printf("符号输入错误!\n");

printf("%d%c%d",a,cOperator,b);

printf("=%d\n",x);

}

(1)不知道楼主为什么要用"while",但个人认为没有必要.

(2)楼主所有的if语句都存在问题,例如:if(cOperator='+')这句,应改为if(cOperator=='+'),因为C语言中的"="不是代表"等于",而是"赋值".

MFC编写计算器具体步骤 方法 代码,拜托高手急用!

1、首先打开VS2013,新建一个VC++ MFC项目,命名为 gongzi。

2、然后在程序类型中,选择“基于对话框”,点击“完成”按钮。

3、然后在弹出的对话框中,删除原先的Static Text,添加相应的控件到窗体上。

4、接着在应发工资编辑框右击添加变量。 变量名称是 m_editTotal, 变量类型是 double, 类别为 value,点击“完成”。同样扣税费用编辑框右击添加变量。 变量名称是 m_editTax, 变量类型是 double, 类别为 value,应扣税款标签右击添加变量。

5、然后双击“计算应扣税款”进入代码,添加代码。

6、最后点击运行,输入对应的数目,按下按钮,查看执行效果。

求MFC编写计算器的详细方法 步骤 代码

在MFC AppWized(exe)项目下做。界面自己做

1.在对话框的头文件CalculatorDlg.h中添加#includemath.h

2.为CCalculatorDlg类添加成员数据和成员函数

double number1,number2;

int NumberState,OperationState;

void cal();

并在CCalculatorDlg类的构造函数中增加NumberState=1;

3.添加消息按钮afx_msg void OnNumberKey(UINT nID);

afx_msg void OnOperationKey(UINT nID);

4.在CalculatorDlg.cpp文件中BEGIN_MESSAGE_MAP(CMy1Dlg, CDialog)和END_MESSAGE_MAP()间添加代码

ON_COMMAND_RANGE(IDC_NUMBER1,IDC_NUMBER10,OnNumberKey)

ON_COMMAND_RANGE(IDC_NUMBER11,IDC_NUMBER20,OnOperationKey)

5.为成员函数OnNumberKey和OnOperationKey添加代码

void CCalculatorDlg::OnNumberKey(UINT nID)

{

int n=0;

switch(nID)

{

case IDC_NUMBER1:n=1;break;

case IDC_NUMBER2:n=2;break;

case IDC_NUMBER3:n=3;break;

case IDC_NUMBER4:n=4;break;

case IDC_NUMBER5:n=5;break;

case IDC_NUMBER6:n=6;break;

case IDC_NUMBER7:n=7;break;

case IDC_NUMBER8:n=8;break;

case IDC_NUMBER9:n=9;break;

case IDC_NUMBER10:n=0;break;

}

if(NumberState==1)

{

m_result=m_result*10+n;

number1=m_result;

UpdateData(FALSE); // 更新编辑框中的值

}

else

{

m_result=m_result*10+n;

number2=m_result;

UpdateData(FALSE);

}

}

void CCalculatorDlg::OnOperationKey(UINT nID)

{

switch(nID)

{

case IDC_NUMBER13: // "/"按钮

OperationState=1;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case IDC_NUMBER14: // "*"按钮

OperationState=2;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case IDC_NUMBER15: // "+"按钮

OperationState=3;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case IDC_NUMBER16: // "-"按钮

OperationState=4;

UpdateData(FALSE);

m_result=0;

NumberState=2;

break;

case IDC_NUMBER17: // "C"按钮,撤消用,不需要可以删除

number1=number2=m_result=0;

UpdateData(FALSE);

NumberState=1;

break;

case IDC_NUMBER20: // "="按钮

cal(); // 调用cal成员函数

break;

}

}

6.为成员函数cal()添加代码

void CCalculatorDlg::cal()

{

switch(OperationState)

{

case 1:

m_result=(double)number1/number2;

UpdateData(FALSE); // 更新编辑框中的结果

number1=m_result; // 把此次的运算结果作为下一次运算的第一个操作数

NumberState=2; // 下次输入的数作为第二个操作数

break;

case 2:

m_result=number1*number2;

UpdateData(FALSE); // 更新编辑框中的结果

number1=m_result;

NumberState=2;

break;

case 3:

m_result=number1+number2;

UpdateData(FALSE); // 更新编辑框中的结果

number1=m_result;

NumberState=2;

break;

case 4:

m_result=number1-number2;

UpdateData(FALSE); // 更新编辑框中的结果

number1=m_result;

NumberState=2;

break;

}

OperationState=0;

}

注意按钮的ID号要和程序中的ID号相同!!!!

VC计算器的源代码

// jisuanqiDlg.cpp : implementation file

//

#include "stdafx.h"

#include "jisuanqi.h"

#include "jisuanqiDlg.h"

#include "math.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog

{

public:

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

// Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

// No message handlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CJisuanqiDlg dialog

CJisuanqiDlg::CJisuanqiDlg(CWnd* pParent )

: CDialog(CJisuanqiDlg::IDD, pParent)

{

//{{AFX_DATA_INIT(CJisuanqiDlg)

m_num = 0.0;

//}}AFX_DATA_INIT

// Note that LoadIcon does not require a subsequent DestroyIcon in Win32

m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);

}

void CJisuanqiDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CJisuanqiDlg)

DDX_Text(pDX, IDC_EDIT1, m_num);

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CJisuanqiDlg, CDialog)

//{{AFX_MSG_MAP(CJisuanqiDlg)

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, OnButton4)

ON_BN_CLICKED(IDC_BUTTON5, OnButton5)

ON_BN_CLICKED(IDC_BUTTON6, OnButton6)

ON_BN_CLICKED(IDC_BUTTON7, OnButton7)

ON_BN_CLICKED(IDC_BUTTON8, OnButton8)

ON_BN_CLICKED(IDC_BUTTON9, OnButton9)

ON_BN_CLICKED(IDC_BUTTON14, OnButton0)

ON_BN_CLICKED(IDC_BUTTON15, OnButtonPoint)

ON_BN_CLICKED(IDC_BUTTON16, OnButtonEqual)

ON_BN_CLICKED(IDC_BUTTON13, OnButtonChu)

ON_BN_CLICKED(IDC_BUTTON12, OnButtonMul)

ON_BN_CLICKED(IDC_BUTTON11, OnButtonSub)

ON_BN_CLICKED(IDC_BUTTON10, OnButtonAdd)

ON_BN_CLICKED(IDC_BUTTON17, OnButtondelet)

ON_BN_CLICKED(IDC_BUTTON18, OnButtonclear)

ON_BN_CLICKED(IDC_BUTTON19, OnButtonkaifang)

ON_BN_CLICKED(IDC_BUTTON20, OnButtonziranduishu)

ON_BN_CLICKED(IDC_BUTTON21, OnButtonchangyongduishu)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CJisuanqiDlg message handlers

BOOL CJisuanqiDlg::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 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);

if (pSysMenu != NULL)

{

CString strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if (!strAboutMenu.IsEmpty())

{

pSysMenu-AppendMenu(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 dialog

SetIcon(m_hIcon, TRUE); // Set big icon

SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

t=true;

j=true;

i=10;

p=0;

q=0;

m_num=0;

m_lnum=0;

return TRUE; // return TRUE unless you set the focus to a control

}

void CJisuanqiDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

if ((nID 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog::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 CJisuanqiDlg::OnPaint()

{

if (IsIconic())

{

CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle

int 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 icon

dc.DrawIcon(x, y, m_hIcon);

}

else

{

CDialog::OnPaint();

}

}

// The system calls this to obtain the cursor to display while the user drags

// the minimized window.

HCURSOR CJisuanqiDlg::OnQueryDragIcon()

{

return (HCURSOR) m_hIcon;

}

void CJisuanqiDlg::OnButton1()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+1;

UpdateData(FALSE);

}

else

{

m_num=m_num+1.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton2()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+2;

UpdateData(FALSE);

}

else

{

m_num=m_num+2.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton3()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+3;

UpdateData(FALSE);

}

else

{

m_num=m_num+3.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton4()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+4;

UpdateData(FALSE);

}

else

{

m_num=m_num+4.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton5()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+5;

UpdateData(FALSE);

}

else

{

m_num=m_num+5.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton6()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+6;

UpdateData(FALSE);

}

else

{

m_num=m_num+6.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton7()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+7;

UpdateData(FALSE);

}

else

{

m_num=m_num+7.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton8()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+8;

UpdateData(FALSE);

}

else

{

m_num=m_num+8.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton9()

{

// TODO: Add your control notification handler code here

if(t)

{

m_num=m_num*10+9;

UpdateData(FALSE);

}

else

{

m_num=m_num+9.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButton0()

{

// TODO: Add your control notification handler code here

//UpdateData();

if(t)

{

m_num=m_num*10+0;

UpdateData(FALSE);

}

else

{

m_num=m_num+0.0/i;

i*=10;

UpdateData(FALSE);

}

}

void CJisuanqiDlg::OnButtonPoint()

{

// TODO: Add your control notification handler code here

int i=10;

t=false;

}

void CJisuanqiDlg::OnButtonEqual()

{

// TODO: Add your control notification handler code here

switch(r)

{

case '+':

{

m_num=m_num+m_lnum;

UpdateData(FALSE);

break;

}

case '-':

{

m_num=m_snum-m_num;

UpdateData(FALSE);

break;

}

case '*':

{

m_num=m_mnum*m_num;

UpdateData(FALSE);

break;

}

case '/':

{

if(m_num==0)

{

MessageBox("除数不能是0!");

}

else

{

m_num=m_cnum/m_num;

UpdateData(FALSE);

break;

}

}

}

t=true;

}

void CJisuanqiDlg::OnButtonMul()

{

// TODO: Add your control notification handler code here

r='*';

t=true;

m_mnum=m_num;

m_num=0;

UpdateData(FALSE);

}

void CJisuanqiDlg::OnButtonChu()

{

// TODO: Add your control notification handler code here

r='/';

t=true;

i=10;

m_cnum=m_num;

m_num=0;

UpdateData(FALSE);

}

void CJisuanqiDlg::OnButtonSub()

{

// TODO: Add your control notification handler code here

r='-';

i=10;

t=true;

if(j)

{

m_snum=m_num;

}

else

{

p=0;

adda[p]=m_num;

p++;

for(q=0;q=p;q++)

{

m_lnum=m_lnum+adda[q];

q++;

}

m_num=m_lnum;

UpdateData(FALSE);

m_num=0;

m_snum=m_lnum;

}

m_num=0;

}

void CJisuanqiDlg::OnButtonAdd()

{

// TODO: Add your control notification handler code here

r='+';

t=true;

j=false;

i=10;

p=0;

adda[p]=m_num;

p++;

for(q=0;q=p;q++)

{

m_lnum=m_lnum+adda[q];

q++;

}

m_num=m_lnum;

UpdateData(FALSE);

m_num=0;

}

void CJisuanqiDlg::OnButtondelet()

{

// TODO: Add your control notification handler code here

int p;

p=m_num/10;

m_num=p;

UpdateData(FALSE);

}

void CJisuanqiDlg::OnButtonclear()

{

// TODO: Add your control notification handler code here

t=true;

i=10;

j=true;

m_num=0;

m_lnum=0;

UpdateData(FALSE);

}

void CJisuanqiDlg::OnButtonkaifang()

{

// TODO: Add your control notification handler code here

m_num=sqrt(m_num);

UpdateData(FALSE);

}

void CJisuanqiDlg::OnButtonziranduishu()

{

// TODO: Add your control notification handler code here

m_num=log(m_num);

UpdateData(FALSE);

}

void CJisuanqiDlg::OnButtonchangyongduishu()

{

// TODO: Add your control notification handler code here

m_num=log10(m_num);

UpdateData(FALSE);

}

发表评论

评论列表

  • 囤梦雾敛(2022-06-10 04:43:27)回复取消回复

    ion handler code here m_num=log10(m_num); UpdateData(FALSE);}

  • 边侣庸颜(2022-06-10 06:27:27)回复取消回复

    GetClientRect(rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon +

  • 颜于里赴(2022-06-10 06:10:03)回复取消回复

    UpdateData(FALSE); m_fNumber1 = f; m_fNumber2 = 0.0f; m_iSign = 5; }求用MFC编写的计算器的源代码,请发到我邮箱heya

  • 依疚路岷(2022-06-09 22:12:48)回复取消回复

    , OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(I

  • 蓝殇迟山(2022-06-10 02:18:48)回复取消回复

    IDC_NUMBER15: // "+"按钮 OperationState=3; UpdateData(FALSE); m_result=0; NumberState=2; break; case IDC_NUMBER16: