Utilities Package  Version Linux2023.0
Classes | Typedefs | Functions | Variables
Scobey Namespace Reference

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...
 

Detailed Description

Contains one typedef, eleven named constants, fifteen free functions, and five utility classes.

Typedef Documentation

◆ String80

typedef char Scobey::String80[81]

Provides a legacy C-string type for holding up to 80 characters of text.

Function Documentation

◆ ClearScreen()

void Scobey::ClearScreen ( int  numLines = 25)

Clears the screen (the default output stream, which is assumed by default to have 25 lines).

Returns
void
Parameters
numLinesThe number of lines on the screen.
Precondition
None
Postcondition
numLines blank lines have been displayed on the standard output stream (the screen).

◆ DisplayOpeningScreen()

void Scobey::DisplayOpeningScreen ( const string &  programmerInfo = DEFAULT_PROGRAMMER_INFO,
const string &  programInfo = DEFAULT_PROGRAM_INFO,
int  numBlankLinesBefore = 11,
int  numBlankLinesAfter = 12 
)
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.

Returns
void
Parameters
programmerInfoText containing the programmer's ID info in the appropriate form (specified elsewhere, but not in this documentation).
programInfoText containing a brief (one-or-two-line) description of the program.
numBlankLinesBeforeThe number of blank lines appearing on the screen before the display of the contents of programmerInfo.
numBlankLinesAfterThe number of blank lines appearing on the screen after the display of the contents of programInfo.
Precondition
Note that default values are provided for all parameters and the default values of programmerInfo and programInfo are given by the named constants DEFAULT_PROGRAMMER_INFO and DEFAULT_PROGRAMMER_INFO (respectively), which are described elsewhere in this documentation. Here are the additional preconditions:
  1. The standard input stream cin is empty.
  2. Any newline character(s) required to begin a new line of output have been included in the values of the string input parameter(s) programmerInfo and/or programInfo.
Postcondition
  1. The contents of programmerInfo and programInfo have been displayed, in that order, followed by a line similar to the following:
    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.
  2. The program has paused after displaying a pause message, and the user has pressed Enter.

◆ DisplayTextfile()

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.

Returns
void
Parameters
fileNameThe name of the file to be displayed.
numberOfLinesPerPauseThe number of lines displayed between pauses.
Precondition
fileName has been initialized.
Postcondition
  • Case 1 (typical): If fileName contains the name of an existing and readable textfile in the current directory, or the full pathname of an existing and readable textfile in some other accessible directory, that file has been displayed on the screen numberOfLinesPerPause lines at at time, preceded by the message
    ==================================================
    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 ...
    
  • Case 2 (error): If the file designated by fileName cannot be opened, the function pauses and waits for the user to press Enter to continue, with the message
    Error: <<name-of-file>> could not be opened.
    Press Enter to continue ...
    
    and then returns.

◆ gcd()

int Scobey::gcd ( int  a,
int  b 
)

Finds the greatest common divisor of two nonnegative integers, at least one of which is strictly positive.

Returns
The greatest common divisor of the two input integers.
Parameters
aA nonnegative integer.
bA nonnegative integer.
Precondition
Both a and b have been initialized with nonnegative integer values, and at least one of a or b is strictly positive.
Postcondition
No side effects.

◆ isEven()

bool Scobey::isEven ( int  n)

Determines if a positive integer is even.

Returns
true if n is an even integer, false if n is odd.
Parameters
nThe integer whose "evenness" is to be determined.
Precondition
n is a nonnegative integer.
Postcondition
No side effects.

◆ isOdd()

bool Scobey::isOdd ( int  n)

Determines if a positive integer is odd.

Returns
true if n is an odd integer, false if n is even.
Parameters
nThe integer whose "oddness" is to be determined.
Precondition
n is a nonnegative integer.
Postcondition
No side effects.

◆ numberOfDigits()

int Scobey::numberOfDigits ( int  n)

Finds the number of digits in a positive integer.

Returns
The number of digits in the input integer.
Parameters
nThe integer whose digits are to be counted.
Precondition
n is a positive integer.
Postcondition
No side effects.

◆ Pause()

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.

