So I have to do a postfix calculator in C++ and implement my own stack. How do I read in from the keyboard? and How do I convert the + - / and * operators?
I already built a king od a generic stack without the extra bells and whistles. But besides that I don't have much else.
I'm so lost, thanks for any help in advance!
Postfix calculator in C++?
Read it into a string and then parse the string to determine if it is an operator or number.
It's not that hard. Just loop through the string calling isdigit() and watching out for decimal points. Operators are only going to be a handful of characters as well.
Reply:The way I would handle it would be to attempt to read in a number and if it fails, you know you've come to an operator:
float num;
char c;
then:
cin %26gt;%26gt; num;
if(cin.fail()) {
cin.reset();
cin %26gt;%26gt; c;
}
My method names may be wrong, its been a few years since I've used C++.
As far as determining the operator:
switch(c) {
case '+':
dosomething();
break;
case '-':
.....
You get the idea. Is this helpful? I'd have to risk my life in my closet to find the book I'd need to double check the accuracy, but that may get you started?
Reply:if your using visual c++ try using event hanlers on the properties window like key pressed or key down
Reply:****, i didnt learn this yet.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment