#include <iostream>
#include <vector>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <string>
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++)
{
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();
sentence[x]=new char[strlen(article[iarticle1])+strlen(noun[inoun1])+strlen(verb[iverb])+strlen(preposition[ipreposition])+strlen(article[iarticle2])+strlen(noun[inoun2])+1];
strcpy(sentence[x],article[iarticle1]);
strcat(sentence[x]," ");
strcat(sentence[x],noun[inoun1]);
strcat(sentence[x]," ");
strcat(sentence[x],verb[iverb]);
strcat(sentence[x]," ");
strcat(sentence[x],article[iarticle2]);
strcat(sentence[x]," ");
strcat(sentence[x],preposition[ipreposition]);
strcat(sentence[x]," ");
strcat(sentence[x],noun[inoun2]);
strcat(sentence[x],".");
}
}
///////////////////////////////////////////////////////////////
void outputSentence(vector<char*> & sentence)
{
for(int i=0; i < 20; i++)
{
cout<< i+1 << '.';
cout<< sentence[i]<<endl;
}
}
///////////////////////////////////////////////////////////////
void sortSentence(vector<char*> & sentence)
{
bool ended = false;
char *temp;
int size = (int)sentence.size();
while (!ended)
{
ended = true;
for (int i=0; i<size-1; i++)
{
if (strcmp(sentence[i], sentence[i+1]) > 0)
{
temp = sentence[i];
sentence[i] = sentence[i+1];
sentence[i+1] = temp;
ended = false;
}
}
}
}
strindex (char *s, char *t)
{
}
///////////////////////////////////////////////////////////////
int main()
{
vector <char*> sentence(20);
createVector(sentence);
outputSentence(sentence);
sortSentence(sentence);
cout<<endl<<endl<<endl<<endl<<"AFTER SORTING"<<endl;
outputSentence(sentence);
system("pause");
}
////////////////////////////////////////////////////////////////////////////////////////////
|