Returns
void
Parameters
indentLevelThe number of spaces to indent the first line of each part of the output from the left margin.
messageThe message to be displayed, giving the reason for this particular pause, if such a message is supplied.
pauseNumberThe number of this particular pause, if pauses are being numbered.
Precondition
The input stream cin is empty.
Postcondition
  1. Each line of output produced by this function is automatically indented indentLevel spaces, except for the second and any subsequent lines of the text in message, which require a newline character to start a new line.
  2. If pauseNumber is 0 (the default value), there is no corresponding output, while if pauseNumber is any positive value (6 for example), a line like the following has been displayed as the first line of output:
    This is pause #6.
    
  3. If message is non-empty, its content has been displayed next, starting on the next line. An automatic newline is also inserted following the text of message, so the text of message itself need not (though it may) contain one or more newline characters.
  4. As the last line of output, in all cases, the message
    Press Enter to continue ...
    
    has been displayed, with the cursor at the end of the line.
  5. The user has pressed Enter.

◆ ReadChar()

void Scobey::ReadChar ( const string &  userPrompt,
char &  charValue 
)

Gets a character (char) value from the user.

Parameters
userPromptText of the prompt displayed to the user.
charValueContains the character entered by the user.
Returns
void
Precondition
  1. userPrompt has been initialized.
  2. The input stream is empty.
Postcondition
  1. The text in userPrompt has been displayed and the user has entered a character (a value of type char), which is returned in charValue. It is important to note that any char value will be read, including any whitespace character.
  2. The input stream cin is empty.

◆ ReadDouble()

void Scobey::ReadDouble ( const string &  userPrompt,
double &  doubleValue 
)

Gets a real (double) value from the user.

