Utilities Package  Version VS2013.0
 All Classes Namespaces Files Functions Variables Typedefs Pages
utilities.h
Go to the documentation of this file.
1 
85 #ifndef UTILITIES_H
86 #define UTILITIES_H
87 
88 #include <cstdlib>
89 #include <ctime>
90 #include <string>
91 #include <vector>
92 using std::cout;
93 using std::string;
94 using std::vector;
95 
100 namespace Scobey
101 {
102 
103 //************************************************************************
104 //Typedef Section
105 
106 typedef char String80[81];
111 //
112 //
113 //************************************************************************
114 //Named Constant Section
115 
116 const string CARD_DECK[] =
117  { "AS", "2S", "3S", "4S", "5S", "6S", "7S",
118  "8S", "9S", "TS", "JS", "QS", "KS",
119  "AH", "2H", "3H", "4H", "5H", "6H", "7H",
120  "8H", "9H", "TH", "JH", "QH", "KH",
121  "AD", "2D", "3D", "4D", "5D", "6D", "7D",
122  "8D", "9D", "TD", "JD", "QD", "KD",
123  "AC", "2C", "3C", "4C", "5C", "6C", "7C",
124  "8C", "9C", "TC", "JC", "QC", "KC"
125  };
132 const string DAYS_OF_THE_WEEK_LONG[] =
133  { "Monday", "Tuesday", "Wednesday", "Thursday",
134  "Friday", "Saturday", "Sunday"
135  };
141 const string DAYS_OF_THE_WEEK_SHORT[] =
142  { "Mon", "Tue", "Wed", "Thu",
143  "Fri", "Sat", "Sun"
144  };
150 const string DEFAULT_PROGRAM_INFO =
151  "Descriptive text required here is specificed elsewhere.";
158  "Lastname:Firstname:A00123456:CSC?????";
164 const string MONTHS_OF_THE_YEAR_LONG[] =
165  { "January", "February", "March", "April",
166  "May", "June", "July", "August",
167  "September", "October", "November", "December"
168  };
174 const string MONTHS_OF_THE_YEAR_SHORT[] =
175  { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
176  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
177  };
183 const string NAMES_3CHAR[] =
184  { "Ace", "Ali", "Amy", "Ann", "Art",
185  "Ben", "Bob", "Cal", "Dan", "Del",
186  "Don", "Dot", "Eva", "Eve", "Fay",
187  "Gil", "Guy", "Hal", "Ian", "Jan",
188  "Jim", "Jon", "Kay", "Ken", "Kim",
189  "Liz", "Mac", "Min", "Nan", "Ora",
190  "Pam", "Red", "Rex", "Rik", "Rip",
191  "Rob", "Rod", "Rog", "Ron", "Roy",
192  "Sal", "Sam", "Sue", "Tad", "Tim",
193  "Tom", "Uma", "Val", "Wes", "Zig"
194  };
201 const string NAMES_FAMILY[] =
202  { "Smith", "Johnson", "Williams", "Brown", "Jones",
203  "Miller", "Davis", "Garcia", "Rodriguez", "Wilson",
204  "Martinez", "Anderson", "Taylor", "Thomas", "Hernandez",
205  "Moore", "Martin", "Jackson", "Thompson", "White",
206  "Lopez", "Le", "Gonzalez", "Harris", "Clark",
207  "Lewis", "Robinson", "Walker", "Perez", "Hall",
208  "Young", "Allen", "Sanchez", "Wright", "King",
209  "Scott", "Green", "Baker", "Adams", "Nelson",
210  "Hill", "Ramirez", "Campbell", "Mitchell", "Roberts",
211  "Carter", "Phillips", "Evans", "Turner", "Torres",
212  "Parker", "Collins", "Edwards", "Stewart", "Flores",
213  "Morris", "Nguyen", "Murphy", "Rivera", "Cook",
214  "Rogers", "Morgan", "Peterson", "Cooper", "Reed",
215  "Bailey", "Bell", "Gomez", "Kelly", "Howard",
216  "Ward", "Cox", "Diaz", "Richardson", "Wood",
217  "Watson", "Brooks", "Bennett", "Gray", "James",
218  "Reyes", "Cruz", "Hughes", "Price", "Myers",
219  "Long", "Foster", "Sanders", "Ross", "Morales",
220  "Powell", "Sullivan", "Russell", "Ortiz", "Jenkins",
221  "Gutierrez", "Perry", "Butler", "Barnes", "Fisher"
222  };
229 const string NAMES_FEMALE[] =
230  { "Mary", "Patricia", "Linda", "Barbara", "Elizabeth", "Jennifer",
231  "Maria", "Susan", "Margaret", "Dorothy", "Lisa", "Nancy",
232  "Karen", "Betty", "Helen", "Sandra", "Donna", "Carol",
233  "Ruth", "Sharon", "Michelle", "Laura", "Sarah", "Kimberly",
234  "Deborah", "Jessica", "Shirley", "Cynthia", "Angela", "Melissa",
235  "Brenda", "Amy", "Anna", "Rebecca", "Virginia", "Kathleen",
236  "Pamela", "Martha", "Debra", "Amanda", "Stephanie", "Carolyn",
237  "Christine", "Marie", "Janet", "Catherine", "Frances", "Ann",
238  "Joyce", "Diane", "Alice", "Julie", "Heather", "Teresa",
239  "Doris", "Gloria", "Evelyn", "Jean", "Cheryl", "Mildred",
240  "Katherine", "Joan", "Ashley", "Judith", "Rose", "Janice",
241  "Kelly", "Nicole", "Judy", "Christina", "Kathy", "Theresa",
242  "Beverly", "Denise", "Tammy", "Irene", "Jane", "Lori",
243  "Rachel", "Marilyn", "Andrea", "Kathryn", "Louise", "Sara",
244  "Anne", "Jacqueline", "Wanda", "Bonnie", "Julia", "Ruby",
245  "Lois", "Tina", "Phyllis", "Norma", "Paula", "Diana",
246  "Annie", "Lillian", "Emily", "Robin", "Peggy", "Crystal",
247  "Gladys", "Rita", "Dawn", "Connie", "Florence", "Tracy",
248  "Edna", "Tiffany", "Carmen", "Rosa", "Cindy", "Grace",
249  "Wendy", "Victoria", "Edith", "Kim", "Sherry", "Sylvia",
250  "Josephine", "Thelma", "Shannon", "Sheila", "Ethel", "Ellen",
251  "Elaine", "Marjorie", "Carrie", "Charlotte", "Monica", "Esther",
252  "Pauline", "Emma", "Juanita", "Anita", "Rhonda", "Hazel",
253  "Amber", "Eva", "Debbie", "April", "Leslie", "Clara",
254  "Lucille", "Jamie", "Joanne", "Eleanor", "Valerie", "Danielle",
255  "Megan", "Alicia", "Suzanne", "Michele", "Gail", "Bertha",
256  "Darlene", "Veronica", "Jill", "Erin", "Geraldine", "Lauren",
257  "Cathy", "Joann", "Lorraine", "Lynn", "Sally", "Regina",
258  "Erica", "Beatrice", "Dolores", "Bernice", "Audrey", "Yvonne",
259  "Annette", "June", "Samantha", "Marion", "Dana", "Stacy",
260  "Ana", "Renee", "Ida", "Vivian", "Roberta", "Holly",
261  "Brittany", "Melanie", "Loretta", "Yolanda", "Jeanette", "Laurie",
262  "Katie", "Kristen", "Vanessa", "Alma", "Sue", "Elsie",
263  "Beth", "Jeanne", "Vicki", "Carla", "Tara", "Rosemary",
264  "Eileen", "Terri", "Gertrude", "Lucy", "Tonya", "Ella",
265  "Stacey", "Wilma", "Gina", "Kristin", "Jessie", "Natalie",
266  "Agnes", "Vera", "Willie", "Charlene", "Bessie", "Delores",
267  "Melinda", "Pearl", "Arlene", "Maureen", "Colleen", "Allison",
268  "Tamara", "Joy", "Georgia", "Constance", "Lillie", "Claudia",
269  "Jackie", "Marcia", "Tanya", "Nellie", "Minnie", "Marlene",
270  "Heidi", "Glenda", "Lydia", "Viola", "Courtney", "Marian",
271  "Stella", "Caroline", "Dora", "Jo", "Vickie", "Mattie",
272  "Terry", "Maxine", "Irma", "Mabel", "Marsha", "Myrtle",
273  "Lena", "Christy", "Deanna", "Patsy", "Hilda", "Gwendolyn",
274  "Jennie", "Nora", "Margie", "Nina", "Cassandra", "Leah",
275  "Penny", "Kay", "Priscilla", "Naomi", "Carole", "Brandy",
276  "Olga", "Billie", "Dianne", "Tracey", "Leona", "Jenny",
277  "Felicia", "Sonia", "Miriam", "Velma", "Becky", "Bobbie",
278  "Violet", "Kristina", "Toni", "Misty", "Mae", "Shelly",
279  "Daisy", "Ramona", "Sherri", "Erika", "Katrina", "Claire"
280  };
287 const string NAMES_MALE[] =
288  { "James", "John", "Robert", "Michael", "William", "David",
289  "Richard", "Charles", "Joseph", "Thomas", "Christopher", "Daniel",
290  "Paul", "Mark", "Donald", "George", "Kenneth", "Steven",
291  "Edward", "Brian", "Ronald", "Anthony", "Kevin", "Jason",
292  "Matthew", "Gary", "Timothy", "Jose", "Larry", "Jeffrey",
293  "Frank", "Scott", "Eric", "Stephen", "Andrew", "Raymond",
294  "Gregory", "Joshua", "Jerry", "Dennis", "Walter", "Patrick",
295  "Peter", "Harold", "Douglas", "Henry", "Carl", "Arthur",
296  "Ryan", "Roger", "Joe", "Juan", "Jack", "Albert",
297  "Jonathan", "Justin", "Terry", "Gerald", "Keith", "Samuel",
298  "Willie", "Ralph", "Lawrence", "Nicholas", "Roy", "Benjamin",
299  "Bruce", "Brandon", "Adam", "Harry", "Fred", "Wayne",
300  "Billy", "Steve", "Louis", "Jeremy", "Aaron", "Randy",
301  "Howard", "Eugene", "Carlos", "Russell", "Bobby", "Victor",
302  "Martin", "Ernest", "Phillip", "Todd", "Jesse", "Craig",
303  "Alan", "Shawn", "Clarence", "Sean", "Philip", "Chris",
304  "Johnny", "Earl", "Jimmy", "Antonio", "Danny", "Bryan",
305  "Tony", "Luis", "Mike", "Stanley", "Leonard", "Nathan",
306  "Dale", "Manuel", "Rodney", "Curtis", "Norman", "Allen",
307  "Marvin", "Vincent", "Glenn", "Jeffery", "Travis", "Jeff",
308  "Chad", "Jacob", "Lee", "Melvin", "Alfred", "Kyle",
309  "Francis", "Bradley", "Jesus", "Herbert", "Frederick", "Ray",
310  "Joel", "Edwin", "Don", "Eddie", "Ricky", "Troy",
311  "Randall", "Barry", "Alexander", "Bernard", "Mario", "Leroy",
312  "Francisco", "Marcus", "Micheal", "Theodore", "Clifford", "Miguel",
313  "Oscar", "Jay", "Jim", "Tom", "Calvin", "Alex",
314  "Jon", "Ronnie", "Bill", "Lloyd", "Tommy", "Leon",
315  "Derek", "Warren", "Darrell", "Jerome", "Floyd", "Leo",
316  "Alvin", "Tim", "Wesley", "Gordon", "Dean", "Greg",
317  "Jorge", "Dustin", "Pedro", "Derrick", "Dan", "Lewis",
318  "Zachary", "Corey", "Herman", "Maurice", "Vernon", "Roberto",
319  "Clyde", "Glen", "Hector", "Shane", "Ricardo", "Sam",
320  "Rick", "Lester", "Brent", "Ramon", "Charlie", "Tyler",
321  "Gilbert", "Gene", "Marc", "Reginald", "Ruben", "Brett",
322  "Angel", "Nathaniel", "Rafael", "Leslie", "Edgar", "Milton",
323  "Raul", "Ben", "Chester", "Cecil", "Duane", "Franklin",
324  "Andre", "Elmer", "Brad", "Gabriel", "Ron", "Mitchell",
325  "Roland", "Arnold", "Harvey", "Jared", "Adrian", "Karl",
326  "Cory", "Claude", "Erik", "Darryl", "Jamie", "Neil",
327  "Jessie", "Christian", "Javier", "Fernando", "Clinton", "Ted",
328  "Mathew", "Tyrone", "Darren", "Lonnie", "Lance", "Cody",
329  "Julio", "Kelly", "Kurt", "Allan", "Nelson", "Guy",
330  "Clayton", "Hugh", "Max", "Dwayne", "Dwight", "Armando",
331  "Felix", "Jimmie", "Everett", "Jordan", "Ian", "Wallace",
332  "Ken", "Bob", "Jaime", "Casey", "Alfredo", "Alberto",
333  "Dave", "Ivan", "Johnnie", "Sidney", "Byron", "Julian",
334  "Isaac", "Morris", "Clifton", "Willard", "Daryl", "Ross",
335  "Virgil", "Andy", "Marshall", "Salvador", "Perry", "Kirk",
336  "Sergio", "Marion", "Tracy", "Seth", "Kent", "Terrance",
337  "Rene", "Eduardo", "Terrence", "Enrique", "Freddie", "Wade"
338  };
344 //
345 //
346 //************************************************************************
347 //Free Function Section
348 
349 void ClearScreen
350 (
351  int numLines = 25 //in
352 );
365 (
366  const string& programmerInfo = DEFAULT_PROGRAMMER_INFO, //in
367  const string& programInfo = DEFAULT_PROGRAM_INFO, //in
368  int numBlankLinesBefore = 11, //in
369  int numBlankLinesAfter = 12 //in
370 );
416 void DisplayTextfile
417 (
418  const string& fileName, //in
419  int numberOfLinesPerPause = 23 //in
420 );
468 int gcd
469 (
470  int a, //in
471  int b //in
472 );
486 bool isEven
487 (
488  int n //in
489 );
499 bool isOdd
500 (
501  int n //in
502 );
512 int numberOfDigits
513 (
514  int n //in
515 );
525 void Pause
526 (
527  int indentLevel = 0, //in
528  string message = "", //in
529  int pauseNumber = 0 //in
530 );
570 void ReadChar
571 (
572  const string& userPrompt, //in
573  char& charValue //out
574 );
592 void ReadDouble
593 (
594  const string& userPrompt, //in
595  double& doubleValue //out
596 );
620 void ReadInt
621 (
622  const string& userPrompt, //in
623  int& intValue //out
624 );
648 void ReadThisLine
649 (
650  const string& userPrompt, //in
651  string& lineValue //out
652 );
670 void ReadNextLine
671 (
672  const string& userPrompt, //in
673  string& lineValue //out
674 );
694 void ReadString
695 (
696  const string& userPrompt, //in
697  string& stringValue //out
698 );
714 bool userSaysYes
715 (
716  const string& question //in
717 );
741 //
742 //
743 //************************************************************************
744 //Utility Class Section
745 
746 class Menu
758 {
759 public:
760 
761  Menu();
770  Menu
771  (
772  const string& menuTitle //in
773  );
798  void setTitle
799  (
800  const string& menuTitle //in
801  );
826  void addOption
827  (
828  const string& option //in
829  );
863  void display() const;
887  int getChoice
888  (
889  int maxNumTries = 3, //in
890  string userPrompt =
891  "Enter the number of your menu choice here and press Enter: " //in
892  ) const;
941 private:
942  static const int MAX_NUM_OPTIONS = 20;
943  static const int MAX_OPTION_LENGTH = 70;
944  static const int MAX_TITLE_LENGTH = 70;
945 
946  int numOptions;
947  //Number of options currently on the menu.
948 
949  vector<string> menuText;
950  //Contains the title and the options
951  //Both constructors set the size of menuText to 1+MAX_NUM_OPTIONS,
952  //which includes one row to hold the menu title, and MAX_NUM_OPTIONS
953  //rows to hold the options.
954 };
955 
956 
969 {
970 public:
971 
982  void reset();
994  (
995  int numTimes = 1 //in
996  );
1010  (
1011  int numTimes = 1 //in
1012  );
1024  void incrementExchanges
1025  (
1026  int numTimes = 1 //in
1027  );
1039  void incrementOtherOp
1040  (
1041  int numTimes = 1 //in
1042  );
1054  int getNumberOfComparisons() const;
1063  int getNumberOfExchanges() const;
1072  int getNumberOfAssignments() const;
1081  int getNumberOfOtherOp() const;
1090  void setNameOfOtherOp
1091  (
1092  string nameOfOtherOp //in
1093  );
1104  string getNameOfOtherOp() const;
1115  void displayNonZeroCounts() const;
1145  void displayAllCounts() const;
1169 private:
1170  int numComparisons;
1171  int numExchanges;
1172  int numAssignments;
1173  int numOtherOp;
1174  string nameOfOtherOp;
1175 };
1176 
1177 
1178 
1189 {
1190 public:
1191 
1192  RandomGenerator();
1205  (
1206  int userSeedValue //in
1207  );
1225  void reset();
1236  void reset
1237  (
1238  int userSeedValue //in
1239  );
1249  //
1250  //
1251  //********** Random int generators **********
1252  int getNext
1253  (
1254  int n //in
1255  );
1266  int getNextInt
1267  (
1268  int n //in
1269  );
1277  int getNext
1278  (
1279  int low, //in
1280  int high //in
1281  );
1294  int getNextInt
1295  (
1296  int low, //in
1297  int high //in
1298  );
1306  //
1307  //
1308  //********** Random double generators **********
1309  double getNext
1310  (
1311  double x //in
1312  );
1323  double getNextDouble
1324  (
1325  double x //in
1326  );
1334  double getNext
1335  (
1336  double low, //in
1337  double high //in
1338  );
1352  double getNextDouble
1353  (
1354  double low, //in
1355  double high //in
1356  );
1364  //
1365  //
1366  //********** Random string generators **********
1367  string getNext
1368  (
1369  const string& s //in
1370  );
1396  string getNextString
1397  (
1398  const string& s //in
1399  );
1407  string getNext
1408  (
1409  const string& first, //in
1410  const string& second //in
1411  );
1433  string getNextString
1434  (
1435  const string& first, //in
1436  const string& second //in
1437  );
1445  //
1446  //
1447  //********** Auxiliary random string generators **********
1448  //These are public since they may also be useful to class clients.
1450  (
1451  int size, //in
1452  char firstChar, //in
1453  char lastChar //in
1454  );
1471  (
1472  int size, //in
1473  const string& source //in
1474  );
1489 private:
1490  int seed;
1491  void my_srand(int& seed);
1492  int my_rand();
1493 };
1494 
1495 
1496 
1505 {
1506 public:
1507 
1508  Stopwatch();
1515  Stopwatch
1516  (
1517  const string nameOfEventToBeTimed //in
1518  );
1526  void setEventName
1527  (
1528  const string nameOfEventToBeTimed //in
1529  );
1539  string getEventName() const;
1548  void start();
1559  void stop();
1569  void delay
1570  (
1571  int delayFactor = 1 //in
1572  ) const;
1598  clock_t getTicks() const;
1611  double getSeconds() const;
1624  double getMinutes() const;
1637  double getHours() const;
1650  void display() const;
1670 private:
1671  clock_t numClockTicksPassed;
1672  string eventName;
1673 };
1674 
1675 
1739 {
1740 public:
1741 
1742  TextItems();
1759  TextItems
1760  (
1761  const string fileName //in
1762  );
1795  void displayItem
1796  (
1797  const string title //in
1798  ) const;
1813 private:
1814  vector< vector<string> > itemList;
1815 };
1816 
1817 
1818 //DisplayOpeningScreen free function
1819 //********************************************************************
1820 inline void DisplayOpeningScreen
1822  const string& programmerInfo, //in
1823  const string& programInfo, //in
1824  int numBlankLinesBefore, //in
1825  int numBlankLinesAfter //in
1826 )
1827 {
1828  string blankLinesBefore(numBlankLinesBefore, '\n'),
1829  blankLinesAfter(numBlankLinesAfter, '\n');
1830  cout << blankLinesBefore
1831  << programmerInfo
1832  << programInfo
1833  << "\nThe main driver of this executable was built on "
1834  << __DATE__ << " at " << __TIME__ << ".\n"
1835  << blankLinesAfter;
1836  Pause();
1837 }
1838 
1839 } //End of this part of namespace Scobey
1840 
1841 #endif
void ReadThisLine(const string &userPrompt, string &lineValue)
Reads the text entered by a user on the same line as the prompt.
Definition: utilities.cpp:285
int gcd(int a, int b)
Finds the greatest common divisor of two nonnegative integers, at least one of which is strictly posi...
Definition: utilities.cpp:131
double getSeconds() const
Gets the number of seconds between the last calls of start() and stop().
Definition: utilities.cpp:996
bool isEven(int n)
Determines if a positive integer is even.
Definition: utilities.cpp:150
int getNextInt(int n)
Same as getNext(int n) above, but with a more explicit name, for readability rather than for ease of ...
Definition: utilities.cpp:739
const string NAMES_FEMALE[]
Provides 300 female first names, ranked in order of frequency as found in the United States of Americ...
Definition: utilities.h:229
void ReadNextLine(const string &userPrompt, string &lineValue)
Reads the text entered by a user on the line following the prompt.
Definition: utilities.cpp:275
void setEventName(const string nameOfEventToBeTimed)
Sets, or resets, the name of the event to be timed.
Definition: utilities.cpp:947
void DisplayTextfile(const string &fileName, int numberOfLinesPerPause=23)
Displays a file of text numberOfLinesPerPause lines at a time.
Definition: utilities.cpp:87
char String80[81]
Provides a legacy C-string type for holding up to 80 characters of text.
Definition: utilities.h:106
void displayAllCounts() const
Displays a summary of the number of operations counted.
Definition: utilities.cpp:643
void incrementComparisons(int numTimes=1)
Increments the counter for the number of comparison operations.
Definition: utilities.cpp:558
const string CARD_DECK[]
Provides 2-character representations of each of the fifty-two cards in a standard deck of cards...
Definition: utilities.h:116
Menu()
Default constructor; creates a &quot;blank&quot; menu.
Definition: utilities.cpp:327
const string DEFAULT_PROGRAMMER_INFO
Provides a placeholder value for programmer identification information.
Definition: utilities.h:157
const string DAYS_OF_THE_WEEK_SHORT[]
Provides 3-letter abbreviations for days of the week.
Definition: utilities.h:141
double getNextDouble(double x)
Same as getNext(double x) above, but with a more explicit name, for readability rather than for ease ...
Definition: utilities.cpp:777
TextItems()
Default constructor.
Definition: utilities.cpp:1047
int getNext(int n)
Gets a pseudorandom integer in the range [0,n).
Definition: utilities.cpp:720
int getNumberOfOtherOp() const
Gets the number of &quot;other&quot; operations performed.
Definition: utilities.cpp:602
For displaying menus and getting user menu choices in console applications.
Definition: utilities.h:746
void start()
Causes the stopwatch to start running.
Definition: utilities.cpp:961
int getNumberOfComparisons() const
Gets the number of comparison operations counted.
Definition: utilities.cpp:584
const string NAMES_3CHAR[]
Provides fifty 3-character first names, some male and some female, in alphabetical order...
Definition: utilities.h:183
clock_t getTicks() const
Gets the number of clock ticks between the most recent calls of start() and stop().
Definition: utilities.cpp:990
void display() const
Displays the time, in hours (as an integer value), minutes (as an integer value), and seconds (as a d...
Definition: utilities.cpp:1014
const string NAMES_FAMILY[]
Provides 100 family names (surnames), ranked in order of frequency as found in the United States of A...
Definition: utilities.h:201
void setTitle(const string &menuTitle)
Sets (or resets) the menu title.
Definition: utilities.cpp:359
double getHours() const
Gets the number of hours between the last calls of start() and stop().
Definition: utilities.cpp:1008
RandomGenerator()
Default constructor, based on seed obtained from a call to the time() function.
Definition: utilities.cpp:683
void reset()
Resets all operation counters to zero and the name of the &quot;other&quot; operation, if any, to an empty string.
Definition: utilities.cpp:538
void incrementAssignments(int numTimes=1)
Increments the counter for the number of assignment operations.
Definition: utilities.cpp:549
string getNextStringFromCharRange(int size, char firstChar, char lastChar)
Gets a pseudorandom string containing size characters from the character range [firstChar,secondChar].
Definition: utilities.cpp:898
void setNameOfOtherOp(string nameOfOtherOp)
Sets (or resets) the name of the &quot;other&quot; operation.
Definition: utilities.cpp:609
int getNumberOfAssignments() const
Gets the number of assignment operations counted.
Definition: utilities.cpp:596
const string MONTHS_OF_THE_YEAR_LONG[]
Provides full names for months of the year.
Definition: utilities.h:164
bool isOdd(int n)
Determines if a positive integer is odd.
Definition: utilities.cpp:161
int getChoice(int maxNumTries=3, string userPrompt="Enter the number of your menu choice here and press Enter: ") const
Gets a menu choice from the user, or a default value if the user fails to enter a valid menu choice b...
Definition: utilities.cpp:473
double getMinutes() const
Gets the number of minutes between the last calls of start() and stop().
Definition: utilities.cpp:1002
string getNameOfOtherOp() const
Gets the name of the &quot;other&quot; operation.
Definition: utilities.cpp:617
void incrementOtherOp(int numTimes=1)
Increments the counter for the number of &quot;other&quot; operations.
Definition: utilities.cpp:576
string getNextStringFromString(int size, const string &source)
Gets a pseudorandom string containing size characters taken from the string s.
Definition: utilities.cpp:914
For counting operations performed by an algorithm.
Definition: utilities.h:957
For measuring the time taken by an algorithm to perform its task.
Definition: utilities.h:1497
void ClearScreen(int numLines=25)
Clears the screen (the default output stream, which is assumed by default to have 25 lines)...
Definition: utilities.cpp:75
OperationCounter()
Default constructor.
Definition: utilities.cpp:533
bool userSaysYes(const string &question)
Gets the user&#39;s yes-or-no answer to a single question.
Definition: utilities.cpp:308
void display() const
Displays a &quot;centered&quot; menu on the screen.
Definition: utilities.cpp:427
void displayNonZeroCounts() const
Displays a summary of the counts for all operations actually performed (and which therefore have non-...
Definition: utilities.cpp:623
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.
Definition: utilities.h:1821
string getEventName() const
Gets the current name of the event to be timed.
Definition: utilities.cpp:955
int numberOfDigits(int n)
Finds the number of digits in a positive integer.
Definition: utilities.cpp:172
void addOption(const string &option)
Adds a new option to the menu and assigns it the next available option number.
Definition: utilities.cpp:380
void reset()
Resets the random generator using a seed obtained by a call to the time() function.
Definition: utilities.cpp:700
int getNumberOfExchanges() const
Gets the number of exchange operations counted.
Definition: utilities.cpp:590
void displayItem(const string title) const
Displays a text item on the standard output.
Definition: utilities.cpp:1125
void ReadInt(const string &userPrompt, int &intValue)
Gets an integer (int) value from the user.
Definition: utilities.cpp:257
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...
Definition: utilities.cpp:189
For displaying on-line help and other text messages in console applications.
Definition: utilities.h:1676
For generating pseudorandom integer, real, character and string values.
Definition: utilities.h:1179
void ReadString(const string &userPrompt, string &stringValue)
Gets a whitespace-delimited string value from the user.
Definition: utilities.cpp:295
const string MONTHS_OF_THE_YEAR_SHORT[]
Provides 3-letter abbreviations for months of the year.
Definition: utilities.h:174
const string NAMES_MALE[]
A named constant containing 300 male first names, 6 per line, ranked in order of frequency as found i...
Definition: utilities.h:287
void delay(int delayFactor=1) const
Adds some multiple of an artifical amount of time to the accumulated time on the stopwatch.
Definition: utilities.cpp:974
const string DAYS_OF_THE_WEEK_LONG[]
Provides full names for days of the week.
Definition: utilities.h:132
Stopwatch()
Default constructor.
Definition: utilities.cpp:930
void incrementExchanges(int numTimes=1)
Increments the counter for the number of exchange operations.
Definition: utilities.cpp:567
void ReadChar(const string &userPrompt, char &charValue)
Gets a character (char) value from the user.
Definition: utilities.cpp:209
string getNextString(const string &s)
Same as getNext(const string&amp; s) above, but with a more explicit name, for readability rather than fo...
Definition: utilities.cpp:877
void stop()
Causes the stopwatch to stop running.
Definition: utilities.cpp:967
const string DEFAULT_PROGRAM_INFO
Provides a placeholder value for a program title or brief description.
Definition: utilities.h:150
void ReadDouble(const string &userPrompt, double &doubleValue)
Gets a real (double) value from the user.
Definition: utilities.cpp:229