My professor likes to give us tests on topics we've not covered yet, like string stream :o
This program uses stringstream objects to make sentences like the Mad Lib ™ game. Create 4 string objects: noun, adjective, verb, and adverb.
You will need these functions: AskNoun, AskVerb, AskAdjective, AskAdverb, and BuildSentence. Call the first four functions to obtain the word values. (You’ll need to pass the user’s noun and verb to the adjective and adverb functions.) Next, pass the four sentence parts into BuildSentence, which creates a complete sentence using these words. Return the sentence to main() to show it to the user. You may make up parts of the sentence if you like. Include a go again loop and goodbye message.
Example of output:
Enter a noun (person, place or thing): table
Enter a verb (an action!): drinks
Enter an adjective (describes the table): large
Enter an adverb (describes how it drinks): sloppily
The large table drinks sloppily.
I know this isnt right but this what i have got:
sentbuild.h
#include <sstream>
using namespace std;
class Sentence
{
public:
void getNoun(string word);
void getVerb(string word);
void getAdverb(string word);
void getAdjective(string word);
string BuildSentence();
private:
string Noun;
string Verb;
string Adverb;
string Adjective;
};
sentbuild.cpp
#include <sstream>
#include "SentBuild.h"
void Sentence::getNoun(string word)
{
stringstream(word) >> Noun;
}
void Sentence::getVerb(string word)
{
stringstream(word) >> Verb;
}
void Sentence::getAdverb(string word)
{
stringstream(word) >> Adverb;
}
void Sentence::getAdjective(string word)
{
stringstream(word) >> Adjective;
}
string Sentence::BuildSentence()
{
string s = " ";
string sent = "The "+Adjective+s+Noun+s+Verb+s+Adverb+".\n";
return sent;
}
main.cpp
#include <iostream>
#include <sstream>
#include "SentBuild.h"
using namespace std;
void main()
{
string ans;
do
{
Sentence sent1;
string word;
cout << "Let's play a game of mad lib! \n\n";
cout << "What is your Noun? ";
getline(cin, word); sent1.getNoun(word);
cout << "What is your Verb? ";
getline(cin, word); sent1.getVerb(word);
cout << "What is your Adverb? ";
getline(cin, word); sent1.getAdverb(word);
cout << "What is your Adjective? ";
getline (cin, word); sent1.getAdjective(word);
cout << sent1.BuildSentence() << endl;
cout << "Do you want to play again? ";
getline(cin, ans);
cout << endl;
} while (ans == "yes" || ans == "Yes");
}
it works but I do not think this is what he wants.
any suggestions to help me fix this?