Returns
void
Parameters
userPromptText of the prompt displayed to the user.
doubleValueContains the real number entered by the user.
Precondition
userPrompt has been initialized.
Postcondition
  1. The text in userPrompt has been displayed and the user has entered a real number (a value of type 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.
  2. The input stream cin is empty.

◆ ReadInt()

void Scobey::ReadInt ( const string &  userPrompt,
int &  intValue 
)

Gets an integer (int) value from the user.

Returns
void
Parameters
userPromptText of the prompt displayed to the user.
intValueContains the integer value entered by the user.
Precondition
userPrompt has been initialized.
Postcondition
  1. The text in userPrompt has been displayed and the user has entered an integer (a value of type 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.
  2. The input stream cin is empty.

◆ ReadThisLine()

void Scobey::ReadThisLine ( const string &  userPrompt,
string &  lineValue 
)

Reads the text entered by a user on the same line as the prompt.

Returns
void
Parameters
userPromptText of the prompt displayed to the user.
lineValueContains the text entered by the user.
Precondition
userPrompt has been initialized.
Postcondition
  1. The text in userPrompt has been displayed and the user has entered some text and then pressed Enter. All text entered on same line as the prompt, after the prompt, (including all intermediate whitespace, but not including the terminating newline character) is returned in lineValue.
  2. The input stream cin is empty.

◆ ReadNextLine()

void Scobey::ReadNextLine ( const string &  userPrompt,
string &  lineValue 
)

Reads the text entered by a user on the line following the prompt.

Returns
void
Parameters
userPromptText of the prompt displayed to the user.
lineValueContains the line of text entered by the user.
Precondition
userPrompt has been initialized.
Postcondition
  1. The text in userPrompt has been displayed and the user has entered a line of input and then pressed Enter. The entire line of input (including all intermediate whitespace, but not including the terminating newline character) is returned in lineValue. Note that in this case the input is entered on the line following the prompt, while in each of the other Read* functions, the value is entered by the user on the same line as the prompt for that value.
  2. The input stream cin is empty.

◆ ReadString()

void Scobey::ReadString ( const string &  userPrompt,
string &  stringValue 
)

Gets a whitespace-delimited string value from the user.

Returns
void
Parameters
userPromptText of the prompt displayed to the user.
stringValueContains the string entered by the user.
Precondition
userPrompt has been initialized.
Postcondition
  1. The text in userPrompt has been displayed, and the user has entered a string value and pressed Enter. The string value is returned in stringValue. Note that the string read will be terminated by any whitespace.
  2. The input stream cin is empty.

◆ userSaysYes()

bool Scobey::userSaysYes ( const string &  question)

Gets the user's yes-or-no answer to a single question.

Returns
true if the user answers "Yes" to the question asked, and false otherwise.
Parameters
questionText of the question the user is asked, including the question mark.
Precondition
  1. question has been initialized.
  2. The standard input stream is empty.
Postcondition
The text in question has been displayed, followed by 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.

Variable Documentation

◆ CARD_DECK

const string Scobey::CARD_DECK[]
Initial value:
=
{ "AS", "2S", "3S", "4S", "5S", "6S", "7S",
"8S", "9S", "TS", "JS", "QS", "KS",
"AH", "2H", "3H", "4H", "5H", "6H", "7H",
"8H", "9H", "TH", "JH", "QH", "KH",
"AD", "2D", "3D", "4D", "5D", "6D", "7D",
"8D", "9D", "TD", "JD", "QD", "KD",
"AC", "2C", "3C", "4C", "5C", "6C", "7C",
"8C", "9C", "TC", "JC", "QC", "KC"
}

Provides 2-character representations of each of the fifty-two cards in a standard deck of cards.

◆ DAYS_OF_THE_WEEK_LONG

const string Scobey::DAYS_OF_THE_WEEK_LONG[]
Initial value:
=
{ "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"
}

Provides full names for days of the week.

◆ DAYS_OF_THE_WEEK_SHORT

const string Scobey::DAYS_OF_THE_WEEK_SHORT[]
Initial value:
=
{ "Mon", "Tue", "Wed", "Thu",
"Fri", "Sat", "Sun"
}

Provides 3-letter abbreviations for days of the week.

◆ DEFAULT_PROGRAM_INFO

const string Scobey::DEFAULT_PROGRAM_INFO
Initial value:
=
"Descriptive text required here is specificed elsewhere."

Provides a placeholder value for a program title or brief description.

◆ DEFAULT_PROGRAMMER_INFO

const string Scobey::DEFAULT_PROGRAMMER_INFO
Initial value:
=
"Lastname:Firstname:A00123456:u##"

Provides a placeholder value for programmer identification information.

◆ MONTHS_OF_THE_YEAR_LONG

const string Scobey::MONTHS_OF_THE_YEAR_LONG[]
Initial value:
=
{ "January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
}

Provides full names for months of the year.

◆ MONTHS_OF_THE_YEAR_SHORT

const string Scobey::MONTHS_OF_THE_YEAR_SHORT[]
Initial value:
=
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}

Provides 3-letter abbreviations for months of the year.

◆ NAMES_3CHAR

const string Scobey::NAMES_3CHAR[]
Initial value:
=
{ "Ace", "Ali", "Amy", "Ann", "Art",
"Ben", "Bob", "Cal", "Dan", "Del",
"Don", "Dot", "Eva", "Eve", "Fay",
"Gil", "Guy", "Hal", "Ian", "Jan",
"Jim", "Jon", "Kay", "Ken", "Kim",
"Liz", "Mac", "Min", "Nan", "Ora",
"Pam", "Red", "Rex", "Rik", "Rip",
"Rob", "Rod", "Rog", "Ron", "Roy",
"Sal", "Sam", "Sue", "Tad", "Tim",
"Tom", "Uma", "Val", "Wes", "Zig"
}

Provides fifty 3-character first names, some male and some female, in alphabetical order.

◆ NAMES_FAMILY

const string Scobey::NAMES_FAMILY[]
Initial value:
=
{ "Smith", "Johnson", "Williams", "Brown", "Jones",
"Miller", "Davis", "Garcia", "Rodriguez", "Wilson",
"Martinez", "Anderson", "Taylor", "Thomas", "Hernandez",
"Moore", "Martin", "Jackson", "Thompson", "White",
"Lopez", "Le", "Gonzalez", "Harris", "Clark",
"Lewis", "Robinson", "Walker", "Perez", "Hall",
"Young", "Allen", "Sanchez", "Wright", "King",
"Scott", "Green", "Baker", "Adams", "Nelson",
"Hill", "Ramirez", "Campbell", "Mitchell", "Roberts",
"Carter", "Phillips", "Evans", "Turner", "Torres",
"Parker", "Collins", "Edwards", "Stewart", "Flores",
"Morris", "Nguyen", "Murphy", "Rivera", "Cook",
"Rogers", "Morgan", "Peterson", "Cooper", "Reed",
"Bailey", "Bell", "Gomez", "Kelly", "Howard",
"Ward", "Cox", "Diaz", "Richardson", "Wood",
"Watson", "Brooks", "Bennett", "Gray", "James",
"Reyes", "Cruz", "Hughes", "Price", "Myers",
"Long", "Foster", "Sanders", "Ross", "Morales",
"Powell", "Sullivan", "Russell", "Ortiz", "Jenkins",
"Gutierrez", "Perry", "Butler", "Barnes", "Fisher"
}

Provides 100 family names (surnames), ranked in order of frequency as found in the United States of America.

◆ NAMES_FEMALE

const string Scobey::NAMES_FEMALE[]

Provides 300 female first names, ranked in order of frequency as found in the United States of America.

◆ NAMES_MALE

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.