Please someone help me been stuck on this for hours The TA a
Please someone help me been stuck on this for hours!! The TA and I couldnt figure this out its due tmrw! Please please help me. Thanks in advance
17) Letter frequency analysis. Write a function or series of function that when used will create a letter frequency analysis file. The function should take a string as a parameter. It should process this string one character at a time. The function (s) should create and output a file containing the string analyzed and letter frequency analysis of that string. Your frequencies should add up to 1.0 or 100% depending on implementation. (8) Example output file: Encrypted text is sometimes achieved by replacing one letter b another. To start deciphering the encrvption it is useful to get a frequency count of all the letters. The most frequent letter may represent the most common letter in English E followed by T, A, O and I whereas the least frequent are Q, 2 and X A: 0.05 B: 0.01 C: 0.03 D: 0.02 E: 0.17 F: 0.02 G: 0.02 H: 0.04 I 0.05 J: 0.00 K: 0.00 L: 0.05 M: 0.03 N: 0.07 Hint: Make use of arrays to make this much eas7er Hint: Don\'t worry about capitalization convert everything to upper or Tower case Hint: Ignore characters that are not letters Hint: To get the frequency, you also need to know how many letters are in the stringSolution
Code:
#include <cstdio> // std:s:cin, std::cout
#include<map>
#include <fstream>
#include <iostream>
using namespace std;
void stringanalysis(string str)
{
int i=0;
ofstream outfile;
outfile.open(\"ex.txt\");
outfile<<\"string analysis: \"<<endl;
map<char,int> hash;
while(i<str.size())
{
if(hash.count(str[i])==0)
hash[str[i]]=1;
else
hash[str[i]]++;
i++;
}
map<char,int>::iterator it =hash.begin();
for(it=hash.begin();it!=hash.end();it++)
{
outfile<<it->first<<\" \"<<(float(it->second)/float(str.size()))<<endl;
}
}
int main () {
stringanalysis(\"AAsfdsadfasdfsdfdsaf\");
return 0;
}
