// ------------------------------------------------------------ // ww.h base, and text output functions All C++ // ------------------------------------------------------------ /* Base section has definitions we always use Simplify by not using a text win class Keep all code generic Combine declarations and definitions in one file: hence ifndef-define-endif wraps this whole file. */ #ifndef w_h #define w_h // ------------------------------------------------------------------ // top-level functions #ifndef fptype_1 #define fptype_1 typedef double (*fptype1)( double); #endif #ifndef fptype_2 #define fptype_2 typedef double (*fptype2)( double,double); #endif #ifndef fptype_3 #define fptype_3 typedef double (*fptype3)( double,double,double); #endif // ----------------------------------------------------------------- // the fun function classes #ifndef fun_1 #define fun_1 class fun { public: virtual double f(double) = 0; }; #endif #ifndef fun_2 #define fun_2 class fun2 { public: virtual double f(double, double) = 0; }; #endif #ifndef fun_3 #define fun_3 class fun3 { public: virtual double f(double, double, double) = 0; }; #endif // --------------------------------------------------------------------- // our usual selection of libraries #include // Stream library #include // Console i/o library #include // for gets #include // for atoi #include // for format strings #include // string library #include // Math library // some global constants (defined later) const extern double Pi; const extern double Piby2; const extern double Piby4; const extern double Piby180; const extern double Exp1; // some global functions extern int QUIT; // 1 or 0 void wait(); // wait for key press 'q' -> quit = 1 int roll(int i, int n, int di = 1); // di cyclic perms of 1..n starting at i double fid(double x); // functional identity double sqr(double x); // ------------------------------------------------------ // io functions void nl(int dn = 1); // new line(s) void p(char *s); // print s to current position void pl(char *s); // print s with new line void p(double x); // print x to current position void pl(double x); // print x with new line void p(char *s,double x); // print s x void pl(char*s,double x); // print s x void banner(char *s); // print banner void pf(char *fmt, ...); // p formatted data void pfl(char *fmt, ...); // p formatted data with nl void r(char *s); // read string s, and nl void r(double &x); // read string s, x = atof(s) void r(char *s, double &x); void ftab(fptype1 f, char *fs, // tabulate x f(x) double xa, double xb, int nx); void ftab(fun *f, char *fs, // tabulate x f(x) double xa, double xb, int nx); void precision(int n); // sets cout precision // ------------------------------------------------------------ #endif