//--------------------------------------------------------- // Lab08Graphics.cpp // // // D. Searls // Asbury College // 2008 //--------------------------------------------------------- #include #include #include #include #include "list.cpp" #include "stack.cpp" #include #include "worldType.h" #include const int NUM_PIXELS = 701; 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) { } //--------------------------------------------------------- // drawGrid // // Draw a grid on the graphics device based on the // specified parameter values. // // In parameters: // // w: world coordinate system // minX, maxX: range of x values // minY, maxY: range of y values // xinc, yinc: grid increment in x and y directions //--------------------------------------------------------- void drawGrid(worldType& w, double minX, double maxX, double minY, double maxY, double xinc, double yinc) { } //--------------------------------------------------------- // drawGraph // // Draw the graph of the specified function on the graphics // window with the specified properties. // // In Parameters // w: the graphics window // postfix: the function // xmin, xmax: domain // ymin, ymax: range // xinc, yinc: grid increments //--------------------------------------------------------- void drawGraph(worldType& w, list& postfix, double xmin, double xmax, double ymin, double ymax, double xinc, double yinc) { } //********************************************************* // M A I N D R I V E R //********************************************************* int main() { list postfix; string infix; stringstream infixStream; double x1, y1, x2, y2, xGap, yGap; worldType w(NUM_PIXELS, NUM_PIXELS, 10, 10, -1.0, -1.0, 1.0, 1.0, "y = f(x)"); cout << "Given a function with one variable, this application will draw\n"; cout << "the graph of the function on a square graphics window. You\n"; cout << "will be asked to enter the function, the world coordinates of\n"; cout << "the lower-left and upper-right corners of the graphics window,\n"; cout << "and the spacing of the horizontal and vertical gridlines (called\n"; cout << "\"y gap\" and \"x gap\" respectively).\n\n"; cout << "To terminate the program, 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 << " Lower-left x: "; cin >> x1; cout << " Lower-left y: "; cin >> y1; cout << "Upper-right x: "; cin >> x2; cout << "Upper-right y: "; cin >> y2; cout << " x gap: "; cin >> xGap; cout << " y gap: "; cin >> yGap; cin.ignore(); infixStream.str(infix); postfix.clear(); convertToPostfix(infixStream, postfix); infixStream.clear(); drawGraph(w, postfix, x1, x2, y1, y2, xGap, yGap); cout << endl << " Infix: "; getline(cin, infix); } return 0; }