fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <cctype>
  6. const std::string article[] = { "the" , "a", "one", "some", "any" };
  7. const std::string noun[] = { "boy", "girl", "dog", "town", "car" };
  8. const std::string verb[] = { "drove", "jumped", "ran", "walked", "skipped" };
  9. const std::string preposition[] = { "to", "from", "over", "under", "on" };
  10. int main()
  11. {
  12. std::srand(static_cast<unsigned int>( std::time(NULL) ));
  13. std::string sentence;
  14. // initialize array of strings
  15. for(int i = 1; i <= 20; i++ )
  16. {
  17. //choose random parts of sentence//
  18. sentence = article[ rand() % 5 ] + " "
  19. + noun[ rand() % 5 ] + " "
  20. + verb[ rand() % 5 ] + " "
  21. + preposition[ rand() % 5 ] + " "
  22. + article[ rand () %5 ] + " "
  23. + noun[ rand() % 5 ];
  24. //capitalize first letter//
  25. sentence[0] = std::toupper(sentence[0]);
  26. //add period at end of sentence//
  27. sentence += '.';
  28. }
  29. std::cout << sentence << '\n';
  30. }
  31.  
Success #stdin #stdout 0s 2860KB
stdin
Standard input is empty
stdout
One town skipped from any girl.