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

I am no getting the ryt output in the function nonletters, searchstr, output. /*

ID: 3646380 • Letter: I

Question

I am no getting the ryt output in the function nonletters, searchstr, output.

/*Mario Valles Assignment #11
This program get data from an stored file and computes (describe in the output)
and organize the text to display in a readeable form. Also, the program is going
to localize and count all the times that a search string appears in the program.
Input:
The input is going to be from another file using filestream.
The user is going to be prompt the input the name of the file and the search
string.
The file data input is going to be words, this includes letters,
digits and symbols.
Output:
The output is going to be display on th sreen
The output is going show how many:
letters, sentences, non-letters/non-whitespaces are on the file,
consonants, and the search string appear.
*/

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

void format(string&);
int sentences(string);
int letters(string);
int nonLetters(string);
int searchStr(string, string);
int consonants(string);
void output(string);

int main()
{
ifstream in; //variable to get input from another file
string inputfile, //gets the name of the input file
searchString, //gets the search string
word; //get the word
int countWords, //count the number of words in the file
countSentences, //count the number of sentences in the file
countLetters, //count the number of letters in the file
countConsonants, //count the number of consonants in the file
countNONletters, //count the number of non letter characters
countSearchString; //count the number of time the search string appears
char whitespace; //get the whitespace betweent the words;

cout << "Please enter the name of the input file " << endl;
cin >> inputfile;
cout << "Please enter the search string " << endl;
cin >> searchString;

cout << "Mario Valles Assignment #11" << endl;
cout << "Inputfile: " << inputfile << endl;

in.open(inputfile.c_str());

in >> word;

countWords = 0;

while(in)
{

format(word);

countSentences += sentences(word);
countLetters += letters(word);
countConsonants += consonants(word);
countNONletters += nonLetters(word);
countSearchString += searchStr(word, searchString);

output(word);
countWords++;
in >> word;
}

cout << " # of words: " << countWords << endl;
cout << "# of sentences: " << countSentences << endl;
cout << "# of letters: " << countLetters << endl;
cout << "# of consonants: " << countConsonants << endl;
cout << "# of non-whitespace, non-letter characters: " << countNONletters
<< endl;
cout << "# of occurrences of "" << searchString << "": "
<< countSearchString << endl;

return 0;
}

void format(string& words)
//format gets pass the words in the file to change the format.
//The function leave the first letter unchange,
//and the rest letter it change them into lowercase, if they
//are not. The value pass back is the word with all but the first
//letter in lowercase.
{
for (int i = 1; i < words.length(); i++)
{
if(isupper(words[i]))
words[i] = static_cast<char>(tolower(words[i]));
}
}


int sentences(string words)
//sentences gets the words passed in from the text and computes them
//to tell how many sentece are in the file. Then it return the total
//number of sentences
{
int sentenceCount = 0; //count the amount of sentence

for (int i = 0; i < words.length(); i++)
{
if(words[i] == '.' || words[i] == '!' || words[i] == '?')
sentenceCount++;
}

return sentenceCount;
}

int letters(string words)
//letter get the value of the words passed in from the text. Then it computes
//how many letter are in the file. The function returns the number of letter
//in the file.
{
int letterCount = 0; //count the amount of letters

for (int i = 0; i < words.size(); i++)
{
if(isalpha(words[i]))
letterCount++;
}

return letterCount;
}

int nonLetters(string words)
//nonLetters get the value of a word. Then it computes how many non-letters are in
//the word. Then, the number of non-letters is returned.
{
int nonLetterCount = 0; //counts the amount of nonletters;

for (int i = 0; i < words.length(); i++)
{
if(isdigit(words[i]) || ispunct(words[i]))
nonLetterCount++;
}
return nonLetterCount-1;
}

int searchStr(string words, string searchString)
//searchStr function gets the word and the search string. The it compare it
//compares them. If the value is true it returns the quantity 1 use for counting
//Else the function returns the quantity of 0.
{
int searchStringCount = 0; //count how many the
//search string appears
size_t n ; //gets the position of searchString on words
n = words.find(searchString);
if (int(n) != string::npos)
if(n > 0)
return searchStringCount = 1;
else
return 0;
}

int consonants(string words)
//consonants function gets the a string(word) and counts how many
//consontants are in each string(word). Then the value is returned.
{
int consonantCount = 0; //counts the amount of consonants

for (int i = 0; i < words.length(); i++)
{
if(isalpha(words[i]))
{
if(words[i] == 'a' || words[i] == 'e' || words[i] == 'i'
|| words[i] == 'o' || words[i] == 'u')
consonantCount = consonantCount;
else if(words[i] == 'A' || words[i] == 'E' || words[i] == 'I'
|| words[i] == 'O' || words[i] == 'U')
consonantCount = consonantCount;
else
consonantCount++;
}
}

return consonantCount;
}

void output(string words)
//Output will get passed the value of a string(word).Then output do some computations
//to display a maximum of 40 character per line.
//The computed words/sentences are then displayed in a format of less than 40 character per line.
//No values are passed back.
{
static int charCount = 0; //count the number character per line

charCount = charCount + words.length() + 1;

cout << words << " ";

if(charCount == 41 || charCount == 40)
{
cout << endl;
charCount = 0;
}
}



Explanation / Answer

Can you please tell which part of the output is not correct?