chemicalsSolution C code open file count number of words con

chemicals

Solution

// C++ code open file count number of words containing only letters

#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <vector>

using namespace std;

bool checkletterWord( string word)
{
bool letterWord = true;
int i=0;
while (i < word.size())
{
if (!isalpha(word[i]))
{
letterWord = false;
break;
}
  
i++;
}

return letterWord;
}

int main ()
{
string word;
int count = 0;
ifstream inputFile (\"input.txt\");

if (inputFile.is_open())
{
while ( true )
{
if(inputFile.eof())
break;

inputFile >> word;
if (checkletterWord(word) == true)
{
count++;
}
  
}
inputFile.close();
}

else cout << \"Unable to open file\";

cout << \"Number of words that contain only letters: \" << count << endl;

return 0;
}

/*
input.txt
Elmer Lod45ging is xyz92
Elmer Conference cmp56dr
Daffy Din2ner cmp56dr
Daffy Conf33erence cmp56pqq
Mickey Dinner cmp56pqq
Mickey Conference cmp56er

output

Number of words that contain only letters: 10


*/

chemicalsSolution// C++ code open file count number of words containing only letters #include <iostream> #include <string.h> #include <fstream>
chemicalsSolution// C++ code open file count number of words containing only letters #include <iostream> #include <string.h> #include <fstream>

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site