Hey everyone,
This is my first time posting here. Sorry if it is a repost.
I just started learning C++ about 2 months ago and I need some help with an assignment.
"Write a program frequencies.cpp that reads from input and outputs the frequencies of the letters in the text(not case sensitive)."
This much I have already done.
Now as a challenge we are supposed to modify our code so that it is able to distinguish between 4 languages (for example: english, french, german and italian) using letter frequencies of each language (http://en.wikipedia.org/wiki/Letter_frequency).
I'm not sure how to proceed can anyone point me in the right direction?
Thanks!
#include <iostream>
#include <ios>
usingnamespace std;
int main () {
int freq[27]; //each index counts a letter
for (int i =0; i<27; ++i) {
freq[i]=0; //initialize each letter to 0
}
unsigned t=0;
char x;
cout << endl;
cout << "Insert text to count letter frequency. Press '$' to escape"<<endl;
//'$' signals end of input
while (x!='$') {
cin >> x;
cin >> noskipws;
++t; //increment letter cout
if (x <= 90 && x >= 65) {
x += 32; //no distinction between upper/lower case
}
if (x<=122 && x>= 97) {
++freq[x-97];
}
else {
++freq[26]; //not a letter
}
}
for(int i=0; i<26; i++) //print on screen.
{
cout << "\t"<<char(i+97)<<"\t: " <<freq[i]<< " of " << t-1 << endl;//do not count escape '$'
cout << endl;
}
cout << "\t"<<"Other\t: "<<freq[26]-1<<" of " << t-1 << endl;
return 0;
}