Question
Please follow the below instructions and double-check me. The outcome is not correct. Please pay close attention to 8, 9, and 10. /* 1-Write a
Please follow the below instructions and double-check me. The outcome is not correct. Please pay close attention to 8, 9, and 10.
/* 1-Write a program that uses random number generation to create sentences. 2-The program should use four arrays of pointers to char called article. 3- 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. 4- As each word is picked, it should be concatenated to the previous words in an array large enough to hold the entire sentence. 5- The words should be separated by space. 6- when the final sentence is output, It should start with the capital letter and end with a period. 7- The program should generate 20 such sentences. 8- The arrays should be filled as follows: The article array should contain the articles "the", "a", "one", "some", "any". * The noun array should contanin the nouns "boy", "girl", "dog", "town", "car" * The verb array should contain verbs "drove", "jump", "ran", "walked", "skiped" * The proposition array should contain "to", "from" , "Over", "under", "on". 9- After the proceeding program is written and working, modify it to produce 10- a short story consisting of several of these sentences. 11- The program must offer to the user the option of continue or exit * */
#include
//prototype funstion char *sentence();
int main() { int choice;
cout << "***This program will create random sentences***" << endl; cout << " Programmer : (my name)" << endl; cout << " *********************************************************" << endl;
do { cout << " Enter a choice: 1- Continue 2- Exit " << endl; cin >> choice;
if (choice != 2) { char* s = sentence(); for (int count = 0; count < 20; count++)//The program shoud generate 20 such sentences. cout << endl << s[count] << "." << endl;//The words should be separated by space. }
} while (choice == 1);
return 0; } char *sentence()// display sentences { /* 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. */ string article[5] = { "the", "a", "one", "some", "any" }; string noun[5] = { "boy", "girl", "dog", "town", "car" }; string verb[5] = { "drove", "jump", "ran", "walked", "skiped" }; string proposition[5] = { "to", "from" , "Over", "under", "on" };
int index; string sentence = ""; index = rand() % 5; // generating random index sentence += *(article + index); index = rand() % 5; // generating random index sentence += " " + *(noun + index); index = rand() % 5; // generating random index sentence += " " + *(verb + index); index = rand() % 5; // generating random index sentence += " " + *(proposition + index); index = rand() % 5; // generating random index sentence += " " + *(article + index); index = rand() % 5; // generating random index sentence += " " + *(noun + index); sentence[0] = toupper(sentence[0]); // capitalising first letter char* s = new char[sentence.size() + 1]; cout << copy(sentence.begin(), sentence.end(), s); s[sentence.size()] = '\0'; return s; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started