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