?? calc.cpp
字號:
// Calc.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "Calc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <math.h>
#define N 20
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
extern "C" __declspec(dllexport) double Calc(const char exp[])
{
char ch;
//cout<<exp<<endl;
int add(2),sub(3),mul(4),div(5),op[20],nc(0),oc(0);
double num[N],rel(0);
for(int j=0;j<N;j++)
num[j]=op[j]=0;
j=0;
int len=strlen(exp),i=-1;
while(++i<len)
{
ch=*(exp+i);
if(ch>='0' &&ch<='9' || ch=='+' || ch=='-' || ch=='*' ||ch=='/' ||ch=='(' ||ch==')')
continue;
else
return -99999999.99999;
}
//cout<<strlen(exp)<<endl;
for(i=0;i<strlen(exp);i++)
{
if(exp[i]<58 && exp[i]>47)
{
num[nc]=num[nc]*10+int(exp[i])-48;
//cout<<num[nc]<<' ';
}
else
{
//cout<<exp[i]<<' ';
switch(exp[i])
{
case '+':
op[oc++]=add;
break;
case'-':
op[oc++]=sub;
break;
case'*':
op[oc++]=mul;
break;
case'/':
op[oc++]=div;
break;
case'(':
add+=10;
sub+=10;
mul+=10;
div+=10;
break;
case')':
add-=10;
sub-=10;
mul-=10;
div-=10;
break;
}
//cout<<op[oc-1]<<" ";
}
if(oc>nc)
{
if(op[oc]%10==2){
op[oc--]=0;
break; }
if(op[oc]%10==3)
num[nc]=0;//"-x" => "0-x"
nc++;
}
}
for(int w=0;w<20;w++)
{
j=0;
if(op[0]==0)
break;
int temp=op[0]/2;
for(int i=0;i<20;i++)
if(op[i]/2>temp)
{
j=i;
temp=op[i]/2;
}
switch(op[j]%10)
{
case 2:
rel=num[j]+num[j+1];
break;
case 3:
rel=num[j]-num[j+1];
break;
case 4:
rel=num[j]*num[j+1];
break;
case 5:
rel=num[j]/num[j+1];
break;
}
temp=j;
for(j;j<19;j++)
{
op[j]=op[j+1];
num[j]=num[j+1];
}
num[temp]=rel;
}
// cout<<"The result is "<<num[0]<<endl;
return num[0];
}
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CCalcApp
BEGIN_MESSAGE_MAP(CCalcApp, CWinApp)
//{{AFX_MSG_MAP(CCalcApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalcApp construction
CCalcApp::CCalcApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCalcApp object
CCalcApp theApp;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -