The program is suppose to read from a text and count each letter of the alphabet and the counter_other counts everything else except whitespace. I'm having trouble putting this together, especially the switch. We have not gone over strings yet in class so I don't think I'm suppose to use it in the program.
#include<iostream>
#include<fstream>
#include<cctype>
#include<string>
using namespace std;
void readData(istream &, int []);
void initialize(int[], int);
void printResults(ostream &, int []);
const int SIZE= 27;
int main()
{
int letterCount[SIZE];
char index;
ifstream infile;
ofstream outfile;
initialize(letterCount, SIZE);
readData(infile, letterCount);
printResults(outfile, letterCount);
infile.close();
outfile.close();
system("pause");
return 0;
}
void initialize(int letterCount[], int n)
{
for(int i=0; i<SIZE; i++)
letterCount[i] = 0 ;
}
void readData(istream &in, int letterCount[])
{
int counter=0;
char index;
index = in.get();
in>>index; // priming read
while(index) // while last read was successful
{
in>>index; // get next character
if(index=0; index<27; index++)
case 'A': counter[0]++; break;
case 'B': counter[1]++; break;
case 'C': counter[2]++; break;
case 'D': counter[3]++; break;
case 'E': counter[4]++; break;
case 'F': counter[5]++; break;
case 'G': counter[6]++; break;
case 'H': counter[7]++; break;
case 'I': counter[8]++; break;
case 'J': counter[9]++; break;
case 'K': counter[10]++; break;
case 'L': counter[11]++; break;
case 'M': counter[12]++; break;
case 'N': counter[13]++; break;
case 'O': counter[14]++; break;
case 'P': counter[15]++; break;
case 'Q': counter[16]++; break;
case 'R': counter[17]++; break;
case 'S': counter[18]++; break;
case 'T': counter[19]++; break;
case 'U': counter[20]++; break;
case 'V': counter[21]++; break;
case 'W': counter[22]++; break;
case 'X': counter[23]++; break;
case 'Y': counter[24]++; break;
case 'Z': counter[25]++; break;
default : counter[26]++; break;
}
return;
}
void printResults(ostream &out, int letterCount [ ] )// Prints each alphabet character and its frequency
{
ofstream outfile("C:/Users/gina 0/Documents/histogram.txt");
outfile<< " LETTER "<< " OCCURRENCES "<< " PERCENTAGE " <<endl;
for (int i = 0; i < 26; i++)
{
if (letterCount[i] > 0)
{
outfile << letterCount[i] << " " << char('A' + i) << endl;
}
outfile.width(15);
}
outfile.close();
return;
}