// Prog: rpn_template.cpp // Author: ... // evaluates expressions in reverse polish notation (RPN) #include #include #include #include // POST: leading whitespace characters are extracted // from is, and the first non-whitespace character // is returned (0 if there is no such character) char lookahead (std::istream& is) { is >> std::ws; // skip whitespaces if (is.eof()) return 0; // end of stream else return is.peek(); // next character in is } // PRE: in = e, an expression in RPN // POST: in is empty, and the value of e is returned double evaluate (std::istream& in) { return 0; // ... to do! } int main() { std::stringstream input1 ("1 2 +"); // 3 std::stringstream input2 ("4 2 - 5 4 + *"); // 18 std::stringstream input3 ("3.0 1.5 * 1.5 3.0 * -"); // 0 std::cout << evaluate (input1) << "\n"; std::cout << evaluate (input2) << "\n"; std::cout << evaluate (input3) << "\n"; return 0; }