#include #include #include using namespace std; struct letter { int upper; int lower; }; void openFiles(ifstream &, ofstream &); void countLetters(letter[], ifstream &); void setZero(letter[]); void printLetters(letter[],ofstream &); int main() { letter countAlpha[26]; ifstream inFile; ofstream outFile; //call a function to open our files openFiles(inFile, outFile); //call a function to count all the letters in the file countLetters(countAlpha, inFile); //call a function to print results printLetters(countAlpha, outFile); return 0; } void openFiles(ifstream & in, ofstream & out) { //funtion to open input and output files //when returns to main both files are open char inputFileName[20]; char outputFileName[20]; cout << "Enter the name of your input file"; cin >> inputFileName; cout << "Enter the name of your output file"; cin >> outputFileName; in.open(inputFileName); if (!in) { cout << "Error opening file " << inputFileName << endl; exit(1); } out.open(outputFileName); if (!out) { cout << "Error opening file " << outputFileName << endl; exit(1); } //if declared: string inputFileNameString; //in.open (inputFileNameString.c_str()); } void setZeros(letter B[]) { int i; for (i = 0; i < 26; i++) { B[i].lower = 0; B[i].upper = 0; } } void countLetters(letter letA[], ifstream & in) { char ch; setZeros(letA); in.get(ch); while (!in.eof()) { if (ch >= 'a' && ch <= 'z') letA[ch - 97].lower++; else if (ch >= 'A' && ch <= 'Z') letA[ch - 65].upper++; in.get(ch); } } void printLetters(letter letA[], ofstream & out ) { int i; for (i = 0; i < 26; i++) { cout << static_cast(i + 65) << ' ' << letA[i].upper << " " <(i + 97) << ' ' << letA[i].lower << endl; } }