From c1b6ffe70bd281c6c230fd63fabcaac2aff47514 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 7 Apr 2024 23:18:32 -0700 Subject: feat: initial commit --- appendix/useful.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 appendix/useful.h (limited to 'appendix/useful.h') diff --git a/appendix/useful.h b/appendix/useful.h new file mode 100644 index 0000000..4513936 --- /dev/null +++ b/appendix/useful.h @@ -0,0 +1,45 @@ +// FILE: useful.h +// PROVIDES: A toolkit of useful functions for random numbers and displays. +// +// FUNCTIONS in the toolkit: +// double random_fraction( ) +// Postcondition: The return value is a random real number in the closed +// interval [0..1] (including the endpoints). +// +// double random_real(double low, double high) +// Precondition: low <= high. +// Postcondition: The return value is a random real number in the closed +// interval [low..high] (including the endpoints). +// +// void display(double x) +// Postcondition: The function has written one line of output to the +// standard ouput, with a vertical bar in the middle. If x is positive, +// then approximately x stars are printed to the right of the vertical +// bar. If x is negative, then approximately -x stars are printed to the +// left of the vertical bar. If the absolute value of x is more than +// 39, then only 39 stars are printed. +// Examples: +// display(8) prints: |******** +// display(-4) prints: ****| +// +// void eat_line( ) +// Postcondition: Up to next newline has been read and discarded from cin. +// +// bool inquire(const char query[ ]) +// Precondition: query is a null-terminated string of characters. +// Postcondition: query has been printed, and a one-line response read +// from the user. The function returns true if the user's response begins +// with 'Y' or 'y', and returns false if the user's response begins with +// 'N' or 'n'. (If the response begins with some other letter, then the +// query is repeated.) + +#ifndef USEFUL_H // Prevent duplicate definition +#define USEFUL_H + + double random_fraction( ); + double random_real(double low, double high); + void display(double x); + void eat_line( ); + bool inquire(const char query[ ]); + +#endif -- cgit v1.2.3