Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the third time I am asking this question because the other two times the answer was wrong. I have instructions below. My output

This is the third time I am asking this question because the other two times the answer was wrong. I have instructions below. My output should be 20 sentences per the below instructions plus a paragraph of those 20 sentences. My code is not printing the paragraph. I also want to add my two strings sentence and paragraph to the class. also my program should start with printing the sentences and paragraph first and then ask for the continue or exit, but right now it starts from the beginning.

/*

*Use classes * Write a program that uses random number generation to create sentences. * The program should use four arrays of poiters to char called article. * The program should create a sentence by selecting a word at random from each array in the following order: * articel, 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 enotire sentence. * The words should be separated by space. * when the final sentence is output, It should start with the capital letter and end with a period. * The program shoud generate 20 such sentences. * 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". * After the proceeding program is written and working, modify it to produce * a short story consisting of several of these sentences. * The program must offer to the user the option of continue or exit * */

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

// Random Sentence class declaration class randomSentence { private: string article; string noun; string verb; string proposition; };

string randomSentence() // display sentences { /* The program should create a sentence by selecting a word at random from each array in the following order:articel, 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 s = ""; index = rand() % 5; // generating random index s = *(article + index); index = rand() % 5; // generating random index s += " " + *(noun + index); index = rand() % 5; // generating random index s += " " + *(verb + index); index = rand() % 5; // generating random index s += " " + *(proposition + index); index = rand() % 5; // generating random index s += " " + *(article + index); index = rand() % 5; // generating random index s += " " + *(noun + index); s[0] = toupper(s[0]); // capitalising first letter return s; } string paragraph(string s) // Display the paragraph { string randomSentence(); for (int count = 0; count < 20; count++)//The program shoud generate 20 such sentences. { s += randomSentence() + ".";

cout << endl << s << "." << endl;//The words should be separated by space. } return s; }

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) { string s;

for (int count = 0; count < 20; count++)//The program shoud generate 20 such sentences. { s = randomSentence(); cout << endl << s << "." << endl;//The words should be separated by space. } string paragraph(s);

} else if (choice == 2) { cout << "Program Exited"; exit(0); } else { cout << "Invalid choice"; }

} while (choice == 1);

return 0; }

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

Step: 3

blur-text-image

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions