Paper Generator With the end of the semester in (distant) sight, you\'re probabl
ID: 643505 • Letter: P
Question
Paper Generator
With the end of the semester in (distant) sight, you're probably taking classes that require term papers. Wouldn't it be nice if a
computer could write those papers for you? We won't quite do that here (it's a really hard problem!), but let's make a first step in that
direction.
First, write functions called random_noun(), random_verb(), and random_adjective() that return a randomly-chosen noun, verb, or
adjective, respectively. (Include at least 5 nouns, 5 adjectives, and 5 verbs that the functions can choose from.) Then, write a function
called random_sentence() that returns a string of this form:
The (random_adjective) (random_noun) (random_verb) the (random_adjective) (random_noun).
with random words filled in using the corresponding functions you wrote above.
Finally, write a function called random_essay() that takes a single argument specifying the number of random sentences that the essay
should contain, and returns a string with that number of sentences created by calling random_sentence() repeatedly. Your main program
should ask the user for the number of sentences and print out the result. Here's an example:
>>>
How many sentences would you like in your essay? 3
Here's your automatically-generated essay:
The ugly sandwich sang the uneven dog.
The green flower ate the soggy tree.
The brilliant cat walked the brilliant sandwich.
Your functions should return strings instead of printing them. In other words, the only print statements in your program should be in the main body, not in the functions themselves.
Explanation / Answer
//Program to pick the words randomly and make a sentence
#include
#include
#include
#include
#include
void random_noun();
void random_verb();
void random_adjective();
void random_sentence();
void random_essay(int);
void random_noun()
{ char a[10];
char noun[5][10]={"dog","cat","flower","tree","sandwich"};
int x=random(5);
cout< }
void random_verb()
{
char verb[5][10]={"sang","ate","walked","run","sleep"};
int x=random(5);
cout< }
void random_adjective()
{
char adj[5][10]={"ugly","soggy","brilliant","uneven","green"};
int x=random(5);
cout< }
void random_sentence()
{cout<<"The ";
random_adjective();
cout<<" ";
random_noun();
cout<<" ";
random_verb();
cout<<" the ";
random_adjective();
cout<<" ";
random_noun();
cout<<". ";
}
void random_essay(int a)
{
for(int i=0;i {
random_sentence();
}
}
void main()
{ clrscr();
int a;
cout<<" How many sentences would you like in your essay? ";
cin>>a;
cout<<" Here's your automatically-generated essay: ";
random_essay(a);
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.