1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
bool theCheck(int, char*);
//bool ofCheck(int);
void sentenceAnalysis(char*, int, int);
void main()
{
char pgraph[300];
int ofTotal = 0, sentenceNum = 0, theTotal=0, wordTotal=0;
cout << "Enter a paragraph here: ";
cin.getline(pgraph,300);
for (int count = 0; count < strlen(pgraph); count++)
{
if (pgraph[count] == '.' || pgraph[count] == '!' || pgraph[count] == '?' || pgraph[count] == ':')
{
sentenceNum++;
int wordCount = 0, count2 = 0, theCount = 0, theTotal = 0;
for (int count2 = 0; count2 < count; count2++)
{
if (pgraph[count2] == ' '&& pgraph[count2 - 1] != ' ')
wordCount++;
else if (pgraph[count2] == 't' || pgraph[count2] == 'T')
{
if (theCheck(count2, pgraph))
{
theCount++;
}
}
}
cout << "Sentence" << sentenceNum << ": Contains " << wordCount << " words and contains the word 'the' " << theCount << "times" << endl;
theTotal += theCount;
theCount = 0;
}
/*else if (pgraph[count] == 'o' || pgraph[count] == 'O')
{
if (ofCheck(count))
ofTotal++;
}*/
else if (pgraph[count] == 't' || pgraph[count] == 'T')
{
if (theCheck(count, pgraph)==true)
theTotal++;
}
else if (pgraph[count] == ' '&& pgraph[count - 1] != ' ')
wordTotal++;
}
cout //<< "The total amount of words :" << wordTotal << " the word 'of' appeared" << ofTotal << " time(s). "<<endl
// <<
<< " the word 'the' appeared" << theTotal << " time(s). " << endl
<< " percentage of 'the' over all the words is" << theTotal / wordTotal << '%' << endl
<< " the average amount of words per sentence " << wordTotal / sentenceNum << endl;
system("pause");
}
void sentenceAnalysis(char* pgraph, int count, int sentenceNum)
{
int wordCount = 0, count2 = 0, theCount=0, theTotal = 0;
for (int count2 = 0; count2 < count; count2++)
{
if (pgraph[count2] == ' '&& pgraph[count2-1] != ' ')
wordCount++;
else if (pgraph[count2] == 't' || pgraph[count2] == 'T')
{
if (theCheck(count2, pgraph))
{
theCount++;
}
}
}
cout << "Sentence" << sentenceNum << ": Contains " << wordCount << " words and contains the word 'the' " << theCount << "times"<<endl;
theTotal += theCount;
theCount = 0;
}
bool TheCheck(int count, char* pgraph)
{
if (tolower(pgraph[count]) == 't' && tolower(pgraph[count + 1]) == 'h' && tolower(pgraph[count + 2]) == 'e'
&& isalpha(pgraph[count - 1]) == false && isalpha(pgraph[count+3])==false)
{
return true;
}
else
{
return false;
}
}
|