/* This version is more generally useful, because it can plot any function. It uses the strange but simple idea of giving one function as a parameter to another. */ #include "library.h" double f(double x) { const double A = x*x*x/1e6; return cos(A)*1e4/(x+1) + 250; } double g(double x) { const double A = x*x/1e4; return sin(A)*1e4/(x+1) + 250; } void formula_plot_rest(int A, int B, double function(double x)) { const int x = A; const int y = function(x); draw_to(x, y); if (A < B) formula_plot_rest(A+1, B, function); } void formula_plot(int A, int B, double function(double x)) { const int x = A; const int y = function(x); move_to(x, y); if (A < B) formula_plot_rest(A+1, B, function); } void main() { make_window(500, 500); set_pen_color(color::blue); formula_plot(100, 500, f); set_pen_color(color::red); formula_plot(100, 500, g); }