if anyone worked on the madlibs project in c++ please let me know. i am now working on it and im having problems testing if bracketed words are valid and then replacing them with the ones in the dictionary.
There's not some official, standard "Madlibs Project in C++" that every programmer knows about.
No one knows what you're talking about with "testing if bracketed words are valid." No one knows what dictionary you mean. No one knows where you're trying to do the replacement.
Write a program based on the word game Madlibs. The input to Madlibs is a brief story, with words left out. Players are asked to fill in missing words by prompting for adjectives , nouns, verbs, and so on. When these words are used to replace the missing words, the resulting story is often funny when read aloud.
In the computerized version of the game, the input will be a text file (called madlib_story.txt) with certain words annotated by enclosing the words in brackets. These enclosed words (i.e., the square bracketed terms, like "[noun]" will be replaced by scanning a dictionary file (madlib_dictionary.txt) for the appropriate word, and placed in an output file (madlib_output.txt) that contains all the unbracketed words in their original positions and the replacement words in the same positions as their corresponding bracketed words' locations. An output line (sentence) should be no more than 60 characters long. You must placed the maximum number of characters on a line. Read your dictionary entries into a vector called "DB." Use "DB" to determine if a bracketed word is a valid dictionary entry (hint: search DB). Your program will simultaneously handle two input files (madlib_story.txt and madlib_dictionary.txt) and one output file (madlib_output.txt). You should handle both input files with the ifstream class, we discussed in class, and the output file with the standard ofstream class. Code your program in a single file, madlibs.cpp. Keep the size of your main function to a minimum.
The Dictionary File
The dictionary file will consist of pairs of words (in the madlib_dictionary.txt each pair appears on a separate line). For example, a portion of the dictionary file might be:
noun cat
adjective happy
car-brand mazda
The first word of each pair is the key, and the second is the value. Together, a pair is called an entry. The only entries in your dictionary are the ones specified by the sample dictionary file. Also make sure you check to see that a bracketed word is a valid dictionary entry. Otherwise you will exhaust you dictionary file on an invalid entry. Example: You should not search your dictionary for a bracketed word like [xxxxx]. [xxxxx] will be printed to your story file.
The Story File
This file will consist of text, where some words have a left and right bracket as their first and last characters respectively, e.g.: "[noun]", "[car-brand]". The words in brackets may be followed by a single punctuation mark like a comma, period, or question mark. See the madlib_story.txt for an example.
The Output File
Your program should scan through the story file, outputting non bracketed words directly to the output file. For each each "VALID" bracketed word, continue scanning through the dictionary file until reaching an entry with a matching key and send the corresponding value to the output file in place of the "VALID" bracketed word. Thus, the output file should be a copy of the story file, but with the "VALID" bracketed words replaced with terms from the dictionary file.
Note that using the ifstream object, you will not be able to tell how long the lines of input are. Lines in the output file should be no more than 60 characters long.
Running your program on the dictionary above and the story file:
I once owned a [noun] who was [adjective]
only when in a [car-brand] automobile.
Should result in an output file (though the line break positions may differ):
I once owned a cat who was happy only when in a mazda automobile.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.