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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
unsigned long int wordsn=0, countT=0, vowel=0, max=0, min=0, novowel=0, countSH=0;
double sum=0;
string minWord, maxWord;
ifstream wordfile;
string line;
wordfile.open("/Users/rami/Downloads/default.asp.html");
if (wordfile.fail())
{
cout << "Error opening the file" << endl;
return 0;
}
while (!wordfile.eof())
{
wordfile >> line;
wordsn++;
int nvow=0;
if (line[0] == 't') countT++;
if (wordsn==1) {min=line.length(); max=line.length();}
if (line[0]=='s' && line[1]=='h') countSH++;
for (int i=0;i<line.length();i++)
{
if (line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u'||line[i]=='y') nvow++;
}
int numberVowY=0;
for(int j=0;j<line.length();j++)
{
if (line[j]=='a' || line[j]=='e' || line[j]=='i' || line[j]=='o' || line[j]=='u') numberVowY++;
}
if (numberVowY==line.length()) vowel++;
if (nvow==0) novowel++;
sum = sum+line.length();
if(line.length()<=min && line.length()!=0 ) {min=line.length(); minWord=line;}
if(line.length()>max) {max=line.length(); maxWord=line;}
}
wordfile.close();
cout << "The total number of words in file: " << wordsn << endl;
cout << "The total number of words that begin with the letter t: " << countT << endl;
cout << "The total number of words that have no vowels (a,e,i,o,u), including (y): " << novowel << endl;
cout << "The average length of the words: "<< sum/wordsn << " letters" << endl;
cout << "The minimum length of the words: " << min << " The word is: " << minWord << endl;
cout << "The maximum length of the words: " << max << " The word is: " << maxWord << endl;
cout << "The total number of words that are all vowels (a,e,i,o,u): " << vowel << endl;
cout << "The total number of words that begin with 'sh': " << countSH << endl;
return 0;
}
/* Sample Output
The total number of words in file: 798
The total number of words that begin with the letter t: 53
The total number of words that have no vowels (a,e,i,o,u), including (y): 258
The average length of the words: 12.7168 letters
The minimum length of the words: 1 The word is: }
The maximum length of the words: 232 The word is: EXPLORER')?document.contentFrame:window.frames['win'+window.gstrEntryID];try{if(iframe.contentWindow){iframe.contentWindow.printPage();}else{iframe.printPage();}}catch(e){try{iframe.focus();iframe.print();}catch(e){printed=false;var
The total number of words that are all vowels (a,e,i,o,u): 4
The total number of words that begin with 'sh': 0
Program ended with exit code: 0
*/
|