#include <iostream>
#include <vector>
#include <cstring>
#include <ctime>
#include <cstdlib>
using namespace std;
void createVector(vector<char*> &);
void createSentence(vector<char*> &, vector<char*> & , vector<char*> &, vector<char*> & ,vector<char*> & );
//void sortSentence(vector<char*> &);
void outputSentence(vector<char*> &);
///////////////////////////////////////////////////////////////////////////
void createVector(vector<char*> & sentence)
{
int size1,size2,size3,size4;
cout<<"enter size for article:";
cin>> size1;
vector<char*> article(size1);
cout<<"enter size for noun:";
cin>> size2;
vector<char*> noun(size2);
cout<<"enter size for verb:";
cin>> size3;
vector<char*> verb(size3);
cout<<"enter size for preposition:";
cin>> size4;
vector<char*> preposition(size4);
for(int i=0;i<size1;i++)
{
char buffer[256];
cout<<"Type your article #" << (i+1)<< ":";
cin>>buffer;
article[i] = new char[(strlen(buffer) +1)];
strcpy(article[i],buffer);
}
//noun
for(int i=0;i<size2;i++)
{
char buffer[256];
cout<<"Type your noun #" << (i+1)<< ":";
cin>>buffer;
noun[i] = new char[(strlen(buffer)+1)] ;
strcpy(noun[i],buffer);;
}
//Verb
for(int i=0;i<size3;i++)
{
char buffer[256];
cout<<"Type your verb #" << (i+1)<< ":";
cin>>buffer;
verb[i] = new char[(strlen(buffer)+1)] ;
strcpy(verb[i],buffer);
}
//Preposition
for(int i=0;i<size4;i++)
{
char buffer[256];
cout<<"Type your Preposition #" << (i+1)<< ":";
cin>>buffer;
preposition[i] = new char[(strlen(buffer)+1)] ;
strcpy(preposition[i],buffer);;
}
createSentence(article,noun,verb,preposition,sentence);
}
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void createSentence(vector<char*> & article, vector<char*> & noun, vector<char*> & verb, vector<char*> &preposition, vector<char*> & sentence)
{
srand (static_cast<int>(time(NULL)));
for(vector<char*>::size_type x = 0; x < sentence.size(); x++)
{
char buffer[256];
int iarticle1 = rand() % (int)article.size();
int iarticle2 = rand() % (int)article.size();
int inoun1 = rand() %(int) noun.size();
int inoun2 = rand() % (int)noun.size();
int iverb = rand() % (int)verb.size();
int ipreposition = rand() % (int)preposition.size();
buffer=new char[(strlen(article[iarticle1])+strlen(noun[inoun1])+strlen(verb[iverb])+strlen(preposition[ipreposition])+strlen(article[iarticle2])+strlen(noun[inoun2])+1)];
strcpy(buffer,article[iarticle1]);
strcat(buffer," ");
strcat(buffer,noun[inoun1]);
strcat(buffer," ");
strcat(buffer,article[iarticle1]);
strcat(buffer," ");
strcat(buffer,verb[iverb]);
strcat(buffer," ");
strcat(buffer,preposition[ipreposition]);
strcat(buffer," ");
strcat(buffer,noun[inoun2]);
strcat(buffer,".");
}
}
///////////////////////////////////////////////////////////////
void outputSentence(vector<char*> & sentence)
{
for(int i=0; i < sentence.size(); i++)
cout<<i+1<<'. '<< sentence[i]<<endl;
}
///////////////////////////////////////////////////////////////
/*
void sortSentence(vector<char*> & sentence)
{
int* temp;
int i,j;
char* p, *po = sentence;
if (*p > *sentence[j+1])
{ temp = hello[j];
hello[j] = hello[j+1];
hello[j+1] = temp;
}
}
*/
///////////////////////////////////////////////////////////////
int main()
{
vector <char*> sentence(20);
createVector(sentence);
outputSentence(sentence);
//sortSentence(sentence);
//outputSentence(sentence);
system("pause");
}
////////////////////////////////////////////////////////////////////////////////////////////
|