The Frequency of the lower case letters are:
Letter ╠ is 2478 times.
Letter ╠ is 476 times.
Letter ╠ is 1033 times.
Letter ╠ is 1328 times.
Letter ╠ is 4519 times.
Letter ╠ is 653 times.
Letter ╠ is 590 times.
Letter ╠ is 1635 times.
Letter ╠ is 2717 times.
Letter ╠ is 22 times.
Letter ╠ is 162 times.
I really don't understand why you have an array named asciiCode (or why you think having an int with the same name is a good idea) since it is completely superfluous as far as the logic goes.
1 2 3 4 5 6 7 8 9 10 11
cout << "The Frequency of the capital letters are: " << endl;
for(char caps = 'A'; caps <= 'Z'; caps++)
{
cout << "Letter " << caps << " is " << setw(4) << frequency[caps] << " times." << endl;
}
cout << "\nThe Frequency of the lower case letters are: " << endl;
for(char lower = 'a'; lower <= 'z'; lower++)
{
cout << "Letter " << lower << " is " << setw(4) << frequency[lower] << " times." << endl;
}
#include<iostream>
#include<fstream>
#include<iomanip>
usingnamespace std;
int main()
{
fstream inFile;
char oneChar;
char ASCII[128] = {0}; //127 characters of the ASCII +1
int frequency[128];
char code;
for(int ASCII = 0; ASCII < 128; ASCII++) //Loop through all the ASCII characters to get the frequency of each
{
frequency[ASCII] = 0;
}
inFile.open("101 Scientific Facts and Foreknowledge.txt", ios::in); //Reads file
if(inFile.fail()) //Check for error opening the file
{
cout << "Error: File not found!" << endl << endl;
}
else
{
oneChar = inFile.get();
while(inFile.eof() == false) //End of file
{
if(oneChar != ' ')
{
frequency[oneChar]++; //When not empty character
}
oneChar = inFile.get();
}
}
inFile.close();
cout << "The Frequency of the capital letters are: " << endl;
for(char caps = 'A'; caps <= 'Z'; caps++)
{
cout << "Letter " << caps << " is " << setw(4) << frequency[caps] << " times." << endl;
}
cout << "The Frequency of the lower case letters are: " << endl;
for(char lower = 'a'; lower <= 'z'; lower++)
{
cout << "Letter " << lower << " is " << setw(4) << frequency[lower] << " times." << endl;
}
return 0;
}
The Frequency of the capital letters are:
Letter A is 116 times.
Letter B is 115 times.
Letter C is 172 times.
Letter D is 57 times.
Letter E is 64 times.
Letter F is 49 times.
Letter G is 143 times.
Letter H is 101 times.
Letter I is 143 times.
Letter J is 64 times.
Letter K is 8 times.
Letter L is 64 times.
Letter M is 63 times.
Letter N is 39 times.
Letter O is 59 times.
Letter P is 56 times.
Letter Q is 0 times.
Letter R is 109 times.
Letter S is 83 times.
Letter T is 208 times.
Letter U is 11 times.
Letter V is 70 times.
Letter W is 45 times.
Letter X is 0 times.
Letter Y is 20 times.
Letter Z is 2 times.
The Frequency of the lower case letters are:
Letter a is 2478 times.
Letter b is 476 times.
Letter c is 1033 times.
Letter d is 1328 times.
Letter e is 4519 times.
Letter f is 653 times.
Letter g is 590 times.
Letter h is 1635 times.
Letter i is 2717 times.
Letter j is 22 times.
Letter k is 162 times.
Letter l is 1370 times.
Letter m is 663 times.
Letter n is 2445 times.
Letter o is 2411 times.
Letter p is 462 times.
Letter q is 18 times.
Letter r is 2095 times.
Letter s is 2482 times.
Letter t is 2884 times.
Letter u is 846 times.
Letter v is 456 times.
Letter w is 575 times.
Letter x is 85 times.
Letter y is 522 times.
Letter z is 23 times.
Press any key to continue . . .