coding UTF-8; import Math; import Text; import GUI; import File; import tool.Graph2D; /** The default value of the expression y(x) to plot graph */ const string DEFAULT_Y_EXPRESSION = "sin(3*x)"; /** The default value of the maximum value of the x-range of the graph. */ const string DEFAULT_X_MAX = "1.0"; /** The default value of the minimum value of the x-range of the graph. */ const string DEFAULT_X_MIN = "-1.0"; /** The default value of the number of the point of the graph. */ const string DEFAULT_X_N = "100"; // Followings are variables to store IDs of the graph and GUI components. /** Stores the ID of the graph. **/ int graph = NULL; /** Stores the ID of the input-window. **/ int window = NULL; /** Stores the ID of the text-field of the expression y(x). **/ int expressionField = NULL; /** Stores the ID of the text-field of the maximum value of x-range. **/ int xMaxField = NULL; /** Stores the ID of the text-field of the minimum value of x-range. **/ int xMinField = NULL; /** Stores the ID of the text-field of the number of points of the graph. **/ int xNField = NULL; /** Stores the ID of the PLOT button. **/ int plotButton = NULL; /** Stores the ID of the CLEAR button. **/ int clearButton = NULL; /** Stores the ID of the EXPORT button. **/ int exportButton = NULL; /** Stores the ID of the EXIT button. **/ int exitButton = NULL; /** * Invoked automatically when this program have started. */ void main(){ // Set the console window invisible because it is not necessary for GUI program. hide(); // Create (or get from the system) a 2D graph window. graph = getGraph2D(); // Set the size and the location of the graph-window. setGraph2DLocation(graph, 330, 0); setGraph2DSize(graph, 720, 600); // Create and launch the input-window. createInputWindow(); // If you want to read processings after when the user click PLOT button, // see "onButtonClick" function at near the bottom of this code. } /** * Plots the expression to the 2D graph. * * @param yExpression The expression of y(x). * @param xMin The minimum value of x-range. * @param xMax The maximum value of x-range. * @param n The number of points of the graph. */ void plotGraph( string yExpression, double xMin, double xMax, int n ){ // Arrays storing vertices data to transfer the graph. double xArray[n]; double yArray[n]; // coordinate variables of a point. double x; double y; // Check the syntax of the expression y(x). if( !evaluable(yExpression, 0.0) ){ alert("The form of the expression of \"y(x)\" is wrong."); return; } // Store coordinate values to arrays at n-1 equally divided points of the x-range. float dx = (xMax-xMin)/(n-1); for( int i=0; i