// ComputerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Computer.h"
#include"iostream"
#include"string"
#include "ComputerDlg.h"
#include"malloc.h"
#include"stdlib.h"
#define MAXSIZE 50 //表达式的长度
using namespace std;
#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()
/
// CComputerDlg dialog
CComputerDlg::CComputerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CComputerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CComputerDlg)
m_String1 = _T("");
m_String2 = _T("");
m_String3 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CComputerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CComputerDlg)
DDX_Text(pDX, IDC_EDITexpression, m_String1);
DDX_Text(pDX, IDC_EDITqianzhui, m_String2);
DDX_Text(pDX, IDC_EDIThouzhui, m_String3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CComputerDlg, CDialog)
//{{AFX_MSG_MAP(CComputerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTONChar0, OnBUTTONChar0)
ON_BN_CLICKED(IDC_BUTTONChar1, OnBUTTONChar1)
ON_BN_CLICKED(IDC_BUTTONChar2, OnBUTTONChar2)
ON_BN_CLICKED(IDC_BUTTONChar3, OnBUTTONChar3)
ON_BN_CLICKED(IDC_BUTTONChar4, OnBUTTONChar4)
ON_BN_CLICKED(IDC_BUTTONChar5, OnBUTTONChar5)
ON_BN_CLICKED(IDC_BUTTONChar6, OnBUTTONChar6)
ON_BN_CLICKED(IDC_BUTTONChar7, OnBUTTONChar7)
ON_BN_CLICKED(IDC_BUTTONChar8, OnBUTTONChar8)
ON_BN_CLICKED(IDC_BUTTONChar9, OnBUTTONChar9)
ON_BN_CLICKED(IDC_BUTTONCharA, OnBUTTONCharA)
ON_BN_CLICKED(IDC_BUTTONCharB, OnBUTTONCharB)
ON_BN_CLICKED(IDC_BUTTONCharC, OnBUTTONCharC)
ON_BN_CLICKED(IDC_BUTTONCharD, OnBUTTONCharD)
ON_BN_CLICKED(IDC_BUTTONCharE, OnBUTTONCharE)
ON_BN_CLICKED(IDC_BUTTONCharF, OnBUTTONCharF)
ON_BN_CLICKED(IDC_BUTTONComputeExpression, OnBUTTONComputeExpression)
ON_BN_CLICKED(IDC_BUTTONCharG, OnBUTTONCharG)
ON_BN_CLICKED(IDC_BUTTONCharH, OnBUTTONCharH)
ON_BN_CLICKED(IDC_BUTTON3, OnButtonInfix)
ON_BN_CLICKED(IDC_BUTTON1, OnButtonPostfix)
ON_BN_CLICKED(IDC_BUTTONCharF2, OnBUTTONSin)
ON_BN_CLICKED(IDC_BUTTONCharF3, OnBUTTONCharCos)
ON_BN_CLICKED(IDC_BUTTONCharF4, OnBUTTONCharTan)
ON_BN_CLICKED(IDC_BUTTONCharF5, OnBUTTONCharSin_1)
ON_BN_CLICKED(IDC_BUTTONCharF6, OnBUTTONCharLog)
ON_BN_CLICKED(IDC_BUTTONCharF7, OnBUTTONCharSqrt)
ON_BN_CLICKED(IDC_BUTTONCharF8, OnBUTTONCharPow)
ON_BN_CLICKED(IDC_BUTTONCharF9, OnBUTTONCharEXP)
ON_BN_CLICKED(IDC_BUTTONCharF10, OnBUTTONCharSinh)
ON_BN_CLICKED(IDC_BUTTONCharF11, OnBUTTONCharCosh)
ON_BN_CLICKED(IDC_BUTTONCharF12, OnBUTTONCharTanh)
ON_BN_CLICKED(IDC_BUTTONCharF13, OnBUTTONCharLog10)
ON_BN_CLICKED(IDC_BUTTONCharF14, OnBUTTONCharPI)
ON_BN_CLICKED(IDC_BUTTONCharF15, OnBUTTONCharFactorial)
ON_BN_CLICKED(IDC_BUTTONComputeExpression2, OnBUTTONComputeClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CComputerDlg message handlers
BOOL CComputerDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CComputerDlg::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 CComputerDlg::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 CComputerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//以下部分从窗口获得求值表达式;
void CComputerDlg::OnBUTTONChar0()
{ UpdateData(true);
m_String1= m_String1+'0';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar1()
{
UpdateData(true);
m_String1= m_String1+'1';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar2()
{
UpdateData(true);
m_String1= m_String1+'2';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar3()
{
UpdateData(true);
m_String1= m_String1+'3';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar4()
{
UpdateData(true);
m_String1= m_String1+'4';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar5()
{
UpdateData(true);
m_String1= m_String1+'5';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar6()
{
UpdateData(true);
m_String1= m_String1+'6';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar7()
{
UpdateData(true);
m_String1= m_String1+'7';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar8()
{
UpdateData(true);
m_String1= m_String1+'8';
UpdateData(false);
}
void CComputerDlg::OnBUTTONChar9()
{
UpdateData(true);
m_String1= m_String1+'9';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharA()
{
UpdateData(true);
m_String1= m_String1+'(';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharB()
{
UpdateData(true);
m_String1= m_String1+')';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharC()
{
UpdateData(true);
m_String1= m_String1+'+';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharD()
{
UpdateData(true);
m_String1= m_String1+'-';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharE()
{
UpdateData(true);
m_String1= m_String1+'*';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharF()
{
UpdateData(true);
m_String1= m_String1+'/';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharG()
{
UpdateData(true);
m_String1= m_String1+'-';
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharH()
{
UpdateData(true);
m_String1= m_String1+'.';
UpdateData(false);
}
//功能:对输入的表达式的合法性进行检查;
//调用方式:P.testString();
//入口参数:m_String1;
void CComputerDlg::testString()
{
int i=0;
UpdateData(true);
while(i<m_String1.GetLength())
{
if(m_String1[i]<'%'||m_String1[i]>'9')
{
MessageBox("您输入的表达式中有错误的字符!请检查后重新输入!");
return;
}
else {
switch(m_String1[i])
{
case 39:
case '&':
MessageBox("您输入的表达式中有错误的字符!请检查后重新输入!");
return;
default:i++;break;
}
}
}
}
//功能:将m_String1中的字符串类型的表达式进行切分,
//并且将结果保存在stack1这个结构数组之中,
//stack1种的节点如果操作符为'!',则为数字节点;
void CComputerDlg::createLine( )
{ int i=0,j=0,k=0;
char temp[MAXSIZE][MAXSIZE],ph; //将操作符和数字存放在stack1中
EXP p;
top1=0;
m_String1+='=';
while(j<(m_String1.GetLength()-1))
{
ph=m_String1[j];
if(m_String1[j]<48&&m_String1[j]!='.') //m_String1[j]是操作符
{
if(m_String1[j]=='-'&&j==0) //如果是开头是负号
{
if(m_String1[j+1]=='(') //接下来的是括号
{
p.opr=0;
p.opt='!'; //0减去正数就可以将正数转化为负数
stack1[top1++]=p; //在表达式的最前面加上0,
p.opt='-';
stack1[top1++]=p;
}
else temp[k][i++]='-';
}
else if(m_String1[j]=='('&&m_String1[j+1]=='-')
{
p.opt=m_String1[j++];//如果遇到的‘(’后面是负号,将其后数字作负数处理;
stack1[top1++]=p;
temp[k][i++]='-';
}
else
{
p.opt=m_String1[j];
stack1[top1++]=p;
}
j++;
}
else
{
temp[k][i++]=m_String1[j++];
if((m_String1[j]<48&&m_String1[j]!='.')||j==(m_String1.GetLength()-1))
{ //下一个字符是操作符
if(i>0)
{
p.opr=atof(temp[k++]); //将切分后的数字子串转化为double类型的数字;
p.opt='!'; //设置数字标记
stack1[top1++]=p;
i=0; //temp复位;
}
}
}
}
stack1[top1].opt='#'; //在结尾添加结束标记
m_String1.Delete(m_String1.GetLength()-1,1);
}
//利用堆栈计算表达式的值调用方式,P.getValue();
//传入参数为全局变量stack1这个结构数组,
//计算的结果存放在OPND[0]中,里面存放的
//是已经经过转化的数字和操作符
void CComputerDlg::getValue(){
int D=-1 ,R=0,tp=0;
double a,b;
char optr1,optr2;
double OPND[25];
char OPTR[25];
EXP temp;
temp=stack1[tp++];
OPTR[R]='#';//在操作符堆栈中设置歧视标志;
while(tp<top1||OPTR[R]!='#')
{
if(temp.opt=='!')//是数字节点;
{
OPND[++D]=temp.opr;
temp=stack1[tp++];
}
else{
optr1=OPTR[R];//获取操作符堆栈中的顶端操作符
optr2=temp.opt;//从stack1中读取的操作符
switch(optr1)
{
case '+':
case '-':switch(optr2)
{
case '*':
case '/'://当当前操作符的优先级高,就把当前操作符入栈
case '(':OPTR[++R]=optr2;
temp=stack1[tp++];
break;
case '+':
case '-':b=OPND[D--];a=OPND[D--];
//当前节点的优先级低或和栈顶的操作符
//优先级相等就计算栈顶的操作符
if(optr1=='+')
a=a+b;
else a=a-b;
OPND[++D]=a;
OPTR[R]=optr2;
temp=stack1[tp++];
break;
case '#':
case ')':b=OPND[D--];a=OPND[D--];
if(optr1=='+')
a=a+b;
else a=a-b;
OPND[++D]=a;
R--;
break;
default:MessageBox("表达式输入有错误!");return;
}
break;
case'*':
case'/':switch(optr2)
{
case '(': OPTR[++R]=optr2;
temp=stack1[tp++];
break;
case '+':
case '-':
case '*':
case '/': b=OPND[D--];a=OPND[D--];
if(optr1=='*')
a=a*b;
else a=a/b;
OPND[++D]=a;
OPTR[R]=optr2;
if(R==2)
R--;
else
temp=stack1[tp++];
break;
case '#':
case ')': b=OPND[D--];a=OPND[D--];
if(optr1=='*')
a=a*b;
else a=a/b;
OPND[++D]=a;
R--;
break;
default:MessageBox("表达式输入有错误!");return;
}
break;
case '#':OPTR[++R]=optr2;
temp=stack1[tp++];
break;
case'(':if(optr2==')')
R--;//脱掉括号
else
{
OPTR[++R]=optr2; //遇到'('就入栈;
}
temp=stack1[tp++];
break;
default:MessageBox("表达式输入有错误!");return;
}
}
}
result=OPND[0];//计算结果保存在result中;
}
//功能:将double类型数据转化成字符串
//入口参数:double b
//出口参数:CString str
CString CComputerDlg::doubleToString(double b)
{
double a=b;
int j=0,k=0,m=0,t,n;
int i=sizeof(double);
CString str;
if(a<0){str+='-';a=fabs(a);}
if(a<1)str+='0';
while(a>=1)
{ a=a/10;
j++;/*计算整数位的位数?*/
}
n=j;
a=fabs(b);
for( ;j>0;j--)
{ m=pow(10,j-1);
t=a/m;
a=a-t*m;
str+=t+48;//将数字转化为字符存到str中;
}
str+='.';//加上小数点;
if(a==0)str+='0';
while(a!=0&&(k+n)<15)
{
t=a*10;
a=a*10;
str+=t+48;
a=a-t;
k++;
}
return(str);
}
//功能:根据stack1中存放的操作符信息和操作书信息
//建立求值树,树的叶子节点为操作数,非叶节点为操作符
//入口参数:结构数组stack1
//出口参数:Bolanshi*pnow;
//实现思路:如果当前要插入的节点为操作数节点的话,将其
//插入作为前节点的叶子节点,如果插入节点为操作符,比较
//它和pnow的优先级,如果优先级大于pnow,则将其插入作为
//pnow的叶子节点,并且把pnow原来的叶子节点作为其左孩子
//节点,如果优先级小于或等于pnow的优先级,则将其pnow作
//为其左孩子,并将pnow移到该节点,遇到'(',就采用递归方
//式建立子树,遇到')'就返回;建立的树中不包含括号;
struct CComputerDlg::Bolanshi * CComputerDlg::PolandTree()
{
Bnode* p;
int flag=0;
Bnode*pnow=new(Bnode);
pnow->lchild=pnow->rchild=NULL;
char optr1,optr2;
while(stack1[top1].opt!='#')
{
p=new(Bnode);
p->lchild=p->rchild=NULL;
p->data=stack1[top1].opr;
p->operate=stack1[top1].opt;
top1++;
if(p->operate=='!')//P为操作数节点;
{
if(pnow->lchild==NULL) //左孩子为空
{
pnow->lchild=p;
continue;
}
if(pnow->rchild==NULL) //右孩子为空;
{
pnow->rchild=p;
continue;
}
else pnow->rchild->rchild=p;//左右孩子都不为空;
}
else
{
optr1=pnow->operate;
optr2=p->operate;
switch(optr1)
{
case'+':
case'-':switch(optr2)
{
case'+':
case'-':p->lchild=pnow;
pnow=p;
break;
case'*':
case'/':if(flag=1&&top1==2)
{
p->lchild=pnow;
pnow=p;
flag=0;
}
else
{
p->lchild=pnow->rchild;
pnow->rchild=p;
}
break;
case'(':flag=1;
if(pnow->lchild==NULL)
pnow->lchild=PolandTree();
if(pnow->lchild!=NULL&&pnow->rchild==NULL)
pnow->rchild=PolandTree();
break;
case')':return(pnow);
default:MessageBox("表达式中有错误!");return(pnow);
}
break;
case'*':
case'/':switch(optr2)
{
case'+':
case'-':
case'*':
case'/':p->lchild=pnow;
pnow=p;
break;
case'(':p=PolandTree();
p->lchild=pnow->rchild;
pnow->rchild=p;
break;
case')':return(pnow);
}
break;
case'!':p->lchild=pnow;pnow=p;break;
case'(': flag=1;
if(pnow->lchild==NULL)
pnow->lchild=PolandTree();
if(pnow->lchild!=NULL&&pnow->rchild==NULL)
pnow->rchild=PolandTree();
break;
case')':return(pnow);
default:if(p->operate=='(')
{
pnow=PolandTree();
}
else pnow->operate=p->operate;
break;
}//end of switch(1)
}//end of else
}//end of while
return(pnow);
}
// 功能: 递归方式前序遍历二叉树
//入口参数: Bnode*root
//出口参数: str
void CComputerDlg::Prefix(Bnode*root)
{
CString str;
if (root)
{
if(root->operate=='!')
{
str=doubleToString(root->data);
m_String2+=str;
m_String2+=' ';
}
else
{
m_String2+=root->operate;
m_String2+=' ';
}
if(root->lchild)Prefix(root->lchild);//递归遍历左子树
if(root->rchild)Prefix(root->rchild);//递归遍历右子树
}
}
// 功能: 递归方式后序遍历二叉树
//入口参数: Bnode*root
//出口参数: str
void CComputerDlg::Postfix(Bnode *root)
{
CString str;
if (root)
{
if(root->lchild)Postfix(root->lchild);//递归遍历左子树
if(root->rchild)Postfix(root->rchild);//递归遍历右子树
if(root->operate=='!')
{
str=doubleToString(root->data);
m_String3+=str;
m_String3+=' ';
}
else
{
m_String3+=root->operate;
m_String3+=' ';
}
}
}
void CComputerDlg::OnBUTTONComputeExpression()
{
CString str;
testString();
createLine();
getValue();
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
str=doubleToString(result);
m_String1+='=';
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnButtonInfix()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
Bnode*root=new(Bnode);
testString();
createLine();
top1=0;
root=PolandTree();
Prefix(root);
UpdateData(false);
}
void CComputerDlg::OnButtonPostfix()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
Bnode*root=new(Bnode);
testString();
createLine();
top1=0;
root=PolandTree();
Postfix(root);
UpdateData(false);
}
void CComputerDlg::OnBUTTONSin()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
a=sin(a);
m_String1+=" sin()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharCos()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
a=cos(a);
m_String1+=" cos()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharTan()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
a=tan(a);
m_String1+=" tan()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharSin_1()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
if(a<(-3.14159265338327/2)||a>(3.14159265338327/2))
{
MessageBox("参数超出可计算范围!请确认输入是否正确!");
return;
}
a=asin(a);
m_String1+=" sin-1()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharLog()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
if(a<=0)
{
MessageBox("参数只能是正数,请确认输入是否正确!");
return;
}
a=log(a);
m_String1+=" log()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharSqrt()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
if(a<0)
{
MessageBox("参数不能是负数,请确认输入是否正确!");
return;
}
a=sqrt(a);
m_String1+=" sqrt()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharPow()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a,b;
char temp[2][20];
CString str;
int i=0;
for(;m_String1[i]!=',';i++)
{
temp[0][i]=m_String1[i];
}
i++;
for(int j=0; (i+j)<m_String1.GetLength();j++)
{
temp[1][j]=m_String1[i+j];
}
a=atof(temp[0]);
b=atof(temp[1]);
a=pow(a,b);
m_String1+=" pow()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharEXP()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
a=exp(a);
m_String1+=" EXP()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharSinh()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
a=sinh(a);
m_String1+=" sinh()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharCosh()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
a=cosh(a);
m_String1+=" cosh()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharTanh()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
a=tanh(a);
m_String1+=" tanh()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharLog10()
{
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
double a;
CString str;
a=atof(m_String1);
if(a<=0)
{
MessageBox("参数只能是正数,请确认输入是否正确!");
return;
}
a=log10(a);
m_String1+=" log10()=";
str=doubleToString(a);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharPI()
{
UpdateData(true);
double PI=3.14159265338327;
CString str;
str=doubleToString(PI);
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONCharFactorial()
{
long a,value=1;
CString str;
UpdateData(true);
if(m_String1.GetLength()==0)
{
MessageBox("你还没有输入参数!");
return;
}
a=atof(m_String1);
for(int i=1;i<=a;i++)
value*=i;
str=doubleToString(value);
m_String1+="!=";
m_String1+=str;
UpdateData(false);
}
void CComputerDlg::OnBUTTONComputeClear()
{
m_String1.Empty();
m_String2.Empty();
m_String3.Empty();
UpdateData(false);
}