the letter e is the most frequently used letter in the english language, and the letter z is the lease used. a friend of yours doing a blah blah believes that this may not be necessarily be true of writings of first year college students. to test his theory, he asks you to write a program that will take a text file and print, for each letter of the english alphabet, the number of times the letter appears in the file
hint: use an integer array of size 128 and use the ASCII values of letters to index into the array to store and retrieve counts for the letters
Hello fellow programmers i have this question for a project and i just want to know if i follow the instructions correctly
i am a an international student that live in the us so the language is quit a barrier
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const char FileName[] = "c:\\TestCount.txt";
int main()
{
string lineBuffer;
ifstream inMyStream (FileName); //open my file stream
if ( inMyStream.is_open() )
{
//create an array to hold the counts
int upperCaseCount[26] = {0};
int lowerCaseCount[26] = {0};
//read the text file
while ( getline (inMyStream, lineBuffer) )
{
//get a line of text
getline (inMyStream, lineBuffer);
//read through each in the lineBuffer
char oneLetter;
for (int n=0; n < lineBuffer.length(); ++n )
{
oneLetter = char( lineBuffer[n] );
if ( oneLetter >= 'A' && oneLetter <='Z' )
{ //decide if it is a capital
upperCaseCount[int(oneLetter)- 65]++; //make the index match the count array
}
if ( oneLetter >= 'a' && oneLetter <='z' )
{ //decide if it is a lower case
upperCaseCount[int(oneLetter)- 97]++; //make the index match the count array
}
}
inMyStream.close(); //close the file stream
//display the counts
for ( int i = 0; i < 26; i++ )
{
cout << char(i + 65) << "\t\t" << upperCaseCount[i] << endl;
}
for ( int i = 0; i < 26; i++ )
{
cout << char(i + 97) << "\t\t" << lowerCaseCount[i] << endl;
}
}
}
else
{
cout << "File Error: Open Failed\n";
}
return 0;
}