Write a program that uses random-number generation to create sentences. The program should use four arrays of pointers to char called article, noun, verb and preposition. 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 that is large enough to hold the entire sentence. The words should be separated by spaces. The program should generate 20 sentences. You can use the following declaration:
string article[5] = { "the", "a", "one", "some", "any" };
string noun[5] = { "boy", "girl", "dog", "town", "car" };
string verb[5] = { "drove", "jumped", "ran", "walked", "skipped" };
string preposition[5] = { "to", "from", "over", "under", "on" };
string sentence ;
******I dont know why its not generating 20 sentences...can some one help me*******
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
//#include<iostream>
//#include<cstdlib>
//#include<ctime>
//using namespace std;
//int main(){
// string article[5] = { "the", "a", "one", "some", "any" };
// string noun[5] = { "boy", "girl", "dog", "town", "car" };
// string verb[5] = { "drove", "jumped", "ran", "walked", "skipped" };
// string preposition[5] = { "to", "from", "over", "under", "on" };
// string sentence;
// int sum;
// srand(time(0));
// for(int i=0;i<20;i++){
// sum=1+rand()%20;
// sentence[sum];
// cout<<"The randome numbers are :"<<sum<<endl;
// cout<<article[i] <<" "<< noun[i] <<" "<< verb[i] <<" "<< preposition[i] <<" "<<article[i]<<" "<<noun[i]<<endl;
// }
// return 0; }
|