C Graphical Calculator is an ANSI C project that functions as a graphical calculator. It reads a mathematical function and an interval from the command line and generates a PostScript file containing the graph of the function over the specified range. If no custom limits are provided, the program defaults to using an interval of -10 to 10 for both the x and y axes.
- Input Validation: Verifies the correctness of the function and file name provided via command-line arguments.
- Graph Calculation: Computes function values over the defined interval using a fixed step value.
- PostScript Generation: Produces a PostScript file that visually represents the function with clearly marked axes and grid lines.
- Cross-Platform: Compiled in ANSI C, ensuring portability between Windows and Linux systems.
- ANSI C compiler (e.g.
gcc) - Make utility for building the project
To compile the project, use the provided Makefile.
For Linux:
makeFor Windows:
make -f makefile.winThe Makefile uses the project target name SemestralWork.
Run the generated executable from the command line using the following syntax:
graph.exe "function" "output_file.ps" [limits]Where:
"function"is a mathematical function ofx(e.g."sin(x)*cos(x)")."output_file.ps"is the name of the PostScript file to be created.[limits]is an optional parameter defining the interval in the formatx_min:x_max:y_min:y_max(e.g.-5:5:-10:10).
-
With Custom Limits
graph.exe "x^2 - 3*x + 2" "quadratic.ps" "-5:5:-10:10"
This command generates a graph for the function
x^2 - 3*x + 2withxranging from-5to5andyranging from-10to10. -
With Default Limits
graph.exe "sin(x)*cos(x)" "output.ps"
In this case, the program uses the default interval of
-10to10for both axes.
- Input Parsing: The program processes command-line arguments to extract the function, output filename, and optional interval limits.
- Function Processing: The function is parsed and validated to ensure proper syntax and allowed characters.
- Graph Calculation: The program computes the function values over the specified interval using a predetermined step size.
- PostScript Generation: The calculated points are used to create a PostScript file that includes axes, grid lines, and labels for clear visualization of the graph.
- The function must be provided in terms of
xand adhere to standard mathematical notation. - In case of insufficient or incorrectly formatted arguments, the program will display a usage message and exit with an error.
This project is released under the MIT License.
Enjoy using C Graphical Calculator and feel free to contribute or report any issues!
