📄 计算器dlg.cpp
字号:
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=log(operate);
display="ln("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtonlg()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=log10(amount);
display="lg"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=log10(operate);
display="lg("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtoncot()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=1/tan(amount);
display="Cot"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=1/tan(operate);
display="Cot("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtontan()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=tan(amount);
display="Tan"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=tan(operate);
display="Tan("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtoncos()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=cos(amount);
display="Cos"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=cos(operate);
display="Cos("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtonsin()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=sin(amount);
display="Sin"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=sin(operate);
display="Sin("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtonarcsin()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=asin(amount);
display="arcSin"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=asin(operate);
display="arcSin("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtonarccos()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=acos(amount);
display="arcCos"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=acos(operate);
display="arcCos("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtonarctan()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=atan(amount);
display="arcTan"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=atan(operate);
display="arcTan("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtonarccot()
{
// TODO: 在此添加控件通知处理程序代码
if(stack2.empty()==true)
haveparent=true;
if(haveparent==true&&stack2.empty()==true)
{
answer=3.1415926/2-atan(amount);
display="arcCot"+display;
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
else
{
if(symbol!='(')
stack2.push(amount);
do{
stack1.get_top(symbol);
stack1.pop();
stack2.get_top(operate1);
stack2.pop();
stack2.get_top(operate2);
stack2.pop();
if(symbol=='+') operate=operate2+operate1;
if(symbol=='-') operate=operate2-operate1;
else if(symbol=='*') operate=operate2*operate1;
else if(symbol=='/') operate=operate2/operate1;
stack2.push(operate);
}while(symbol!='#');
answer=3,1415926/2-atan(operate);
display="arcCot("+display+")";
GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATICB)->ShowWindow(SW_SHOW);
amount=answer;
stack1.push('#');
haveparent=true;
}
UpdateData(FALSE);
}
void CMyDlg::OnBnClickedButtonpi()
{
// TODO: 在此添加控件通知处理程序代码
display=display+"∏";
UpdateData(FALSE);
n=1;
amount=3.14159265;
}
void CMyDlg::OnBnClickedButtonbackspace()
{
// TODO: 在此添加控件通知处理程序代码
CString string = display.Right(1);
if(string!="0"&&string!="1"&&string!="2"&&string!="3"&&string!="4"&&string!="5"&&string!="6"&&string!="7"&&string!="8"&&string!="9"&&string!=".")
{
AfxMessageBox("不能删除运算符!");
return;
}
display=display.Left(display.GetLength()-1);
UpdateData(FALSE);
if(string==".")
{
dot=0;
return;
}
if(dot==0)
amount=static_cast<int>(amount/10);
else if(dot!=0)
{
n=1;
for(int i=0;i<dot-1;i++)
n=n*10;
amount=static((static_cast<int>(amount*n))/10)/(n/10);
dot--;
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -