Question
You have a set of different types of robots that combine to generate poetry. All robots have a common vocabulary and have a unique color
You have a set of different types of robots that combine to generate poetry. All robots have a common vocabulary and have a unique color that identifies them (red,
blue, purple, green, yellow, orange). The kind of words in the vocabulary that each robot understands depends on the type of therobot. Each robot produces phrases that are randomly generated on command using avocabulary that consists of nouns, verbs, adverbs, adjectives, articles, and prepositions. The types of phrases that each robot can produce are:
o The red robots produce a phrase consisting of
1 adjective followed by 1 noun (i.e., happy campers)
o The blue robots produce a phrase consisting of
1 verb followed by 1 adverb (i.e., eating rapidly)
o The purple robots produce a phrase consisting of
1 preposition, 1 article, 1 adjective, and 1 noun (under the fiery rock)o The green robots produce a phrase consisting of 1 article, 1 adjective, 1 noun, and 1 verb (i.e., the happy sun burns)
o The yellow robots produce a phrase consisting of
2 nouns joined by and (i.e., cow and chicken)
o The orange robots produce a phrase consisting of
2 verbs joined by or (i.e., bending or calling)You have six data files, one for each type of word (nouns.txt, verbs.txt, adverbs.txt, adjectives.txt,articles.txt and prepositions.txt).
Your program will combine these phrases into poems.
There are four set modes: red, blue, purple green, yellow, purple, orange green, yellow, red, blue, orange, purple any 4 randomly selected robots The output at the right shows the poemsproduced for each of these modes. Note that you have a chance for extra creditby adding a loop and a user menu to select the poem type.
Your program must:1. Define a global vector to hold the words for each part of speech. For example, for nouns, vector
Global means that your vectors are defined at file level, outside of main, so that they can beshared between different functions without passing them as parameters. For example,
vector
int main(int argc, char *argv[]){}
2. Define a function to read the words from a given file into a given vector. The signature touse is below. (You have seen this method used in one of the demonstration videos.)
void readFromFile(string filename, vector
When you use this, you will pass it a file and a vector, for example, to populate the nounsvector: readFromFile("nouns.txt", nouns); 3. Define a function that is passed a vector and randomly returns a word from the vector. Thesignature to use is below. You have done something similar for the MagicEightBallprogram.
string getRandomWord(vector
4. Define a function that returns the poem for each robot. For example,
string redSays();string blueSays();
Each of these should call thegetRandomWord function, sending itthe appropriate vector to create thepoem for each robot according to therules for the robot. Remember that the + operator concatenates strings together. string adj = getRandomWord(adjectives);string noun = getRandomWord(nouns);return adj + " " + noun;
5. The last set of functions is to create one for each mode. string redBluePurple();string greenYellowPurpleOrange();
string greenYellowRedBlueOrangePurple();string randomFour();
In these functions you will return the poem constructed by the set of robots, for example, return redSays() + " " + blueSays() + " " +purpleSays();
6. You can complete the program in one of two ways.
a. For minimum credit call each of the four functions defined for each mode as in myexample.b. For more credit, create a menu system, looping and allowing a user to input a valueto indicate which type of poem they would like to see. This must output a selectionmenu that also includes a quit option.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started