Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Download the file USDictionary.txt from the course Blackboard site that contains

ID: 3831942 • Letter: D

Question

Download the file USDictionary.txt from the course Blackboard site that contains words in the dictionary (about 118,000 words-all in lower case). Write a C++ program that will determine and the following items: The total number of words in the dictionary. The total number of characters in the dictionary (not including white space) The total number of characters in the dictionary (including white spaces) The total number of words ending in the letter e. The total number of 6 letter words. The total number of words beginning with a vowel. The total number of words containing the substring "ate" The total number of occurrences of the letter e. The total number of words containing at least two occurrences of the letter e. Turn in a printout of the program and the results.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;

//Read data from file and returns number of records
int readFile(string words[])
{
//Creates an object of ifstream
ifstream readf;
//Opens the file Dictonary.txt for reading
readf.open ("Dictonary.txt");
int c = 0;
//Loops till end of file
while(!readf.eof())
{
//Reads data and stores in respective array
readf>>words[c++];
words[c] = " ";
//Increase the record counter
c++;
}//End of while
//Close file
readf.close();
//Displays the words available in the file
cout<<" Words in the file: ";
for(int x = 0; x < c; x++)
cout<<words[x];
//Returns record counter
return c;
}//End of function

//Function to count number of words
void countWords(string words[], int len)
{
//Initializes counter to zero
int wordCount = 0;
//Loops till length
for(int x = 0; x < len; x++)
{
string word = words[x];
for(int y = 0; y < word.length(); y++)
if(word.at(y) == ' ')
wordCount++;
}//End of for loop
cout<<" Number of words = "<<wordCount;
}//End of function

//Function to count number of character including space
void countCharacterIncludingSpace(string words[], int len)
{
//Initializes counter to zero
int charCount = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
y = 0;
string word = words[x];
for( ; y < word.length(); charCount++, y++)
;//Do nothing statement
}//End of for loop
cout<<" Number of characters including space = "<<charCount;
}//End of function

//Function to count number of characters without space
void countCharacterWithoutSpace(string words[], int len)
{
//Initializes counter to zero
int charCount = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
y = 0;
string word = words[x];
for( ; y < word.length(); y++)
if(word.at(y) != ' ')
charCount++;
}//End of for loop
cout<<" Number of characters without space = "<<charCount;
}//End of function

//Function to count number of words ending with letter e
void countEndLetterE(string words[], int len)
{
//Initializes counter to zero
int countE = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
string word = words[x];
if(word.at(word.length()-1) == 'e')
countE++;
}//End of for loop
cout<<" Number of words ending with 'e' = "<<countE;
}//End of function

//Function to count number of words length is six
void countSixLetterWord(string words[], int len)
{
//Initializes counter to zero
int countSix = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
string word = words[x];
if(word.length() == 6)
countSix++;
}//End of for loop
cout<<" Number of words length six = "<<countSix;
}//End of function

//Function to count number of words beginning with vowels
void countBeginningVowel(string words[], int len)
{
//Initializes counter to zero
int countVowel = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
string word = words[x];
if(word.at(0) == 'a' || word.at(0) == 'e' || word.at(0) == 'i' || word.at(0) == 'o' || word.at(0) == 'u')
countVowel++;
}//End of for loop
cout<<" Number of words beginning with vowels = "<<countVowel;
}//End of function

//Function to count number of words containing substring ate
void countSubstringAte(string words[], int len)
{
//Initializes counter to zero
int countSubstring = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
string word = words[x];
//for(y = 0; y < word.length()-2; y++)
//if(word.at(y) == 'a' && word.at(y+1) == 't' && word.at(y+2) == 'e')
if(word.find("ate") != -1)
countSubstring++;
}//End of for loop
cout<<" Number of words containing substring "ate" = "<<countSubstring;
}//End of function

//Function to count occurance of letter e
void countLetterE(string words[], int len)
{
//Initializes counter to zero
int countE = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
string word = words[x];
for(y = 0; y < word.length(); y++)
if(word.at(y) == 'e')
countE++;
}//End of for loop
cout<<" Number of occurances of letter 'e' = "<<countE;
}//End of function

//Function to count two occurance of letter in in a word
void countTwoOccuranceE(string words[], int len)
{
//Initializes counter to zero
int countE, coutTwoE = 0, y;
//Loops till length
for(int x = 0; x < len; x++)
{
countE = 0;
string word = words[x];
for(y = 0; y < word.length(); y++)
{
if(word.at(y) == 'e')
countE++;
}//End of inner for loop
if(countE >= 2)
coutTwoE++;
}//End of outer for loop
cout<<" Number of words containing at least two occurances of the letter 'e' = "<<coutTwoE;
}//End of function

//Main definition
int main()
{
string dictonaryWords[800];
int length = readFile(dictonaryWords);
countWords(dictonaryWords, length);
countCharacterIncludingSpace(dictonaryWords, length);
countCharacterWithoutSpace(dictonaryWords, length);
countEndLetterE(dictonaryWords, length);
countSixLetterWord(dictonaryWords, length);
countBeginningVowel(dictonaryWords, length);
countLetterE(dictonaryWords, length);
countTwoOccuranceE(dictonaryWords, length);
countSubstringAte(dictonaryWords, length);
return 0;
}//End of function

Output:

Words in the file: done eat working voice test surprise organization public turing delete age targate
Number of words = 12
Number of characters including space = 83
Number of characters without space = 71
Number of words ending with 'e' = 6
Number of words length six = 3
Number of words beginning with vowels = 3
Number of occurances of letter 'e' = 10
Number of words containing at least two occurances of the letter 'e' = 1
Number of words containing substring "ate" = 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote