Created
June 12, 2021 22:15
-
-
Save DreamVB/c221c0b91597ef740d986cb31f2f8bc1 to your computer and use it in GitHub Desktop.
Random Sentence Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Sentence Generator version 1.0 | |
| #include <iostream> | |
| #include <string> | |
| #include <time.h> | |
| #include <array> | |
| #include <vector> | |
| using namespace std; | |
| const std::string make_sentence(void){ | |
| std::array<int, 6>indexs; | |
| std::vector<string>words; | |
| std::string sentence; | |
| std::array<string, 14>article = { "a", "one", "the","some","any", | |
| "his","her","an","that","a car", "a ulgy duck","an elephant","a european","an honor" }; | |
| std::array<string, 9>Adjective = { "good", "bad", "amused", "happy", "adorable", "brave", | |
| "anxious","crazy", "confused" }; | |
| std::array<string, 8>nouns = { "man", "womman", "boy", "girl", "dog", "cat","bird","person" }; | |
| std::array<string, 7>verb = { "ran", "walked", "jumps", "swam", "skipped", "fell","sits" }; | |
| std::array<string, 7>preposition = { "to", "from", "over", "under", "above","through","around" }; | |
| indexs[0] = rand() % 13; //article | |
| indexs[1] = rand() % 8; //Adjective | |
| indexs[2] = rand() % 7; //nouns | |
| indexs[3] = rand() % 6; //verb | |
| indexs[4] = rand() % 6; //preposition | |
| words.push_back(article[indexs[0]]); | |
| words.push_back(Adjective[indexs[1]]); | |
| words.push_back(nouns[indexs[2]]); | |
| words.push_back(verb[indexs[3]]); | |
| words.push_back(preposition[indexs[4]]); | |
| //Get new random index | |
| indexs[0] = rand() % 13; | |
| words.push_back(article[indexs[0]]); | |
| //Get new random index | |
| indexs[1] = rand() % 8; | |
| words.push_back(Adjective[indexs[1]]); | |
| // | |
| indexs[2] = rand() % 7; | |
| words.push_back(nouns[indexs[2]]); | |
| //Build the sentence | |
| for (int x = 0; x < words.size(); x++){ | |
| if (x < words.size() - 1){ | |
| sentence += words.at(x) + " "; | |
| } | |
| else{ | |
| sentence += words.at(x); | |
| } | |
| } | |
| //Add full stop | |
| sentence += "."; | |
| //Uppercase first letter. | |
| sentence[0] = toupper(sentence[0]); | |
| //Clear up | |
| words.clear(); | |
| return sentence; | |
| } | |
| int main(){ | |
| srand((unsigned int)time(NULL)); | |
| for (int x = 0; x < 16; x++){ | |
| std::cout << make_sentence() << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment