Utilities Package (contained in namespace Scobey) Version 2011.0
For use with VS2010 |
00001 00108 #ifndef UTILITIES_H 00109 #define UTILITIES_H 00110 00111 #include <cstdlib> 00112 #include <ctime> 00113 #include <string> 00114 #include <vector> 00115 using std::cout; 00116 using std::string; 00117 using std::vector; 00118 00123 namespace Scobey 00124 { 00125 00126 //************************************************************************ 00127 //Typedef Section 00128 00129 typedef char String80[81]; 00134 // 00135 // 00136 //************************************************************************ 00137 //Named Constant Section 00138 00139 const string CARD_DECK[] = 00140 { "AS", "2S", "3S", "4S", "5S", "6S", "7S", 00141 "8S", "9S", "TS", "JS", "QS", "KS", 00142 "AH", "2H", "3H", "4H", "5H", "6H", "7H", 00143 "8H", "9H", "TH", "JH", "QH", "KH", 00144 "AD", "2D", "3D", "4D", "5D", "6D", "7D", 00145 "8D", "9D", "TD", "JD", "QD", "KD", 00146 "AC", "2C", "3C", "4C", "5C", "6C", "7C", 00147 "8C", "9C", "TC", "JC", "QC", "KC" 00148 }; 00155 const string DAYS_OF_THE_WEEK_LONG[] = 00156 { "Monday", "Tuesday", "Wednesday", "Thursday", 00157 "Friday", "Saturday", "Sunday" 00158 }; 00164 const string DAYS_OF_THE_WEEK_SHORT[] = 00165 { "Mon", "Tue", "Wed", "Thu", 00166 "Fri", "Sat", "Sun" 00167 }; 00173 const string DEFAULT_PROGRAM_INFO = 00174 "Descriptive text required here is specificed elsewhere."; 00180 const string DEFAULT_PROGRAMMER_INFO = 00181 "Lastname:Firstname:A00123456:CSC?????"; 00187 const string MONTHS_OF_THE_YEAR_LONG[] = 00188 { "January", "February", "March", "April", 00189 "May", "June", "July", "August", 00190 "September", "October", "November", "December" 00191 }; 00197 const string MONTHS_OF_THE_YEAR_SHORT[] = 00198 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 00199 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 00200 }; 00206 const string NAMES_3CHAR[] = 00207 { "Ace", "Ali", "Amy", "Ann", "Art", 00208 "Ben", "Bob", "Cal", "Dan", "Del", 00209 "Don", "Dot", "Eva", "Eve", "Fay", 00210 "Gil", "Guy", "Hal", "Ian", "Jan", 00211 "Jim", "Jon", "Kay", "Ken", "Kim", 00212 "Liz", "Mac", "Min", "Nan", "Ora", 00213 "Pam", "Red", "Rex", "Rik", "Rip", 00214 "Rob", "Rod", "Rog", "Ron", "Roy", 00215 "Sal", "Sam", "Sue", "Tad", "Tim", 00216 "Tom", "Uma", "Val", "Wes", "Zig" 00217 }; 00224 const string NAMES_FAMILY[] = 00225 { "Smith", "Johnson", "Williams", "Brown", "Jones", 00226 "Miller", "Davis", "Garcia", "Rodriguez", "Wilson", 00227 "Martinez", "Anderson", "Taylor", "Thomas", "Hernandez", 00228 "Moore", "Martin", "Jackson", "Thompson", "White", 00229 "Lopez", "Le", "Gonzalez", "Harris", "Clark", 00230 "Lewis", "Robinson", "Walker", "Perez", "Hall", 00231 "Young", "Allen", "Sanchez", "Wright", "King", 00232 "Scott", "Green", "Baker", "Adams", "Nelson", 00233 "Hill", "Ramirez", "Campbell", "Mitchell", "Roberts", 00234 "Carter", "Phillips", "Evans", "Turner", "Torres", 00235 "Parker", "Collins", "Edwards", "Stewart", "Flores", 00236 "Morris", "Nguyen", "Murphy", "Rivera", "Cook", 00237 "Rogers", "Morgan", "Peterson", "Cooper", "Reed", 00238 "Bailey", "Bell", "Gomez", "Kelly", "Howard", 00239 "Ward", "Cox", "Diaz", "Richardson", "Wood", 00240 "Watson", "Brooks", "Bennett", "Gray", "James", 00241 "Reyes", "Cruz", "Hughes", "Price", "Myers", 00242 "Long", "Foster", "Sanders", "Ross", "Morales", 00243 "Powell", "Sullivan", "Russell", "Ortiz", "Jenkins", 00244 "Gutierrez", "Perry", "Butler", "Barnes", "Fisher" 00245 }; 00252 const string NAMES_FEMALE[] = 00253 { "Mary", "Patricia", "Linda", "Barbara", "Elizabeth", "Jennifer", 00254 "Maria", "Susan", "Margaret", "Dorothy", "Lisa", "Nancy", 00255 "Karen", "Betty", "Helen", "Sandra", "Donna", "Carol", 00256 "Ruth", "Sharon", "Michelle", "Laura", "Sarah", "Kimberly", 00257 "Deborah", "Jessica", "Shirley", "Cynthia", "Angela", "Melissa", 00258 "Brenda", "Amy", "Anna", "Rebecca", "Virginia", "Kathleen", 00259 "Pamela", "Martha", "Debra", "Amanda", "Stephanie", "Carolyn", 00260 "Christine", "Marie", "Janet", "Catherine", "Frances", "Ann", 00261 "Joyce", "Diane", "Alice", "Julie", "Heather", "Teresa", 00262 "Doris", "Gloria", "Evelyn", "Jean", "Cheryl", "Mildred", 00263 "Katherine", "Joan", "Ashley", "Judith", "Rose", "Janice", 00264 "Kelly", "Nicole", "Judy", "Christina", "Kathy", "Theresa", 00265 "Beverly", "Denise", "Tammy", "Irene", "Jane", "Lori", 00266 "Rachel", "Marilyn", "Andrea", "Kathryn", "Louise", "Sara", 00267 "Anne", "Jacqueline", "Wanda", "Bonnie", "Julia", "Ruby", 00268 "Lois", "Tina", "Phyllis", "Norma", "Paula", "Diana", 00269 "Annie", "Lillian", "Emily", "Robin", "Peggy", "Crystal", 00270 "Gladys", "Rita", "Dawn", "Connie", "Florence", "Tracy", 00271 "Edna", "Tiffany", "Carmen", "Rosa", "Cindy", "Grace", 00272 "Wendy", "Victoria", "Edith", "Kim", "Sherry", "Sylvia", 00273 "Josephine", "Thelma", "Shannon", "Sheila", "Ethel", "Ellen", 00274 "Elaine", "Marjorie", "Carrie", "Charlotte", "Monica", "Esther", 00275 "Pauline", "Emma", "Juanita", "Anita", "Rhonda", "Hazel", 00276 "Amber", "Eva", "Debbie", "April", "Leslie", "Clara", 00277 "Lucille", "Jamie", "Joanne", "Eleanor", "Valerie", "Danielle", 00278 "Megan", "Alicia", "Suzanne", "Michele", "Gail", "Bertha", 00279 "Darlene", "Veronica", "Jill", "Erin", "Geraldine", "Lauren", 00280 "Cathy", "Joann", "Lorraine", "Lynn", "Sally", "Regina", 00281 "Erica", "Beatrice", "Dolores", "Bernice", "Audrey", "Yvonne", 00282 "Annette", "June", "Samantha", "Marion", "Dana", "Stacy", 00283 "Ana", "Renee", "Ida", "Vivian", "Roberta", "Holly", 00284 "Brittany", "Melanie", "Loretta", "Yolanda", "Jeanette", "Laurie", 00285 "Katie", "Kristen", "Vanessa", "Alma", "Sue", "Elsie", 00286 "Beth", "Jeanne", "Vicki", "Carla", "Tara", "Rosemary", 00287 "Eileen", "Terri", "Gertrude", "Lucy", "Tonya", "Ella", 00288 "Stacey", "Wilma", "Gina", "Kristin", "Jessie", "Natalie", 00289 "Agnes", "Vera", "Willie", "Charlene", "Bessie", "Delores", 00290 "Melinda", "Pearl", "Arlene", "Maureen", "Colleen", "Allison", 00291 "Tamara", "Joy", "Georgia", "Constance", "Lillie", "Claudia", 00292 "Jackie", "Marcia", "Tanya", "Nellie", "Minnie", "Marlene", 00293 "Heidi", "Glenda", "Lydia", "Viola", "Courtney", "Marian", 00294 "Stella", "Caroline", "Dora", "Jo", "Vickie", "Mattie", 00295 "Terry", "Maxine", "Irma", "Mabel", "Marsha", "Myrtle", 00296 "Lena", "Christy", "Deanna", "Patsy", "Hilda", "Gwendolyn", 00297 "Jennie", "Nora", "Margie", "Nina", "Cassandra", "Leah", 00298 "Penny", "Kay", "Priscilla", "Naomi", "Carole", "Brandy", 00299 "Olga", "Billie", "Dianne", "Tracey", "Leona", "Jenny", 00300 "Felicia", "Sonia", "Miriam", "Velma", "Becky", "Bobbie", 00301 "Violet", "Kristina", "Toni", "Misty", "Mae", "Shelly", 00302 "Daisy", "Ramona", "Sherri", "Erika", "Katrina", "Claire" 00303 }; 00310 const string NAMES_MALE[] = 00311 { "James", "John", "Robert", "Michael", "William", "David", 00312 "Richard", "Charles", "Joseph", "Thomas", "Christopher", "Daniel", 00313 "Paul", "Mark", "Donald", "George", "Kenneth", "Steven", 00314 "Edward", "Brian", "Ronald", "Anthony", "Kevin", "Jason", 00315 "Matthew", "Gary", "Timothy", "Jose", "Larry", "Jeffrey", 00316 "Frank", "Scott", "Eric", "Stephen", "Andrew", "Raymond", 00317 "Gregory", "Joshua", "Jerry", "Dennis", "Walter", "Patrick", 00318 "Peter", "Harold", "Douglas", "Henry", "Carl", "Arthur", 00319 "Ryan", "Roger", "Joe", "Juan", "Jack", "Albert", 00320 "Jonathan", "Justin", "Terry", "Gerald", "Keith", "Samuel", 00321 "Willie", "Ralph", "Lawrence", "Nicholas", "Roy", "Benjamin", 00322 "Bruce", "Brandon", "Adam", "Harry", "Fred", "Wayne", 00323 "Billy", "Steve", "Louis", "Jeremy", "Aaron", "Randy", 00324 "Howard", "Eugene", "Carlos", "Russell", "Bobby", "Victor", 00325 "Martin", "Ernest", "Phillip", "Todd", "Jesse", "Craig", 00326 "Alan", "Shawn", "Clarence", "Sean", "Philip", "Chris", 00327 "Johnny", "Earl", "Jimmy", "Antonio", "Danny", "Bryan", 00328 "Tony", "Luis", "Mike", "Stanley", "Leonard", "Nathan", 00329 "Dale", "Manuel", "Rodney", "Curtis", "Norman", "Allen", 00330 "Marvin", "Vincent", "Glenn", "Jeffery", "Travis", "Jeff", 00331 "Chad", "Jacob", "Lee", "Melvin", "Alfred", "Kyle", 00332 "Francis", "Bradley", "Jesus", "Herbert", "Frederick", "Ray", 00333 "Joel", "Edwin", "Don", "Eddie", "Ricky", "Troy", 00334 "Randall", "Barry", "Alexander", "Bernard", "Mario", "Leroy", 00335 "Francisco", "Marcus", "Micheal", "Theodore", "Clifford", "Miguel", 00336 "Oscar", "Jay", "Jim", "Tom", "Calvin", "Alex", 00337 "Jon", "Ronnie", "Bill", "Lloyd", "Tommy", "Leon", 00338 "Derek", "Warren", "Darrell", "Jerome", "Floyd", "Leo", 00339 "Alvin", "Tim", "Wesley", "Gordon", "Dean", "Greg", 00340 "Jorge", "Dustin", "Pedro", "Derrick", "Dan", "Lewis", 00341 "Zachary", "Corey", "Herman", "Maurice", "Vernon", "Roberto", 00342 "Clyde", "Glen", "Hector", "Shane", "Ricardo", "Sam", 00343 "Rick", "Lester", "Brent", "Ramon", "Charlie", "Tyler", 00344 "Gilbert", "Gene", "Marc", "Reginald", "Ruben", "Brett", 00345 "Angel", "Nathaniel", "Rafael", "Leslie", "Edgar", "Milton", 00346 "Raul", "Ben", "Chester", "Cecil", "Duane", "Franklin", 00347 "Andre", "Elmer", "Brad", "Gabriel", "Ron", "Mitchell", 00348 "Roland", "Arnold", "Harvey", "Jared", "Adrian", "Karl", 00349 "Cory", "Claude", "Erik", "Darryl", "Jamie", "Neil", 00350 "Jessie", "Christian", "Javier", "Fernando", "Clinton", "Ted", 00351 "Mathew", "Tyrone", "Darren", "Lonnie", "Lance", "Cody", 00352 "Julio", "Kelly", "Kurt", "Allan", "Nelson", "Guy", 00353 "Clayton", "Hugh", "Max", "Dwayne", "Dwight", "Armando", 00354 "Felix", "Jimmie", "Everett", "Jordan", "Ian", "Wallace", 00355 "Ken", "Bob", "Jaime", "Casey", "Alfredo", "Alberto", 00356 "Dave", "Ivan", "Johnnie", "Sidney", "Byron", "Julian", 00357 "Isaac", "Morris", "Clifton", "Willard", "Daryl", "Ross", 00358 "Virgil", "Andy", "Marshall", "Salvador", "Perry", "Kirk", 00359 "Sergio", "Marion", "Tracy", "Seth", "Kent", "Terrance", 00360 "Rene", "Eduardo", "Terrence", "Enrique", "Freddie", "Wade" 00361 }; 00367 // 00368 // 00369 //************************************************************************ 00370 //Free Function Section 00371 00372 void ClearScreen 00373 ( 00374 int numLines = 25 //in 00375 ); 00387 void DisplayOpeningScreen 00388 ( 00389 const string& programmerInfo = DEFAULT_PROGRAMMER_INFO, //in 00390 const string& programInfo = DEFAULT_PROGRAM_INFO, //in 00391 int numBlankLinesBefore = 11, //in 00392 int numBlankLinesAfter = 12 //in 00393 ); 00439 void DisplayTextfile 00440 ( 00441 const string& fileName, //in 00442 int numberOfLinesPerPause = 23 //in 00443 ); 00491 int gcd 00492 ( 00493 int a, //in 00494 int b //in 00495 ); 00509 bool isEven 00510 ( 00511 int n //in 00512 ); 00522 bool isOdd 00523 ( 00524 int n //in 00525 ); 00535 int numberOfDigits 00536 ( 00537 int n //in 00538 ); 00548 void Pause 00549 ( 00550 int indentLevel = 0, //in 00551 string message = "", //in 00552 int pauseNumber = 0 //in 00553 ); 00593 void ReadChar 00594 ( 00595 const string& userPrompt, //in 00596 char& charValue //out 00597 ); 00613 void ReadDouble 00614 ( 00615 const string& userPrompt, //in 00616 double& doubleValue //out 00617 ); 00641 void ReadInt 00642 ( 00643 const string& userPrompt, //in 00644 int& intValue //out 00645 ); 00669 void ReadThisLine 00670 ( 00671 const string& userPrompt, //in 00672 string& lineValue //out 00673 ); 00691 void ReadNextLine 00692 ( 00693 const string& userPrompt, //in 00694 string& lineValue //out 00695 ); 00715 void ReadString 00716 ( 00717 const string& userPrompt, //in 00718 string& stringValue //out 00719 ); 00735 bool userSaysYes 00736 ( 00737 const string& question //in 00738 ); 00762 // 00763 // 00764 //************************************************************************ 00765 //Utility Class Section 00766 00767 class Menu 00779 { 00780 public: 00781 00782 Menu(); 00791 Menu 00792 ( 00793 const string& menuTitle //in 00794 ); 00819 void setTitle 00820 ( 00821 const string& menuTitle //in 00822 ); 00847 void addOption 00848 ( 00849 const string& option //in 00850 ); 00884 void display() const; 00908 int getChoice 00909 ( 00910 int maxNumTries = 3, //in 00911 string userPrompt = 00912 "Enter the number of your menu choice here and press Enter: " //in 00913 ) const; 00962 private: 00963 static const int MAX_NUM_OPTIONS = 20; 00964 static const int MAX_OPTION_LENGTH = 70; 00965 static const int MAX_TITLE_LENGTH = 70; 00966 00967 int numOptions; 00968 //Number of options currently on the menu. 00969 00970 vector<string> menuText; 00971 //Contains the title and the options 00972 //Both constructors set the size of menuText to 1+MAX_NUM_OPTIONS, 00973 //which includes one row to hold the menu title, and MAX_NUM_OPTIONS 00974 //rows to hold the options. 00975 }; 00976 00977 00978 class OperationCounter 00990 { 00991 public: 00992 00993 OperationCounter(); 01003 void reset(); 01014 void incrementAssignments 01015 ( 01016 int numTimes = 1 //in 01017 ); 01030 void incrementComparisons 01031 ( 01032 int numTimes = 1 //in 01033 ); 01045 void incrementExchanges 01046 ( 01047 int numTimes = 1 //in 01048 ); 01060 void incrementOtherOp 01061 ( 01062 int numTimes = 1 //in 01063 ); 01075 int getNumberOfComparisons() const; 01084 int getNumberOfExchanges() const; 01093 int getNumberOfAssignments() const; 01102 int getNumberOfOtherOp() const; 01111 void setNameOfOtherOp 01112 ( 01113 string nameOfOtherOp //in 01114 ); 01125 string getNameOfOtherOp() const; 01136 void displayNonZeroCounts() const; 01166 void displayAllCounts() const; 01190 private: 01191 int numComparisons; 01192 int numExchanges; 01193 int numAssignments; 01194 int numOtherOp; 01195 string nameOfOtherOp; 01196 }; 01197 01198 01199 01200 class RandomGenerator 01210 { 01211 public: 01212 01213 RandomGenerator(); 01225 RandomGenerator 01226 ( 01227 int userSeedValue //in 01228 ); 01246 void reset(); 01257 void reset 01258 ( 01259 int userSeedValue //in 01260 ); 01270 // 01271 // 01272 //********** Random int generators ********** 01273 int getNext 01274 ( 01275 int n //in 01276 ); 01287 int getNextInt 01288 ( 01289 int n //in 01290 ); 01298 int getNext 01299 ( 01300 int low, //in 01301 int high //in 01302 ); 01315 int getNextInt 01316 ( 01317 int low, //in 01318 int high //in 01319 ); 01327 // 01328 // 01329 //********** Random double generators ********** 01330 double getNext 01331 ( 01332 double x //in 01333 ); 01344 double getNextDouble 01345 ( 01346 double x //in 01347 ); 01355 double getNext 01356 ( 01357 double low, //in 01358 double high //in 01359 ); 01373 double getNextDouble 01374 ( 01375 double low, //in 01376 double high //in 01377 ); 01385 // 01386 // 01387 //********** Random string generators ********** 01388 string getNext 01389 ( 01390 const string& s //in 01391 ); 01417 string getNextString 01418 ( 01419 const string& s //in 01420 ); 01428 string getNext 01429 ( 01430 const string& first, //in 01431 const string& second //in 01432 ); 01454 string getNextString 01455 ( 01456 const string& first, //in 01457 const string& second //in 01458 ); 01466 // 01467 // 01468 //********** Auxiliary random string generators ********** 01469 //These are public since they may also be useful to class clients. 01470 string getNextStringFromCharRange 01471 ( 01472 int size, //in 01473 char firstChar, //in 01474 char lastChar //in 01475 ); 01491 string getNextStringFromString 01492 ( 01493 int size, //in 01494 const string& source //in 01495 ); 01510 private: 01511 int seed; 01512 void my_srand(int& seed); 01513 int my_rand(); 01514 }; 01515 01516 01517 01518 class Stopwatch 01526 { 01527 public: 01528 01529 Stopwatch(); 01536 Stopwatch 01537 ( 01538 const string nameOfEventToBeTimed //in 01539 ); 01547 void setEventName 01548 ( 01549 const string nameOfEventToBeTimed //in 01550 ); 01560 string getEventName() const; 01569 void start(); 01580 void stop(); 01590 void delay 01591 ( 01592 int delayFactor = 1 //in 01593 ) const; 01619 clock_t getTicks() const; 01632 double getSeconds() const; 01645 double getMinutes() const; 01658 double getHours() const; 01671 void display() const; 01691 private: 01692 clock_t numClockTicksPassed; 01693 string eventName; 01694 }; 01695 01696 01697 class TextItems 01760 { 01761 public: 01762 01763 TextItems(); 01780 TextItems 01781 ( 01782 const string fileName //in 01783 ); 01816 void displayItem 01817 ( 01818 const string title //in 01819 ) const; 01834 private: 01835 vector< vector<string> > itemList; 01836 }; 01837 01838 01839 //DisplayOpeningScreen free function 01840 //******************************************************************** 01841 inline void DisplayOpeningScreen 01842 ( 01843 const string& programmerInfo, //in 01844 const string& programInfo, //in 01845 int numBlankLinesBefore, //in 01846 int numBlankLinesAfter //in 01847 ) 01848 { 01849 string blankLinesBefore(numBlankLinesBefore, '\n'), 01850 blankLinesAfter(numBlankLinesAfter, '\n'); 01851 cout << blankLinesBefore 01852 << programmerInfo 01853 << "\nThis executable was built on " << __DATE__ 01854 << " at " << __TIME__ << ".\n" 01855 << programInfo 01856 << blankLinesAfter; 01857 Pause(); 01858 } 01859 01860 } //End of this part of namespace Scobey 01861 01862 #endif