(Randomly Creating Sentences) Write a program that uses random number generation to create sentences. The program should use four arrays of pointers to char called article, noun, verb and preposition. The program should create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked, it should be

concatenated to the previous words in a character array that is large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence is out- put, it should start with a capital letter and end with a period. The program should generate 20 such sentences. The arrays should be filled as follows: The article array should contain the articles "the", "a", "one", "some" and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the verb array should contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the preposition array should contain the prepositions "to", "from", "over", "under" and "on". After completing the program, modify it to produce a short story consisting of several of these sentences. (How about a random term-paper writer!)

What will be an ideal response?


```
#include
#include
#include
#include
using namespace std;

const int SIZE = 100;

int main()
{
// arrays declared for article, noun, verb, and preposition
const char *article[] = { "the", "a", "one", "some", "any" };
const char *noun[] = { "boy", "girl", "dog", "town", "car" };
const char *verb[] = { "drove", "jumped", "ran", "walked", "skipped" };
const char *preposition[] = { "to", "from", "over", "under", "on" };
char sentence[ SIZE ] = ""; // to hold the sentence

srand( time( 0 ) ); // seed random number generator

// loop through and make 20 random sentences out of the given arrays
for ( int i = 1; i <= 20; ++i )
{
// uses function strcat to concatenate random sentences
strcat( sentence, article[ rand() % 5 ] );
strcat( sentence, " " );
strcat( sentence, noun[ rand() % 5 ] );
strcat( sentence, " " );
strcat( sentence, verb[ rand() % 5 ] );
strcat( sentence, " " );
strcat( sentence, preposition[ rand() % 5 ] );
strcat( sentence, " " );
strcat( sentence, article[ rand() % 5 ] );
strcat( sentence, " " );
strcat( sentence, noun[ rand() % 5 ] );

// print the current sentence
cout << static_cast< char > ( toupper( sentence[ 0 ] ) )
<< &sentence[ 1 ] << ".\n";

sentence[ 0 ] = '\0'; // reset the sentence
} // end for

cout << endl;
return 0; // indicates successful termination
} // end main
```
A dog ran under a dog.
Any town walked to any dog.
Any town drove on any dog.
The dog skipped over one town.
Some girl walked to the dog.
The girl ran to a car.
The dog jumped from the boy.
Some boy walked over the girl.
A dog drove on a girl.
Some car jumped from any car.
A boy jumped to some girl.
Some girl ran over any boy.
One town skipped from some car.
Any girl jumped on a car.
Some dog jumped on a town.
A boy drove from the boy.
One town skipped under the girl.
One boy skipped to some dog.
Any car ran on a town.
The car jumped to one boy.

Computer Science & Information Technology

You might also like to view...

The VBScript operator for inequality is which of the following?

a) != b) <> c) NotEqual d) !

Computer Science & Information Technology

Two key differences between RIPv1 and RIPv2 are that RIPv1 does not support ____________________ and variable-length subnet masking (VLSM).

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

If a picture is pixilated, then that is an indication that it is very high quality

Indicate whether the statement is true or false

Computer Science & Information Technology

Most themes include one layout.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology