473,379 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

string expressions to integer

i want to know how to enter
expressions like : ((1+3)*5)
in string
then calculate its result ?????
Jun 14 '10 #1
8 1779
Dheeraj Joshi
1,123 Expert 1GB
Use stack for performing the operation. And you must evaluate your expression into postfix notation.

Regards
Dheeraj Joshi
Jun 14 '10 #2
plzexample

becz

if it is operator i cant make operation on to elements

explain for me in this example

((1+2)*3)
Jun 14 '10 #3
Dheeraj Joshi
1,123 Expert 1GB
Postfix expression of above statement will be
Expand|Select|Wrap|Line Numbers
  1. 12+3*
  2.  
push 1
push 2
Now input is +
pop 1
pop 2
calculate sum 1+2 = 3
push 3
Now input is *
pop 3
pop 3
calculate 3*3 = 9
Now no more inputs and stack top is -1, so stop

Regards
Dheeraj Joshi
Jun 14 '10 #4
donbock
2,426 Expert 2GB
What precisely is your assignment?

Are the four basic arithmetic functions (add, subtract, multiply, divide) sufficient or do you need to support other functions (such as exponentiation)?

The purpose of the postfix stack is to conform to the arithmetic order of operations. You need to have a clear understanding of the proper order of operations. Note that "order of operations" is a mathematical concept -- it has nothing to do with computer programming.
Jun 14 '10 #5
i need adding + and multiplication * only
and there are parentheses

but the way by stack is hardly to made!!!!!
Jun 14 '10 #6
how i push 1 then 2 before founding +
Jun 14 '10 #7
donbock
2,426 Expert 2GB
You should read about postfix notation. Evaluating a postfix expression is easy (that's the allure). The trick is to translate your input expression from infix notation to postfix notation.

Look at the example in your original post: ((1+3)*5)
The postfix equivalent is 1,3,+,5,*

This can be read as ...
  1. Put the number "1" in your left hand.
  2. Put the number "3" in your right hand.
  3. Add the numbers you're holding, putting the result in your left hand and dropping what's in your right hand.
  4. Put the number "5" in your right hand.
  5. Multiply the numbers you're holding, putting the result in your left hand and dropping what's in your right hand.

This distinction between "right hand" and "left hand" is not important for symmetric operators like add and multiply; but it is vital for asymmetric operators like subtract, divide, and exponentiate.

Writing an infix-to-postfix translator is a pretty common problem for introductory/intermediate programming courses. There is no point trying to write a program until you understand what postfix notation is, why it works, and how to do the translations with pencil and paper.
Jun 14 '10 #8
johny10151981
1,059 1GB
try post fix notation
read the algorithm,
Jun 16 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: news.hku.hk | last post by:
could you tell me how can i convet a string to integer?? #include <iostream> #include <string> using namespace std; int main(){ int integer; string buffer("123456789");
5
by: Allerdyce.John | last post by:
Do I need to convert string to integer in python? or it will do it for me (since dynamic type)? In my python script, I have this line: x /= 10; when i run it, I get this error: TypeError:...
9
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string froma file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
3
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
3
by: mattsniderppl | last post by:
Hi, I was hoping someone would know the reasons that this error is given, since i can't find any documentation explaining what causes this. I have a line of code in the onLoad function of my jsp...
4
by: GrahamG | last post by:
Hi, got the following code working after some effort. But have a question about the recursive code. I works fine but I cannot step through it to see what happens. Is there something that I can do to...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
3
by: jed | last post by:
in need an example of converting a string to integer
2
by: KWSW | last post by:
Another question to ask about built in java functions. I know that there is a Integer.toBinaryString function where I can get the binary value of an integer in a string representation. Example...
9
by: vaskar | last post by:
I have got one problem in VB.NET 2005 using unicode I want to add two numbers in vb.net 2005 through UNICODE I didn't know how to convert UNICODE string to integer. I hope you can solve my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.