Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program needs to use classes. My code is not printing the paragraph of the sentences. Please let me know what needs to change. /*

This program needs to use classes. My code is not printing the paragraph of the sentences. Please let me know what needs to change.

/* * Write a program that uses random number generation to create sentences. * The program should use four arrays of pointers to char called article. * 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 an array large * enough to hold the entire 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 should 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 contain the nouns "boy", "girl", "dog", "town", "car" * The verb array should contain verbs "drove", "jump", "ran", "walked", "skipped" * 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;

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 : Sadaf Safi****" << 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);

}

} 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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions