Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

content of file Zoos are places where wild are kept in pens or cages so that can come and look at them . There is

content of file

Zoos are places where wild  are kept in pens or cages <#> so that  can come and look at them . There is a zoo <#> in the park beside the  fountain . When it is feeding time , <#> all the animals make  noises . The elephant goes <{>  <}> <#> and the turtledoves go <{>  . <}> My favorite animal is the <#>   , so fast it can outrun a/an  . <#> You never know what you will find at the zoo . <#> 

write the code necessary to make the Mad Lib appear on the screen:

Please enter the filename of the Mad Lib: madlibZoo.txt Plural noun: boys Plural noun: girls Type of liquid: lemonade Adjective: fuzzy Funny noise: squeak Another funny noise: snort Adjective: hungry Animal: mouse Another animal: blue-fin tuna Zoos are places where wild boys are kept in pens or cages so that girls can come and look at them. There is a zoo in the park beside the lemonade fountain. When it is feeding time, all the animals make fuzzy noises. The elephant goes "squeak" and the turtledoves go "snort." My favorite animal is the hungry mouse, so fast it can outrun a/an blue-fin tuna. You never know what you will find at the zoo. Do you want to play again (y/n)? n Thank you for playing. 

Hints

A few hints to make the code writing a bit easier:

The best way to store the story is in an array of words. Thus the process of reading the story from the file removes all spaces from the story.

By default, you insert a space before each word when you display the story. The only conditions when a space is not inserted is when the preceding character is a {, [, or #, or when the following character is a }, ], #, or punctuation. In other words, do not think about removing spaces, but rather about adding them when conditions are right.

Your program will need to be able to play any number of Mad Lib games. The easiest way to handle this is to have a while loop in main()

Assignment

Perhaps the easiest way to do this is in a five-step process:

Start with the code from Project 09.

Fix any necessary bugs.

Write the code to display the Mad Lib on the screen. ( display function)

#include

#include

using namespace std;

void getFile(char fileName[])

{

cout << "Please enter the filename of the Mad Lib: ";

cin >> fileName;

cin.ignore();

return;

}

void readFile(char fileName[], char file[][32], int &wordCount)

{

ifstream fin;

fin.open(fileName);

if (fin.fail())

{

return;

}

while (fin >> file[wordCount])

{

wordCount++;

}

fin.close();

return;

}

void promptUser(char file[][32], int wordCount, char promptsAnswers[], int & promptCount)

{

char prompt[256][32];

for (int i = 0; i < wordCount; i++)

{

if (file[i][0] == '<')

{

for (int k = 0; file[i][k]; k++)

{

prompt[promptCount][k] = file[i][k];

}

promptCount++;

}

}

for (int v = 0, f = 0; v < promptCount; f++)

{

if (prompt[v][f] == '<')

prompt[v][f] = '\t';

else if (prompt[v][f] == '>')

{

prompt[v][f] = ':';

prompt[v][f+1] = ' ';

v++;

f = -1;

}

else if (prompt[v][f] == '_')

prompt[v][f] = ' ';

}

for (int q = 0; q < promptCount; q++)

{

if (islower(prompt[q][1]))

prompt[q][1] = toupper(prompt[q][1]);

if (prompt[q][1] != '#' && prompt[q][1] != '{' && prompt[q][1] != '}'

&& prompt[q][1] != '[' && prompt[q][1] != ']')

{

cout << prompt[q];

cin.getline(promptsAnswers, 256);

}

}

return;

}

void display(char file[][32], int wordCount, char promptsAnswers[],

int promptCount)

{

}

int main()

{

char promptsAnswers[256];

int wordCount = 0;

int promptCount = 0;

char fileName[256];

char file[256][32];

getFile(fileName);

readFile(fileName, file, wordCount);

promptUser(file, wordCount, promptsAnswers, promptCount);

display(file, wordCount, promptsAnswers, promptCount);

cout << "Thank you for playing. ";

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

Students also viewed these Databases questions

Question

help asp

Answered: 1 week ago