I just realized that the directions were a bit more specific than I remembered from class.
Here's the question:
1) Write a function findFreq that takes a character array (c-string) and returns the frequency of each
alphabetic letter. It should have a function heading similar to,
void findFreq(char text[], char letter[], int frequency[])
The character array letter is for 26 uppercase letters and int array frequency is to store the
frequency of letters.
2) Write a function printFreq that outputs a list of all the letters that occur in the text and the number
of times each letter occurs. The letters should be listed in alphabetic order. The function printFreq
should have a function heading similar to,
void printFreq(char letter[], int frequency[])
3) Write a function setText that takes a character array and make the following substitutions to the
letters:
Change letter ‘A’ -> letter ‘J’,
letter ‘I’ -> letter ‘Q’,
letter ‘S’ -> letter ‘Z’.
You can call function findFreq and printFreq when testing function setText.
4) The input file hw.txt is provided to you. Your function main should read a C-string from
the input file and perform several function calls to above user-defined functions.
Here's what I've been working with:
I thought the assignment was to JUST make the program output the letter frequency in the text file.
Code:#include <fstream> #include <iostream> using namespace std; int main() { int freq[128]; ifstream inFile; char ch; inFile.open("C:\\Users\\me\\Desktop\\hw.txt"); for (int k = 0; k < 128; k++) { freq[k] = 0; } ch = inFile.get(); while (ch != EOF) { cout << ch; ch = toupper(ch); freq[ch]++; ch = inFile.get(); } cout << endl << "Letter: Frequency:" << endl; for (char ch = 'A'; ch <= 'Z'; ch++) { cout << ch << " : " << freq[ch] << endl; } system("pause"); return 0; }
I'm not a very good programmer, if someone is up for a challenge, and is in a very generous, helpful mood, I appreciate