This is my second time taking C++ course and I'm about to fail again since I'm barely hanging on with a C-D grade percentage. Here is the problem. I'm using the book "Beginning C++ Through Game Programming - 2nd Edition" and Dev-C++ to compile code.
I'm not even majoring in Computer Science so Programming is just not me. If anyone could make this work I'd appreciate it in advance, thanks. :'(
Rewrite the Mad Lib Game, so that there is a new object, a storyWordManager object, instantiated from a StoryWordManager class. The madLib object will be given a pointer to the storyWordManager object as a parameter that is passed into the MadLib constructor. The storyWordManager object's constructor method will prompt the user for the necessary story words (or numbers) and will accept input from the cin object. The madLib object will invoke public "get" methods to access the necessary story words as the story is built and "told".
#include <iostream>
#include <string>
using namespace std;
// pass constant reference instead of copy of string object
string askText(const string& prompt);
int askNumber(const string& prompt);
void tellStory(const string& name,
const string& noun,
int number,
const string& bodyPart,
const string& verb);
int main()
{
cout << "Welcome to Mad Lib.\n\n";
cout << "Answer the following questions to help create a new story.\n";
string name = askText("Please enter a name: ");
string noun = askText("Please enter a plural noun: ");
int number = askNumber("Please enter a number: ");
string bodyPart = askText("Please enter a body part: ");
string verb = askText("Please enter a verb: ");
tellStory(name, noun, number, bodyPart, verb);
return 0;
}
string askText(const string& prompt)
{
string text;
cout << prompt;
cin >> text;
return text;
}
int askNumber(const string& prompt)
{
int num;
cout << prompt;
cin >> num;
return num;
}
void tellStory(const string& name,
const string& noun,
int number,
const string& bodyPart,
const string& verb)
{
cout << "\nHere's your story:\n";
cout << "The famous explorer ";
cout << name;
cout << " had nearly given up a life-long quest to find\n";
cout << "The Lost City of ";
cout << noun;
cout << " when one day, the ";
cout << noun;
cout << " found the explorer.\n";
cout << "Surrounded by ";
cout << number;
cout << " " << noun;
cout << ", a tear came to ";
cout << name << "'s ";
cout << bodyPart << ".\n";
cout << "After all this time, the quest was finally over. ";
cout << "And then, the ";
cout << noun << "\n";
cout << "promptly devoured ";
cout << name << ". ";
cout << "The moral of the story? Be careful what you ";
cout << verb;
cout << " for.";
system("pause");
}