This is for C i will rate right away Thanks 17 Letter freque

This is for C++, i will rate right away! Thanks!

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.

Hint: Make use of arrays to make this much easier

Hint: Don’t worry about capitalization – convert everything to upper or lower case.

Hint: Ignore characters that are not letters

Hint: To get the frequency, you also need to know how many letters are in the string

Solution

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;
}

This is for C++, i will rate right away! Thanks! 17) Letter frequency analysis. Write a function or series of function that when used will create a letter frequ

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site