Hey, I have improved my program and now its working if I enter @@@ at the end of line, but my requirement is
"You can stop your entering by inputting "@@@" in a new line as a sentinel."
How should I change my program to satisfy this requirement:
int main(int argc, char *argv[])
{
Word listWord[200];
string input;
int len, tempcount, check = 0, listLen = 0;
cout<<"Please enter your sentences, you can enter '@@@' by a new line to finish the input: ";
getline(cin, input);
istringstream in(input);
string singleword;
do
{
check = 0;
in>>singleword;
if(singleword == "@@@")
break;
len = singleword.length();
for(int k=0; k<len; k++)
{
if(ispunct(singleword[k]))
{
if(singleword[k] != '-' && singleword[k] != '\'')
{
singleword.erase(k,1);
len = singleword.length();
k--;
}
}
}
len = singleword.length();
for(int i=0; i<len; i++)
singleword[i] = tolower(singleword[i]);
for(int j=0; j<listLen; j++)
{
if(listWord[j].getName() == singleword)
{
tempcount = listWord[j].getCount();
listWord[j].setCount(tempcount+1);
check = 1;
break;
}
}
if(check == 0)
{
listWord[listLen].setName(singleword);
listWord[listLen].setCount(1);
listLen++;
}
}while(in);
sort(listWord, listLen);
int distinctWord = 0;
int totalWord = 0;
for(int i=0; i<listLen; i++)
{
if(listWord[i].getCount() == 1)
distinctWord++;
totalWord += listWord[i].getCount();
}
cout<<"\nTotal Number of words: "<<totalWord<<endl;
cout<<"Total Number of distinct words: "<<distinctWord<<endl;
cout<<"\nWord\t\tCount"<<endl;
for(int i=0; i<listLen; i++)
cout<<listWord[i].getName()<<"\t\t"<<listWord[i].getCount()<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Thanks for helping.