Search : in
By :

Data Structure - C++

Last answer on Mar 24, 2009 8:19:10 am GMT don_226, on Mar 24, 2009 6:44:35 am GMT 
 Report this message to moderators

Hello guys,
If anyone can help me to solve this program i will be so thankfull.

Write a program called read_and_evaluate_expression that reads in a evaluates a postfix expression (defined below) and writes out its value.
There is one stack for holding operands, call numbers, which is initially empty.
• Read in the next digit or operator.
• Whenever you read a digit, push it onto the numbers stack.
• When you read in an operator - let's call it op - since it is a binary operator, it requires two arguments:
o remove the first two number from numbers; call the first one removed R and the second one L.
o evaluate L op R and push the result onto numbers.
• Ignore any blank space.
Note the numbers is from 0 to 9 and separated by one space

• Example: input line is 2 3 4 * + 5 -
• read '2', push it onto numbers.
• read following space.
• read '3', push it onto numbers.
• read following space.
• read '4', push it onto numbers.
• read following space.
• read '*'. Pop numbers: R=4. Pop numbers: L=3. L op R = 3 * 4 evaluates to 12. Push 12 onto numbers.
• read following space.
• read '+'. Pop numbers: R=12. Pop numbers: L=2. L op R = 2 + 12 evaluates to 14. Push 14 onto numbers.
• read following space.
• read '5'. Push it onto numbers.
• read following space.
• read '-'. Pop numbers: R=5. Pop numbers: L=14. L op R = 14 - 5 evaluates to 9. Push 9 onto numbers.
• When you reach end of the string . Pop numbers to get final answer 9 and write it out.

Configuration: Windows XP
Internet Explorer 6.0

Best answers for « Data Structure C++ » in :
Backup/Restore Mysql database ShowBackup/Restore Mysql database Backup Restore your database Note A simple approach on how to backup and restore MySQL databases. Backup To save an existing database it is recommended that you create a dump. To dump all...
Java Runtime Machine ShowJava Runtime Machine A Java Virtual Machine is a set of computer software and data structures that use a virtual machine model to execute other computer programs and scripts. JVM model use a form of computer intermediate language...
Backup Outlook 2003 data ShowBackup Outlook 2003 data All Outlook 2003 data ( Emails, Agenda, Contacts, Tasks...) are in one file with .pst extension The file is in the following default folder: C:\Documents and Settings\Login\Local Settings\Application...
Backup ShowBackup Setting up a redundant architecture ensures that system data will be available but does not protect the data against user-introduced errors or against natural disasters such as fires, floods or even earthquakes. Therefore it is necessary to...
OOP - Data encapsulation ShowThe concept of encapsulation Encapsulation is a way of organising data and methods into a structure by concealing the the way the object is implemented, i.e. preventing access to data by any means other than those specified. Encapsulation...
Data transmission - Cabling ShowCabling types Several physical data-transmission media are available to connect together the various devices on a network. One possibility is to use cables. There are many types of cables, but the most common are: Coaxial cable Double twisted...

1

 subzero00, on Mar 24, 2009 8:19:10 am GMT

Here is a website providing nice tutorials for C++ hopes it will help....
http://www.dreamincode.net/forums/showforum48.htm

Reply to subzero00