CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> Visual C++ / C++ >> Miscellaneous >> Miscellaneous >> Math


Simple Numerical Formula Parser
Rating: none

Ralf Wirtz (view profile)
April 5, 2000


(continued)



Environment: VC6 SP3, Windows 95/98/NT/2000

The class CFormulaParser encapsulates a very useful mathematical parser for analytic/numerical formula transformation.

The formula dialog above is actually not necessary for the functionality but allows you comfortable to put in a formula string.

Hereby an extract from the header file:

class CFormulaParser
{
private:
 //Implementation
 CString m_strFormula;
 CString m_strFunction;
 CString m_strErrortext;
 double m_dFktValue;
 double m_dFunctionConstant[ANZFUNKTKONST];
 CStringArray m_strStandardFunction;

 double SignFactor(WORD& nPosition, CString& strCharacter);
 double Expression(WORD& nPosition, CString& strCharacter);

 double SimpleExpression(WORD& nPosition,
                         CString& strCharacter);

 double Term(WORD& nPosition, CString& strCharacter);
 double Factor(WORD& nPosition, CString& strCharacter);
 double Char_n(WORD& nPosition, CString& strCharacter);

public:
 CString GetFormula();
 void SetFormula(CString Formula);
 void SetFunctConst(int index, double val);

 CFormulaParser();
 virtual ~CFormulaParser();

//Interface
 double Calculation(CString strFormula,
                    double xValue,
                    WORD&
                    ErrorPosition,
                    CString&
                    Errortext);
};
The main method in CFormulaParser for the evaluation is:
double Calculation(CString strFormula,
                   double xValue,
                   WORD&
                   ErrorPosition,
                   CString&
                   Errortext);
where
  • strFormula is the formula string, e.g. "b*sin(x)/x"
  • xValue is in this case x, e.g. 3.14 (point instead comma!)
  • ErrorPosition gives back the error position in the string
  • Errortext gives back the corresponding error text
The parser is part of the program SimplexNumerica. For more information, please see my German website
http://www.SimplexNumerica.de.

Download

Download demo project (with source) - 104 Kb

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Hmm - NN_PP (10/13/2004)
Nice, but minor mistakes. - Legacy CodeGuru (09/03/2003)
Added function to check parenthesys - Legacy CodeGuru (01/07/2003)
Nice work: Fix for text insertion - Legacy CodeGuru (12/24/2002)
Good work! Only some minor problems fixed. - Legacy CodeGuru (12/05/2002)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES