8.11(Random Sentences) Write a program that uses random-number generation to create sen-shouldtences. The program use four arrays of pointers to char called article, noun, verb andosition. The program should create a sentence by selecting a word at random from each array inprep-the following order: article, noun, verb, preposition, article and noun. As each word is picked,it should be concatenated to the previous words in an array large enough to hold the entire sentence.The words should be separated by spaces. When the final sentence is output, it should start with acapital letter and end with a period. The program should generate 20 such sentences. The arraysshould be filled as follows: The article array should contain the articles "the", "a", "one", "some"%3Dand "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; theshould contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the prep-arrayverbshould contain the prepositions "to", "from", "over", "under" and "on".After the preceding program is written and working, modify it to produce a short story con-Sisting of several of these sentences. (How about the possibility of a random term-paperosition arraywriter?)lines

Question
Asked Feb 1, 2020
42 views

Write in c programming language . 8.11

8.11
(Random Sentences) Write a program that uses random-number generation to create sen-
should
tences. The program use four arrays of pointers to char called article, noun, verb and
osition. The program should create a sentence by selecting a word at random from each array in
prep-
the following order: article, noun, verb, preposition, article and noun. As each word is picked,
it should be concatenated to the previous words in an array large enough to hold the entire sentence.
The words should be separated by spaces. When the final sentence is output, 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"
%3D
and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the
should contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the prep-
array
verb
should contain the prepositions "to", "from", "over", "under" and "on".
After the preceding program is written and working, modify it to produce a short story con-
Sisting of several of these sentences. (How about the possibility of a random term-paper
osition array
writer?)
lines
help_outline

Image Transcriptionclose

8.11 (Random Sentences) Write a program that uses random-number generation to create sen- should tences. The program use four arrays of pointers to char called article, noun, verb and osition. The program should create a sentence by selecting a word at random from each array in prep- the following order: article, noun, verb, preposition, article and noun. As each word is picked, it should be concatenated to the previous words in an array large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence is output, 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" %3D and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the should contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the prep- array verb should contain the prepositions "to", "from", "over", "under" and "on". After the preceding program is written and working, modify it to produce a short story con- Sisting of several of these sentences. (How about the possibility of a random term-paper osition array writer?) lines

fullscreen
check_circle

Expert Answer

Step 1

Program Instructions:

  • See the random generator and declare the arrays with given values.
  • Declare an array named sentence to hold and print the sentences formed.
  • Use a for loop and rand() function to form 20 sentences and generated random index number for arrays respectively.
  • Use the toupper() method of ctype header file to start the sentence with a capital letter.
  • In the second version, modify the program to hold the whole story of these sentences rather than to print them one by one.
Step 2

Program to generate 20 sentences:

// header files

#include <stdio.h>

#include <ctype.h>

#include <stdlib.h>

#include <string.h>

#include <time.h>

int main ()

{

     // seed the rand() function

  srand(time(NULL));

 

  // goven arrays

  char *article[] = {"the", "a", "one", "some", "any"};

  char *noun[] = {"boy", "girl", "dog", "town", "car"};

  char *verb[] = {"drove", "jumped", "ran", "walked", "skipped"}; 

  char *preposition[] = {"to", "from", "over", "under", "on"};   

   

  // array to hold sentence

  char sentence[60]="";

   

    // to generate the sentences

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

  {

       strcat(sentence, article[rand()%5]);

       strcat(sentence, " ");

      

       sentence[0] = toupper(sentence[0]);

       

       strcat(sentence, noun[rand()%5]);

       strcat(sentence, " ");

        

       strcat(sentence, verb[rand()%5]);

       strcat(sentence, " ");

   &...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Write a C++ program You are burning some music CDs for a party. You've arranged a list of songs in t...

A: Following is the C++ program:Header file are declared.Main function is defined.Declare necessary var...

question_answer

Q: How would I decrypt an RSA message? Let's say we're given C, p, q, e.

A: Steps to decrypt an RSA message:The formula to get the plain text from cyber text using RSA algorith...

question_answer

Q: In c++  I have this working code that requres the user to input 6 times  I was wondering how would i...

A: In this C++ program,Linear search: num is matched with each element of array starting from index 0 u...

question_answer

Q: Output the information as a formatted histogram. Each name is right justified with a setw() value of...

A: Program:#include &lt;iostream&gt;#include &lt;string&gt;#include &lt;iomanip&gt; using namespace std...

question_answer

Q: Write a program in python with no imports named filemaker.py that will be used to store the first na...

A: Create a file named filemaker.pyPrompt user for name of a friend and his age repeatedly until user e...

question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Following is the source code according to the requirements given in the question. Comments have been...

question_answer

Q: Create a complex query based on two or more tables (SCHOOL, DEPARTMENT, PROFESSOR, TECHNOLOGY, COURS...

A: Query:SELECT DEPARTMENT.DEPARTMENT_NAME, DEPARTMENT.DEPARTMENT_ID,SCHOOL.SCHOOL_CODE,COURSE.COURSE_T...

question_answer

Q: How do you write a program that gets a list of integers from input, and outputs non-negative integer...

A: Program Instructions:Input the list of integers separated by space from the user.Use list compressio...

question_answer

Q: What is a sign bit used for and where is it located?

A: Variables can be represented in two ways, one is signed and other is unsigned, such as integer. Sign...