Question: // HW8_practice.cpp : This file contains the 'main' function. Program execution begins and ends there. // This program counts the number of words in files
// HW8_practice.cpp : This file contains the 'main' function. Program execution begins and ends there.
// This program counts the number of words in files selected by the user.
#include "pch.h"
#include
#include
#include
#include
#include
using namespace std;
int count(string);
int vowel(string);
int letters(string);
int digit(string);
string convert(string);
string remove_lead(string);
string reverse(string);
//Function words length
int count(string word) {
int index;
return word.length();
}
//Function vowel counter
//http://www.cplusplus.com/forum/general/110873/
int vowel(string word) {
char philip;
int vowelCounter = 0;
int consonantCounter = 0;
for (int index = 0; index
{
philip = toupper(word[index]);
switch (philip)
{
case 'A': case 'a':
case 'E': case 'e':
case 'I': case 'i':
case 'O': case 'o':
case 'U': case 'u':
vowelCounter++;
break;
default:
consonantCounter++;
}
}
return vowelCounter;
}
//Function letters
int letters(string words) {
int l = 0;
for (int index = 0; index
{
if (isalpha(words[index]))
l++;
}
return l;
}
//Function digit
int digit(string words) {
int l = 0;
for (int index = 0; index
{
if (isdigit(words[index]))
l++;
}
return l;
}
//Function convert
//Coverting all uppercase letters to lowercase
string convert(string words) {
int index = 0;
for (index = 0; index
words[index] = tolower(words[index]);
}
return words;
}
//Function remove disit
string remove_lead(string words) {
int index = 0, pos = 0, flag = 0;
string str;
do {
if (isdigit(words[index]) || isalpha(words[index])) {
flag = 1;
//break;
}
else
{
for (pos = 0; pos
char ch = words[pos];
words[pos] = words[pos + 1];
}
unsigned sz = words.length();
words.resize(sz - 1);
}
} while (flag == 0);
return words;
}
//Function reverse
string reverse(string str) {
if (str.length() == 1) {
return str;
}
else {
return reverse(str.substr(1, str.length())) + str.at(0);
}
}
int main()
{
ifstream inputfile;
string filename;
string words, word, longest = " ", shortest = " ", nm;
int index = 0, countWords = 0, vow = 0, let = 0, dit = 0, sum = 0;
float countS = 0;
//Get the filename from the user.
cout
cin >> filename;
//Open the input file.
inputfile.open(filename.c_str());
cout
cout
//If the inputfile succesfully opened, process the file.
if (inputfile)
{
while (inputfile >> words) {
int m = 0, n = 0;
string wor, lt;
countWords = countWords + count(words);
string str = remove_lead(words);
str = reverse(str);
str = remove_lead(str);
string conWord = reverse(str);
cout
index++;
sum = sum + count(conWord);
vow = vow + vowel(words);
let = let + letters(words);
dit = dit + digit(words);
if (index == 1)
shortest = str;
if (str.length() > longest.length())
longest = conWord;
if (str.length()
shortest = conWord;
if (index % 4 == 0) cout
}
cout
cout
cout
cout
cout
cout
cout
countS = (float)sum / (float)index;
cout
//Close the file.
inputfile.close();
}
else
{
//Display an error message.
cout
}
return 0;
}
It looks good on 100Words_W.txt

input: Apology_W.txt


please help me Thank you
Microsoft Visual Studio Debug Console into him new me year who our just an take think Name of the file 100Words_W.txt Number of words after format: 100 Vowels:134 Letters338 Digits 0 Longest word : because Shortest word a Average length of formatted words3.38 C: \UsersIphililsource repos \HW8 practice Debug\Hw8_practice.exe (process 54136) exited with code 0 To automatically close the console when debugging stops, enable Tools-Options->Debugging->Automatically close the conso le when debugging stops. CAUsers phili\source repos\HW8 practice Debug\HW8_practice.exe Enter the filename: Apology_W.txt ords list after formating the of this ebook is the anywhere project gutenberg ebook apology by plato for use 0 anyone no cost and with almost no restrictions whatsoever you may copy it give 1 away or re-use it under the the included terms of project gutenberg license withthis bk or online at www. gutenberg.org 94 95 96 97 98 unsigned sz words.length); words.resize(sz - 1); } while (flag == 0); return words; 100 101 102 103 104 105 106 107 108 109 110 Exception Unhandled //Function reverse string reverse(string str Unhandled exception at 0x74F 51812 in HW8_practice.exe: Microsoft C+ + exception: std:length error at memory location 0x00F3F1D4 if (str.length( 1 return str; else return reverse(st Copy Details > Exception Settings 112 113 114 115 116 int main( ifstream inputfile; string filename; string words, word, longest-"", shortest-"", nm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
