//--------------------------------------------------------- // Lab08Graphics.cpp // // // D. Searls // Asbury College // 2008 //--------------------------------------------------------- #include #include #include #include #include "list.cpp" #include "stack.cpp" #include using namespace std; struct tokenType { bool isOperand; double operand; string op; }; //----------------------------------------------- // precedence // // Returns the precedence of the specified // operator based on this table: // // Operator Precedence // -------- ---------- // function 4 // ^ 3 // * 2 // / 2 // + 1 // - 1 // ( 0 // "" 0 Null Operator // // Precondition: the operator is "+", "-", "*", // "/", "^", "(", "" or a function. // // In Parameter: op //----------------------------------------------- int precedence(string op) { } //----------------------------------------------- // Function: convertToPostfix // // Convert the infix expression (read from the // specified string stream) into a postfix // expression. // // Precondition: the infix expression consists of // space-delimited tokens and has no errors. // // In Parameter: infix // Out Parameter: postfix //----------------------------------------------- void convertToPostfix(stringstream& infix, list& postfix) { } //--------------------------------------------------------- // valueOf // // Given the value of the independent variable, x, this // function returns the value of the postfix expression. // // In Parameters: postfix, x //--------------------------------------------------------- double valueOf(list& postfix, double x) { } //********************************************************* // M A I N D R I V E R //********************************************************* int main() { list postfix; tokenType* ptr; string infix; stringstream infixStream; double x; cout << "Given an infix expression, this application will\n"; cout << "display the corresponding postfix expression and\n"; cout << "its value.\n\n"; cout << "To terminate, just tap the Enter key when asked\n"; cout << "for an infix expression.\n\n"; cout << " Infix: "; getline(cin, infix); while (infix.length() > 0) { cout << " x: "; cin >> x; cin.ignore(); infixStream.str(infix); postfix.clear(); convertToPostfix(infixStream, postfix); infixStream.clear(); cout << "Postfix: "; for (ptr = postfix.first(); ptr != postfix.end(); ptr = postfix.next()) { if (ptr->isOperand) { if (isnan(ptr->operand)) { cout << x; } else { cout << ptr->operand; } } else { cout << ptr->op; } cout << ' '; } cout << " = " << valueOf(postfix, x) << endl << endl; cout << " Infix: "; getline(cin, infix); } return 0; }