fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. class Fortunecookie
  10. {
  11. private:
  12. string fortune[10];
  13. int rand_index;
  14. public:
  15. void openFortuneCookie();
  16. void generateNewFortune();
  17. Fortunecookie(); // typo
  18. };
  19.  
  20.  
  21. void Fortunecookie::generateNewFortune()
  22. {
  23. rand_index = rand() %10;
  24. }
  25.  
  26. Fortunecookie::Fortunecookie()
  27. : fortune{" One that would have the fruit must climb the tree",
  28. " A new opportunity awaits you at the fork of the road",
  29. " The early bird gets the worm, but the second mouse gets the cheese. ",
  30. " You are cleverly disguised as responsible adult.",
  31. " The best things in life aren't things",
  32. " Forget injuries; never forget kindnesses.",
  33. " Borrow money from a pessimist. They don't expect it back",
  34. " Your good enough, strong enough and gosh darnit' people like you",
  35. " A feather in the hand is better than a bird in the air. ",
  36. " In life, you must be the water"
  37. }
  38. {
  39. rand_index = rand() %10; // number between 0 and 9
  40. }
  41. void Fortunecookie::openFortuneCookie()
  42. {
  43. generateNewFortune();
  44.  
  45. cout << " |====================================================================| \n";
  46. cout << " | | \n";
  47. cout << " | " <<setw(2)<<rand_index+1<<"-"<<setw(63)<<fortune[rand_index]<< " |\n";
  48. cout << " | | \n";
  49. cout << " |====================================================================| \n";
  50. }
  51. int main ()
  52. {
  53. srand(time(0)); // only once, at the beginning of the programme
  54. Fortunecookie yourfortune; // this calls the default constructor
  55. //yourfortune.generateNewFortune();
  56. //yourfortune.Fortunecookie(); // OUCH !!
  57. yourfortune.openFortuneCookie();
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
 |====================================================================| 
 |                                                                    | 
 |  4-               You are cleverly disguised as responsible adult. |
 |                                                                    | 
 |====================================================================|