跪求MFC写的计算器 作业用
发布网友
发布时间:2024-09-29 09:47
我来回答
共2个回答
热心网友
时间:2024-09-29 11:52
1.定义一个BOOL成员来处理
显示第一个数
或者运算符按下后的数
2.
显示的按键结果的话
就是
m_result=m_result*10+按键
热心网友
时间:2024-09-29 11:57
void CCalculatorDlg::OnButton0()
{
// TODO: Add your control notification handler code here
m_strShow+='0';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_strShow+='1';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton2()
{
// TODO: Add your control notification handler code here
m_strShow+='2';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton3()
{
// TODO: Add your control notification handler code here
m_strShow+='3';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton4()
{
// TODO: Add your control notification handler code here
m_strShow+='4';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton5()
{
// TODO: Add your control notification handler code here
m_strShow+='5';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton6()
{
// TODO: Add your control notification handler code here
m_strShow+='6';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton7()
{
// TODO: Add your control notification handler code here
m_strShow+='7';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton8()
{
// TODO: Add your control notification handler code here
m_strShow+='8';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButton9()
{
// TODO: Add your control notification handler code here
m_strShow+='9';
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strShow);
}
void CCalculatorDlg::OnButtonJia()
{
// TODO: Add your control notification handler code here
m_nType=1;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonEnd()
{
// TODO: Add your control notification handler code here
m_number2=atoi(m_strShow);
//m_number2=m_number2.parseDouble(m_strShow);
switch(m_nType)
{
case 1:
m_show=m_number1+m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 2:
m_show=m_number1-m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 3:
m_show=m_number1*m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
case 4:
m_show=m_number1/m_number2;
SetDlgItemInt(IDC_EDIT1,m_show);
m_strShow="";
break;
}
}
void CCalculatorDlg::OnButtonC()
{
// TODO: Add your control notification handler code here
m_strShow="";
SetDlgItemInt(IDC_EDIT1,0);
}
void CCalculatorDlg::OnButtonJian()
{
// TODO: Add your control notification handler code here
m_nType=2;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonCheng()
{
// TODO: Add your control notification handler code here
m_nType=3;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonChu()
{
// TODO: Add your control notification handler code here
m_nType=4;
m_number1=atoi(m_strShow);
m_strShow.Empty();
}
void CCalculatorDlg::OnButtonBack()
{
// TODO: Add your control notification handler code here
m_strShow=m_strShow.Left(m_strShow.GetLength()-1);
//MessageBox(m_strShow);
SetDlgItemText(IDC_EDIT1,m_strShow);
// UpdateData(FALSE);
}
void CCalculatorDlg::OnButtonZf()
{
// TODO: Add your control notification handler code here
m_strShow.Insert(0,"-");
SetDlgItemText(IDC_EDIT1,m_strShow);
}
void CCalculatorDlg::OnButtonSqrt()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_EDIT1)->GetWindowText(m_strShow);
m_dbShow=atof(m_strShow);
m_dbShow=sqrt(m_dbShow);
static char ch[10]="";
sprintf(ch,"%lf",m_dbShow);
SetDlgItemText(IDC_EDIT1,ch);
}
void CCalculatorDlg::OnButtonFen()
{
// TODO: Add your control notification handler code here
// static double dou=m_strShow.Format("%lf",m_strShow);
GetDlgItem(IDC_EDIT1)->GetWindowText(m_strShow);
m_dbShow=atof(m_strShow);
m_dbShow=1/m_dbShow;
static char ch[10]="";
sprintf(ch,"%lf",m_dbShow);
SetDlgItemText(IDC_EDIT1,ch);
m_strShow.Empty();
sprintf(ch,"%d",0);
}