/ * Function: Calculate expressions containing variables and functions
2> A expression constraint between variables
Instructions for use:
1> The function used by the user is Bool CEXPIRESSION :: Calexp ()
Double m_dresult;
File: / / Calculated
CHAR * m_STREXP;
File: // Expression string
Cvarlist m_varlist;
File: // Variable Table
Bool m_bdegunit; // Using angle units
Cvar var1
Error returning false,
2> Users responsible for initialization variables before using this function
For example, the user has variables a = 10, b = 2, c = 20. where c = a * b;
The user does the following work:
Cvar * pvar;
PVAR = New CVAR;
Pvar-> m_dvalue = 10;
Pvar-> m_strname = "a";
CEXPRESSION EXP1;
Exp1.m_varlist.addvar (PVAR);
PVAR = New CVAR;
Pvar-> m_dvalue = 20;
Pvar-> m_strname = "b";
Exp1.m_varlist.addvar (PVAR);
PVAR = New CVAR;
Pvar-> m_dvalue = 0;
Pvar-> m_strname = "c";
Pvar-> m_strslave = "a * b";
Exp1.m_varlist.addvar (PVAR);
Exp1.m_strexp = "a * b c";
Exp1.calexp ();
Calculate the left value of the expression. *
3> The position of the other variable constraints should be placed after the correlation variable in the variable table. * /
// Expression.h: interface for the CEXPRESSION CLASS.
//
//
#if! defined (AFX_EXPIRESSION_H__2578E33F_FF86_4384_A7CE_A401BAC5A010__INCLUDED_)
#define afx_expression_h__2578E33F_FF86_4384_A7CE_A401BAC5A010__INCLUDED_
#iF _MSC_VER> 1000
#pragma overce
#ENDIF / / 100 m _ _ _
#include
#include
Using namespace std;
#define delimiter 1 // Derivator
#define variable 2 // variable
#define Number 3 // Value
#define function 4 // function
#define pi 3.1415926535898
Class CVAR / / Table Structure for Storage Variables and Variables
{
PUBLIC:
CHAR M_CFLAG; / / equal to 0 is temporary variable, otherwise equal to 1
String m_strname; // Variable name, variable A
String m_strslave; // constraint expression, such as A = B 2
Double m_dvalue; // variable value such as 10, Table A = 10
PUBLIC:
CVAR ();
Virtual ~ cvar ();
Voidin ();
}
Class Cvarlist
{
PUBLIC:
List
Cvarlist ();
Virtual ~ cvarlist (); bool addvar;
}
Class Cexpression
{
PUBLIC:
Double m_dresult;
CHAR * m_STREXP;
Cvarlist m_varlist;
Bool m_bdegunit; // Using angle units
protected:
INT m_ierrflag; // Tag expression calculation is wrong 0: Normal, 1: Expression empty 2: illegal variables or functions 3: Brand does not match
INT m_ifunflag; // Tags the current is performing function parameter calculation.
INT m_imatchflag; / / mark whether parentheses match
CHAR M_CTOKENTYPE; / / Type, such as tandes, variables, etc.
Char M_STRTOKEN [80];
PUBLIC:
Void Message (const char * strmsg);
CEXPRESSION ();
Virtual ~ CEXPRESSION ();
Bool Calexp ();
Bool UpdateslaveVar ();
protected:
Bool gettoken ();
Void error ();
Bool Isdelim (Char C);
Bool isfunc (const char * fname);
Bool Iswhite (Char C);
Bool isinstr (char ch, char * s);
Bool Level1 (Double * Result);
Bool Level2 (Double * Result);
Bool Level3 (Double * Result);
Bool Level4 (Double * Result);
Bool Level5 (Double * Result);
Bool Level6 (Double * Result);
Bool Level7 (Double * Result);
Bool getFunIndex (const char * name, int * index);
Void Putback ();
Void Unary (Char O, Double * R);
Bool Arith (Char O, Double * R, Double * H);
Bool Primitive (Double * Result);
Bool getVarvalue (const char * n, double * result);
Bool getvarindex (const char * name, int * index);
}
#endif //! defined (AFX_EXPRESSION_H__2578E33F_FF86_4384_A7CE_A401BAC5A010__INCLUDED_)