Utilities Package Version 2013.0
|
00001 00086 #ifndef UTILITIES_H 00087 #define UTILITIES_H 00088 00089 #include <cstdlib> 00090 #include <ctime> 00091 #include <string> 00092 #include <vector> 00093 using std::cout; 00094 using std::string; 00095 using std::vector; 00096 00101 namespace Scobey 00102 { 00103 00104 //************************************************************************ 00105 //Typedef Section 00106 00107 typedef char String80[81]; 00112 // 00113 // 00114 //************************************************************************ 00115 //Named Constant Section 00116 00117 const string CARD_DECK[] = 00118 { "AS", "2S", "3S", "4S", "5S", "6S", "7S", 00119 "8S", "9S", "TS", "JS", "QS", "KS", 00120 "AH", "2H", "3H", "4H", "5H", "6H", "7H", 00121 "8H", "9H", "TH", "JH", "QH", "KH", 00122 "AD", "2D", "3D", "4D", "5D", "6D", "7D", 00123 "8D", "9D", "TD", "JD", "QD", "KD", 00124 "AC", "2C", "3C", "4C", "5C", "6C", "7C", 00125 "8C", "9C", "TC", "JC", "QC", "KC" 00126 }; 00133 const string DAYS_OF_THE_WEEK_LONG[] = 00134 { "Monday", "Tuesday", "Wednesday", "Thursday", 00135 "Friday", "Saturday", "Sunday" 00136 }; 00142 const string DAYS_OF_THE_WEEK_SHORT[] = 00143 { "Mon", "Tue", "Wed", "Thu", 00144 "Fri", "Sat", "Sun" 00145 }; 00151 const string DEFAULT_PROGRAM_INFO = 00152 "Descriptive text required here is specificed elsewhere."; 00158 const string DEFAULT_PROGRAMMER_INFO = 00159 "Lastname:Firstname:A00123456:CSC?????"; 00165 const string MONTHS_OF_THE_YEAR_LONG[] = 00166 { "January", "February", "March", "April", 00167 "May", "June", "July", "August", 00168 "September", "October", "November", "December" 00169 }; 00175 const string MONTHS_OF_THE_YEAR_SHORT[] = 00176 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 00177 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 00178 }; 00184 const string NAMES_3CHAR[] = 00185 { "Ace", "Ali", "Amy", "Ann", "Art", 00186 "Ben", "Bob", "Cal", "Dan", "Del", 00187 "Don", "Dot", "Eva", "Eve", "Fay", 00188 "Gil", "Guy", "Hal", "Ian", "Jan", 00189 "Jim", "Jon", "Kay", "Ken", "Kim", 00190 "Liz", "Mac", "Min", "Nan", "Ora", 00191 "Pam", "Red", "Rex", "Rik", "Rip", 00192 "Rob", "Rod", "Rog", "Ron", "Roy", 00193 "Sal", "Sam", "Sue", "Tad", "Tim", 00194 "Tom", "Uma", "Val", "Wes", "Zig" 00195 }; 00202 const string NAMES_FAMILY[] = 00203 { "Smith", "Johnson", "Williams", "Brown", "Jones", 00204 "Miller", "Davis", "Garcia", "Rodriguez", "Wilson", 00205 "Martinez", "Anderson", "Taylor", "Thomas", "Hernandez", 00206 "Moore", "Martin", "Jackson", "Thompson", "White", 00207 "Lopez", "Le", "Gonzalez", "Harris", "Clark", 00208 "Lewis", "Robinson", "Walker", "Perez", "Hall", 00209 "Young", "Allen", "Sanchez", "Wright", "King", 00210 "Scott", "Green", "Baker", "Adams", "Nelson", 00211 "Hill", "Ramirez", "Campbell", "Mitchell", "Roberts", 00212 "Carter", "Phillips", "Evans", "Turner", "Torres", 00213 "Parker", "Collins", "Edwards", "Stewart", "Flores", 00214 "Morris", "Nguyen", "Murphy", "Rivera", "Cook", 00215 "Rogers", "Morgan", "Peterson", "Cooper", "Reed", 00216 "Bailey", "Bell", "Gomez", "Kelly", "Howard", 00217 "Ward", "Cox", "Diaz", "Richardson", "Wood", 00218 "Watson", "Brooks", "Bennett", "Gray", "James", 00219 "Reyes", "Cruz", "Hughes", "Price", "Myers", 00220 "Long", "Foster", "Sanders", "Ross", "Morales", 00221 "Powell", "Sullivan", "Russell", "Ortiz", "Jenkins", 00222 "Gutierrez", "Perry", "Butler", "Barnes", "Fisher" 00223 }; 00230 const string NAMES_FEMALE[] = 00231 { "Mary", "Patricia", "Linda", "Barbara", "Elizabeth", "Jennifer", 00232 "Maria", "Susan", "Margaret", "Dorothy", "Lisa", "Nancy", 00233 "Karen", "Betty", "Helen", "Sandra", "Donna", "Carol", 00234 "Ruth", "Sharon", "Michelle", "Laura", "Sarah", "Kimberly", 00235 "Deborah", "Jessica", "Shirley", "Cynthia", "Angela", "Melissa", 00236 "Brenda", "Amy", "Anna", "Rebecca", "Virginia", "Kathleen", 00237 "Pamela", "Martha", "Debra", "Amanda", "Stephanie", "Carolyn", 00238 "Christine", "Marie", "Janet", "Catherine", "Frances", "Ann", 00239 "Joyce", "Diane", "Alice", "Julie", "Heather", "Teresa", 00240 "Doris", "Gloria", "Evelyn", "Jean", "Cheryl", "Mildred", 00241 "Katherine", "Joan", "Ashley", "Judith", "Rose", "Janice", 00242 "Kelly", "Nicole", "Judy", "Christina", "Kathy", "Theresa", 00243 "Beverly", "Denise", "Tammy", "Irene", "Jane", "Lori", 00244 "Rachel", "Marilyn", "Andrea", "Kathryn", "Louise", "Sara", 00245 "Anne", "Jacqueline", "Wanda", "Bonnie", "Julia", "Ruby", 00246 "Lois", "Tina", "Phyllis", "Norma", "Paula", "Diana", 00247 "Annie", "Lillian", "Emily", "Robin", "Peggy", "Crystal", 00248 "Gladys", "Rita", "Dawn", "Connie", "Florence", "Tracy", 00249 "Edna", "Tiffany", "Carmen", "Rosa", "Cindy", "Grace", 00250 "Wendy", "Victoria", "Edith", "Kim", "Sherry", "Sylvia", 00251 "Josephine", "Thelma", "Shannon", "Sheila", "Ethel", "Ellen", 00252 "Elaine", "Marjorie", "Carrie", "Charlotte", "Monica", "Esther", 00253 "Pauline", "Emma", "Juanita", "Anita", "Rhonda", "Hazel", 00254 "Amber", "Eva", "Debbie", "April", "Leslie", "Clara", 00255 "Lucille", "Jamie", "Joanne", "Eleanor", "Valerie", "Danielle", 00256 "Megan", "Alicia", "Suzanne", "Michele", "Gail", "Bertha", 00257 "Darlene", "Veronica", "Jill", "Erin", "Geraldine", "Lauren", 00258 "Cathy", "Joann", "Lorraine", "Lynn", "Sally", "Regina", 00259 "Erica", "Beatrice", "Dolores", "Bernice", "Audrey", "Yvonne", 00260 "Annette", "June", "Samantha", "Marion", "Dana", "Stacy", 00261 "Ana", "Renee", "Ida", "Vivian", "Roberta", "Holly", 00262 "Brittany", "Melanie", "Loretta", "Yolanda", "Jeanette", "Laurie", 00263 "Katie", "Kristen", "Vanessa", "Alma", "Sue", "Elsie", 00264 "Beth", "Jeanne", "Vicki", "Carla", "Tara", "Rosemary", 00265 "Eileen", "Terri", "Gertrude", "Lucy", "Tonya", "Ella", 00266 "Stacey", "Wilma", "Gina", "Kristin", "Jessie", "Natalie", 00267 "Agnes", "Vera", "Willie", "Charlene", "Bessie", "Delores", 00268 "Melinda", "Pearl", "Arlene", "Maureen", "Colleen", "Allison", 00269 "Tamara", "Joy", "Georgia", "Constance", "Lillie", "Claudia", 00270 "Jackie", "Marcia", "Tanya", "Nellie", "Minnie", "Marlene", 00271 "Heidi", "Glenda", "Lydia", "Viola", "Courtney", "Marian", 00272 "Stella", "Caroline", "Dora", "Jo", "Vickie", "Mattie", 00273 "Terry", "Maxine", "Irma", "Mabel", "Marsha", "Myrtle", 00274 "Lena", "Christy", "Deanna", "Patsy", "Hilda", "Gwendolyn", 00275 "Jennie", "Nora", "Margie", "Nina", "Cassandra", "Leah", 00276 "Penny", "Kay", "Priscilla", "Naomi", "Carole", "Brandy", 00277 "Olga", "Billie", "Dianne", "Tracey", "Leona", "Jenny", 00278 "Felicia", "Sonia", "Miriam", "Velma", "Becky", "Bobbie", 00279 "Violet", "Kristina", "Toni", "Misty", "Mae", "Shelly", 00280 "Daisy", "Ramona", "Sherri", "Erika", "Katrina", "Claire" 00281 }; 00288 const string NAMES_MALE[] = 00289 { "James", "John", "Robert", "Michael", "William", "David", 00290 "Richard", "Charles", "Joseph", "Thomas", "Christopher", "Daniel", 00291 "Paul", "Mark", "Donald", "George", "Kenneth", "Steven", 00292 "Edward", "Brian", "Ronald", "Anthony", "Kevin", "Jason", 00293 "Matthew", "Gary", "Timothy", "Jose", "Larry", "Jeffrey", 00294 "Frank", "Scott", "Eric", "Stephen", "Andrew", "Raymond", 00295 "Gregory", "Joshua", "Jerry", "Dennis", "Walter", "Patrick", 00296 "Peter", "Harold", "Douglas", "Henry", "Carl", "Arthur", 00297 "Ryan", "Roger", "Joe", "Juan", "Jack", "Albert", 00298 "Jonathan", "Justin", "Terry", "Gerald", "Keith", "Samuel", 00299 "Willie", "Ralph", "Lawrence", "Nicholas", "Roy", "Benjamin", 00300 "Bruce", "Brandon", "Adam", "Harry", "Fred", "Wayne", 00301 "Billy", "Steve", "Louis", "Jeremy", "Aaron", "Randy", 00302 "Howard", "Eugene", "Carlos", "Russell", "Bobby", "Victor", 00303 "Martin", "Ernest", "Phillip", "Todd", "Jesse", "Craig", 00304 "Alan", "Shawn", "Clarence", "Sean", "Philip", "Chris", 00305 "Johnny", "Earl", "Jimmy", "Antonio", "Danny", "Bryan", 00306 "Tony", "Luis", "Mike", "Stanley", "Leonard", "Nathan", 00307 "Dale", "Manuel", "Rodney", "Curtis", "Norman", "Allen", 00308 "Marvin", "Vincent", "Glenn", "Jeffery", "Travis", "Jeff", 00309 "Chad", "Jacob", "Lee", "Melvin", "Alfred", "Kyle", 00310 "Francis", "Bradley", "Jesus", "Herbert", "Frederick", "Ray", 00311 "Joel", "Edwin", "Don", "Eddie", "Ricky", "Troy", 00312 "Randall", "Barry", "Alexander", "Bernard", "Mario", "Leroy", 00313 "Francisco", "Marcus", "Micheal", "Theodore", "Clifford", "Miguel", 00314 "Oscar", "Jay", "Jim", "Tom", "Calvin", "Alex", 00315 "Jon", "Ronnie", "Bill", "Lloyd", "Tommy", "Leon", 00316 "Derek", "Warren", "Darrell", "Jerome", "Floyd", "Leo", 00317 "Alvin", "Tim", "Wesley", "Gordon", "Dean", "Greg", 00318 "Jorge", "Dustin", "Pedro", "Derrick", "Dan", "Lewis", 00319 "Zachary", "Corey", "Herman", "Maurice", "Vernon", "Roberto", 00320 "Clyde", "Glen", "Hector", "Shane", "Ricardo", "Sam", 00321 "Rick", "Lester", "Brent", "Ramon", "Charlie", "Tyler", 00322 "Gilbert", "Gene", "Marc", "Reginald", "Ruben", "Brett", 00323 "Angel", "Nathaniel", "Rafael", "Leslie", "Edgar", "Milton", 00324 "Raul", "Ben", "Chester", "Cecil", "Duane", "Franklin", 00325 "Andre", "Elmer", "Brad", "Gabriel", "Ron", "Mitchell", 00326 "Roland", "Arnold", "Harvey", "Jared", "Adrian", "Karl", 00327 "Cory", "Claude", "Erik", "Darryl", "Jamie", "Neil", 00328 "Jessie", "Christian", "Javier", "Fernando", "Clinton", "Ted", 00329 "Mathew", "Tyrone", "Darren", "Lonnie", "Lance", "Cody", 00330 "Julio", "Kelly", "Kurt", "Allan", "Nelson", "Guy", 00331 "Clayton", "Hugh", "Max", "Dwayne", "Dwight", "Armando", 00332 "Felix", "Jimmie", "Everett", "Jordan", "Ian", "Wallace", 00333 "Ken", "Bob", "Jaime", "Casey", "Alfredo", "Alberto", 00334 "Dave", "Ivan", "Johnnie", "Sidney", "Byron", "Julian", 00335 "Isaac", "Morris", "Clifton", "Willard", "Daryl", "Ross", 00336 "Virgil", "Andy", "Marshall", "Salvador", "Perry", "Kirk", 00337 "Sergio", "Marion", "Tracy", "Seth", "Kent", "Terrance", 00338 "Rene", "Eduardo", "Terrence", "Enrique", "Freddie", "Wade" 00339 }; 00345 // 00346 // 00347 //************************************************************************ 00348 //Free Function Section 00349 00350 void ClearScreen 00351 ( 00352 int numLines = 25 //in 00353 ); 00365 void DisplayOpeningScreen 00366 ( 00367 const string& programmerInfo = DEFAULT_PROGRAMMER_INFO, //in 00368 const string& programInfo = DEFAULT_PROGRAM_INFO, //in 00369 int numBlankLinesBefore = 11, //in 00370 int numBlankLinesAfter = 12 //in 00371 ); 00417 void DisplayTextfile 00418 ( 00419 const string& fileName, //in 00420 int numberOfLinesPerPause = 23 //in 00421 ); 00469 int gcd 00470 ( 00471 int a, //in 00472 int b //in 00473 ); 00487 bool isEven 00488 ( 00489 int n //in 00490 ); 00500 bool isOdd 00501 ( 00502 int n //in 00503 ); 00513 int numberOfDigits 00514 ( 00515 int n //in 00516 ); 00526 void Pause 00527 ( 00528 int indentLevel = 0, //in 00529 string message = "", //in 00530 int pauseNumber = 0 //in 00531 ); 00571 void ReadChar 00572 ( 00573 const string& userPrompt, //in 00574 char& charValue //out 00575 ); 00591 void ReadDouble 00592 ( 00593 const string& userPrompt, //in 00594 double& doubleValue //out 00595 ); 00619 void ReadInt 00620 ( 00621 const string& userPrompt, //in 00622 int& intValue //out 00623 ); 00647 void ReadThisLine 00648 ( 00649 const string& userPrompt, //in 00650 string& lineValue //out 00651 ); 00669 void ReadNextLine 00670 ( 00671 const string& userPrompt, //in 00672 string& lineValue //out 00673 ); 00693 void ReadString 00694 ( 00695 const string& userPrompt, //in 00696 string& stringValue //out 00697 ); 00713 bool userSaysYes 00714 ( 00715 const string& question //in 00716 ); 00740 // 00741 // 00742 //************************************************************************ 00743 //Utility Class Section 00744 00745 class Menu 00757 { 00758 public: 00759 00760 Menu(); 00769 Menu 00770 ( 00771 const string& menuTitle //in 00772 ); 00797 void setTitle 00798 ( 00799 const string& menuTitle //in 00800 ); 00825 void addOption 00826 ( 00827 const string& option //in 00828 ); 00862 void display() const; 00886 int getChoice 00887 ( 00888 int maxNumTries = 3, //in 00889 string userPrompt = 00890 "Enter the number of your menu choice here and press Enter: " //in 00891 ) const; 00940 private: 00941 static const int MAX_NUM_OPTIONS = 20; 00942 static const int MAX_OPTION_LENGTH = 70; 00943 static const int MAX_TITLE_LENGTH = 70; 00944 00945 int numOptions; 00946 //Number of options currently on the menu. 00947 00948 vector<string> menuText; 00949 //Contains the title and the options 00950 //Both constructors set the size of menuText to 1+MAX_NUM_OPTIONS, 00951 //which includes one row to hold the menu title, and MAX_NUM_OPTIONS 00952 //rows to hold the options. 00953 }; 00954 00955 00956 class OperationCounter 00968 { 00969 public: 00970 00971 OperationCounter(); 00981 void reset(); 00992 void incrementAssignments 00993 ( 00994 int numTimes = 1 //in 00995 ); 01008 void incrementComparisons 01009 ( 01010 int numTimes = 1 //in 01011 ); 01023 void incrementExchanges 01024 ( 01025 int numTimes = 1 //in 01026 ); 01038 void incrementOtherOp 01039 ( 01040 int numTimes = 1 //in 01041 ); 01053 int getNumberOfComparisons() const; 01062 int getNumberOfExchanges() const; 01071 int getNumberOfAssignments() const; 01080 int getNumberOfOtherOp() const; 01089 void setNameOfOtherOp 01090 ( 01091 string nameOfOtherOp //in 01092 ); 01103 string getNameOfOtherOp() const; 01114 void displayNonZeroCounts() const; 01144 void displayAllCounts() const; 01168 private: 01169 int numComparisons; 01170 int numExchanges; 01171 int numAssignments; 01172 int numOtherOp; 01173 string nameOfOtherOp; 01174 }; 01175 01176 01177 01178 class RandomGenerator 01188 { 01189 public: 01190 01191 RandomGenerator(); 01203 RandomGenerator 01204 ( 01205 int userSeedValue //in 01206 ); 01224 void reset(); 01235 void reset 01236 ( 01237 int userSeedValue //in 01238 ); 01248 // 01249 // 01250 //********** Random int generators ********** 01251 int getNext 01252 ( 01253 int n //in 01254 ); 01265 int getNextInt 01266 ( 01267 int n //in 01268 ); 01276 int getNext 01277 ( 01278 int low, //in 01279 int high //in 01280 ); 01293 int getNextInt 01294 ( 01295 int low, //in 01296 int high //in 01297 ); 01305 // 01306 // 01307 //********** Random double generators ********** 01308 double getNext 01309 ( 01310 double x //in 01311 ); 01322 double getNextDouble 01323 ( 01324 double x //in 01325 ); 01333 double getNext 01334 ( 01335 double low, //in 01336 double high //in 01337 ); 01351 double getNextDouble 01352 ( 01353 double low, //in 01354 double high //in 01355 ); 01363 // 01364 // 01365 //********** Random string generators ********** 01366 string getNext 01367 ( 01368 const string& s //in 01369 ); 01395 string getNextString 01396 ( 01397 const string& s //in 01398 ); 01406 string getNext 01407 ( 01408 const string& first, //in 01409 const string& second //in 01410 ); 01432 string getNextString 01433 ( 01434 const string& first, //in 01435 const string& second //in 01436 ); 01444 // 01445 // 01446 //********** Auxiliary random string generators ********** 01447 //These are public since they may also be useful to class clients. 01448 string getNextStringFromCharRange 01449 ( 01450 int size, //in 01451 char firstChar, //in 01452 char lastChar //in 01453 ); 01469 string getNextStringFromString 01470 ( 01471 int size, //in 01472 const string& source //in 01473 ); 01488 private: 01489 int seed; 01490 void my_srand(int& seed); 01491 int my_rand(); 01492 }; 01493 01494 01495 01496 class Stopwatch 01504 { 01505 public: 01506 01507 Stopwatch(); 01514 Stopwatch 01515 ( 01516 const string nameOfEventToBeTimed //in 01517 ); 01525 void setEventName 01526 ( 01527 const string nameOfEventToBeTimed //in 01528 ); 01538 string getEventName() const; 01547 void start(); 01558 void stop(); 01568 void delay 01569 ( 01570 int delayFactor = 1 //in 01571 ) const; 01597 clock_t getTicks() const; 01610 double getSeconds() const; 01623 double getMinutes() const; 01636 double getHours() const; 01649 void display() const; 01669 private: 01670 clock_t numClockTicksPassed; 01671 string eventName; 01672 }; 01673 01674 01675 class TextItems 01738 { 01739 public: 01740 01741 TextItems(); 01758 TextItems 01759 ( 01760 const string fileName //in 01761 ); 01794 void displayItem 01795 ( 01796 const string title //in 01797 ) const; 01812 private: 01813 vector< vector<string> > itemList; 01814 }; 01815 01816 01817 //DisplayOpeningScreen free function 01818 //******************************************************************** 01819 inline void DisplayOpeningScreen 01820 ( 01821 const string& programmerInfo, //in 01822 const string& programInfo, //in 01823 int numBlankLinesBefore, //in 01824 int numBlankLinesAfter //in 01825 ) 01826 { 01827 string blankLinesBefore(numBlankLinesBefore, '\n'), 01828 blankLinesAfter(numBlankLinesAfter, '\n'); 01829 cout << blankLinesBefore 01830 << programmerInfo 01831 << "\nThis executable was built on " << __DATE__ 01832 << " at " << __TIME__ << ".\n" 01833 << programInfo 01834 << blankLinesAfter; 01835 Pause(); 01836 } 01837 01838 } //End of this part of namespace Scobey 01839 01840 #endif