Utilities Package
Version Linux2023.0
|
Contains one typedef, eleven named constants, fifteen free functions, and five utility classes. More...
Classes | |
class | Menu |
For displaying menus and getting user menu choices in console applications. More... | |
class | OperationCounter |
For counting operations performed by an algorithm. More... | |
class | RandomGenerator |
For generating pseudorandom integer, real, character and string values. More... | |
class | Stopwatch |
For measuring the time taken by an algorithm to perform its task. More... | |
class | TextItems |
For displaying on-line help and other text messages in console applications. More... | |
Typedefs | |
typedef char | String80[81] |
Provides a legacy C-string type for holding up to 80 characters of text. More... | |
Functions | |
void | ClearScreen (int numLines=25) |
Clears the screen (the default output stream, which is assumed by default to have 25 lines). More... | |
void | DisplayOpeningScreen (const string &programmerInfo=DEFAULT_PROGRAMMER_INFO, const string &programInfo=DEFAULT_PROGRAM_INFO, int numBlankLinesBefore=11, int numBlankLinesAfter=12) |
Displays an opening screen for any console program. More... | |
void | DisplayTextfile (const string &fileName, int numberOfLinesPerPause=23) |
Displays a file of text numberOfLinesPerPause lines at a time. More... | |
int | gcd (int a, int b) |
Finds the greatest common divisor of two nonnegative integers, at least one of which is strictly positive. More... | |
bool | isEven (int n) |
Determines if a positive integer is even. More... | |
bool | isOdd (int n) |
Determines if a positive integer is odd. More... | |
int | numberOfDigits (int n) |
Finds the number of digits in a positive integer. More... | |
void | Pause (int indentLevel=0, string message="", int pauseNumber=0) |
Causes the program to pause and wait for the user to press Enter to continue, with default values for the indentation level, the message supplying any additional information to the user, and the pause number. More... | |
void | ReadChar (const string &userPrompt, char &charValue) |
Gets a character (char) value from the user. More... | |
void | ReadDouble (const string &userPrompt, double &doubleValue) |
Gets a real (double) value from the user. More... | |
void | ReadInt (const string &userPrompt, int &intValue) |
Gets an integer (int) value from the user. More... | |
void | ReadThisLine (const string &userPrompt, string &lineValue) |
Reads the text entered by a user on the same line as the prompt. More... | |
void | ReadNextLine (const string &userPrompt, string &lineValue) |
Reads the text entered by a user on the line following the prompt. More... | |
void | ReadString (const string &userPrompt, string &stringValue) |
Gets a whitespace-delimited string value from the user. More... | |
bool | userSaysYes (const string &question) |
Gets the user's yes-or-no answer to a single question. More... | |
Variables | |
const string | CARD_DECK [] |
Provides 2-character representations of each of the fifty-two cards in a standard deck of cards. More... | |
const string | DAYS_OF_THE_WEEK_LONG [] |
Provides full names for days of the week. More... | |
const string | DAYS_OF_THE_WEEK_SHORT [] |
Provides 3-letter abbreviations for days of the week. More... | |
const string | DEFAULT_PROGRAM_INFO |
Provides a placeholder value for a program title or brief description. More... | |
const string | DEFAULT_PROGRAMMER_INFO |
Provides a placeholder value for programmer identification information. More... | |
const string | MONTHS_OF_THE_YEAR_LONG [] |
Provides full names for months of the year. More... | |
const string | MONTHS_OF_THE_YEAR_SHORT [] |
Provides 3-letter abbreviations for months of the year. More... | |
const string | NAMES_3CHAR [] |
Provides fifty 3-character first names, some male and some female, in alphabetical order. More... | |
const string | NAMES_FAMILY [] |
Provides 100 family names (surnames), ranked in order of frequency as found in the United States of America. More... | |
const string | NAMES_FEMALE [] |
Provides 300 female first names, ranked in order of frequency as found in the United States of America. More... | |
const string | NAMES_MALE [] |
A named constant containing 300 male first names, 6 per line, ranked in order of frequency as found in the United States. More... | |
Contains one typedef, eleven named constants, fifteen free functions, and five utility classes.
typedef char Scobey::String80[81] |
Provides a legacy C-string type for holding up to 80 characters of text.
void Scobey::ClearScreen | ( | int | numLines = 25 | ) |
Clears the screen (the default output stream, which is assumed by default to have 25 lines).
numLines | The number of lines on the screen. |
|
inline |
Displays an opening screen for any console program.
The default display shows a first line of programmer identification, the date and time of the current program build on the second line, and a generic program description on the third line of output. These three lines of output are centered vertically, more or less, on an otherwise blank screen. The idea is to keep the program description as short as possible (preferably one or two lines), and to center vertically on the screen all lines of output. To help accomplish these goals the user is permitted to choose the number of blank lines to output both before and after the lines containing information.
programmerInfo | Text containing the programmer's ID info in the appropriate form (specified elsewhere, but not in this documentation). |
programInfo | Text containing a brief (one-or-two-line) description of the program. |
numBlankLinesBefore | The number of blank lines appearing on the screen before the display of the contents of programmerInfo. |
numBlankLinesAfter | The number of blank lines appearing on the screen after the display of the contents of programInfo. |
This executable was built on May 25 2007 at 23:47:51.There are no blank lines separating any of these lines of information, but numBlankLinesBefore blank lines are output before the contents of programmerInfo and numBlankLinesAfter blank lines are output after the line containing the build date and time.
void Scobey::DisplayTextfile | ( | const string & | fileName, |
int | numberOfLinesPerPause = 23 |
||
) |
Displays a file of text numberOfLinesPerPause lines at a time.
This function allows the user to display any textfile on the standard output and also lets the user decide how many lines to display "between pauses", i.e., between the times when the function pauses and waits for the user to press Enter to continue.
fileName | The name of the file to be displayed. |
numberOfLinesPerPause | The number of lines displayed between pauses. |
================================================== The file display will begin when you continue after this pause. And note that one blank line not in the file will appear after each pause. Press Enter to continue ...and followed by this message:
End of file has been reached. Press Enter to continue ...In addition, after each group of lines has been displayed, the program pauses and waits for the user to press Enter, with a message like the following:
=====Line immediately above is line ## of file name-of-file. Press Enter to continue ...
Error: <<name-of-file>> could not be opened. Press Enter to continue ...and then returns.
int Scobey::gcd | ( | int | a, |
int | b | ||
) |
Finds the greatest common divisor of two nonnegative integers, at least one of which is strictly positive.
a | A nonnegative integer. |
b | A nonnegative integer. |
bool Scobey::isEven | ( | int | n | ) |
Determines if a positive integer is even.
true
if n is an even integer, false
if n is odd. n | The integer whose "evenness" is to be determined. |
bool Scobey::isOdd | ( | int | n | ) |
Determines if a positive integer is odd.
true
if n is an odd integer, false
if n is even. n | The integer whose "oddness" is to be determined. |
int Scobey::numberOfDigits | ( | int | n | ) |
Finds the number of digits in a positive integer.
n | The integer whose digits are to be counted. |
void Scobey::Pause | ( | int | indentLevel = 0 , |
string | message = "" , |
||
int | pauseNumber = 0 |
||
) |
Causes the program to pause and wait for the user to press Enter to continue, with default values for the indentation level, the message supplying any additional information to the user, and the pause number.
indentLevel | The number of spaces to indent the first line of each part of the output from the left margin. |
message | The message to be displayed, giving the reason for this particular pause, if such a message is supplied. |
pauseNumber | The number of this particular pause, if pauses are being numbered. |
This is pause #6.
Press Enter to continue ...has been displayed, with the cursor at the end of the line.
void Scobey::ReadChar | ( | const string & | userPrompt, |
char & | charValue | ||
) |
Gets a character (char) value from the user.
userPrompt | Text of the prompt displayed to the user. |
charValue | Contains the character entered by the user. |
void Scobey::ReadDouble | ( | const string & | userPrompt, |
double & | doubleValue | ||
) |
Gets a real (double) value from the user.
userPrompt | Text of the prompt displayed to the user. |
doubleValue | Contains the real number entered by the user. |
double
), which is returned in doubleValue. If the user does not enter a valid real number, the following message is displayed: Error: That was not a valid real number. Try again. Press Enter to continue ...after which the prompt is displayed again and the user gets another chance. This is essentially an infinite loop, so the user must eventually enter a valid real number for the process to terminate normally.
void Scobey::ReadInt | ( | const string & | userPrompt, |
int & | intValue | ||
) |
Gets an integer (int) value from the user.
userPrompt | Text of the prompt displayed to the user. |
intValue | Contains the integer value entered by the user. |
int
), which is returned in intValue. If the user does not enter a valid integer, the following message is displayed: Error: That was not a valid integer. Try again. Press Enter to continue ...after which the prompt is displayed again and the user gets another chance. This is essentially an infinite loop, so the user must eventually enter a valid integer value for the process to terminate normally.
void Scobey::ReadThisLine | ( | const string & | userPrompt, |
string & | lineValue | ||
) |
Reads the text entered by a user on the same line as the prompt.
userPrompt | Text of the prompt displayed to the user. |
lineValue | Contains the text entered by the user. |
void Scobey::ReadNextLine | ( | const string & | userPrompt, |
string & | lineValue | ||
) |
Reads the text entered by a user on the line following the prompt.
userPrompt | Text of the prompt displayed to the user. |
lineValue | Contains the line of text entered by the user. |
void Scobey::ReadString | ( | const string & | userPrompt, |
string & | stringValue | ||
) |
Gets a whitespace-delimited string value from the user.
userPrompt | Text of the prompt displayed to the user. |
stringValue | Contains the string entered by the user. |
bool Scobey::userSaysYes | ( | const string & | question | ) |
Gets the user's yes-or-no answer to a single question.
true
if the user answers "Yes" to the question asked, and false
otherwise. question | Text of the question the user is asked, including the question mark. |
y/[n]
and the user has responded by entering a character and pressing Enter. The value true
is returned if the user responds positively to the question asked by entering a y
or a Y
, or by entering any word beginning with either of these letters. Entering any other letter or word, as well as simply pressing the Enter key, will be interpreted as a negative response and the return value will be false
. The use of [n]
as part of the user prompt is meant to indicate to the user that simply pressing Enter will generate a (default) response of "no". This is a convention of reasonably widespread use in console applications. const string Scobey::CARD_DECK[] |
Provides 2-character representations of each of the fifty-two cards in a standard deck of cards.
const string Scobey::DAYS_OF_THE_WEEK_LONG[] |
Provides full names for days of the week.
const string Scobey::DAYS_OF_THE_WEEK_SHORT[] |
Provides 3-letter abbreviations for days of the week.
const string Scobey::DEFAULT_PROGRAM_INFO |
Provides a placeholder value for a program title or brief description.
const string Scobey::DEFAULT_PROGRAMMER_INFO |
Provides a placeholder value for programmer identification information.
const string Scobey::MONTHS_OF_THE_YEAR_LONG[] |
Provides full names for months of the year.
const string Scobey::MONTHS_OF_THE_YEAR_SHORT[] |
Provides 3-letter abbreviations for months of the year.
const string Scobey::NAMES_3CHAR[] |
Provides fifty 3-character first names, some male and some female, in alphabetical order.
const string Scobey::NAMES_FAMILY[] |
Provides 100 family names (surnames), ranked in order of frequency as found in the United States of America.
const string Scobey::NAMES_FEMALE[] |
Provides 300 female first names, ranked in order of frequency as found in the United States of America.
const string Scobey::NAMES_MALE[] |
A named constant containing 300 male first names, 6 per line, ranked in order of frequency as found in the United States.