1 Replies - 2893 Views - Last Post: 27 April 2009 - 06:22 AM Rate Topic: -----

#1 santa2832  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-April 09

how to convert prefix expression algorithm to a c++ program?

Posted 27 April 2009 - 05:41 AM

Im having trouble converting my prefix expression algorithm to a C++ program. My program ask for a user to enter an operator and some integers in prefix form and my program willevaluate it. We also had to do the postexpression I was able to do this but it seems more difficult with the prefix to me. I will be grateful with any help here the algorithm i have.


evaluatePrefix(inout strExp:string): float

// evaluates a prefix expression strExp
// precondition: strExp is a string containing a valid
// prefix expression with no blanks.
// postcondition: returns the value of the prefix expressions. The input is destroyed.

ch = first chracter of strExp

Delete the first character from strExp

if (ch is an identifier)

// base case - single identifier

return value of the identifier

else if (ch is an operator named op)
{
operand1 = evaluatePrefix(strExp)
operand2 = evaluatePrefix(strExp)

return operand1 op operand2
}//end if

Is This A Good Question/Topic? 0
  • +

Replies To: how to convert prefix expression algorithm to a c++ program?

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: how to convert prefix expression algorithm to a c++ program?

Posted 27 April 2009 - 06:22 AM

Please show us the code you have written so far.

Please give us some more details of your problem.
( a ) Does your code compile
( b ) Any errors or warnings?
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1