У меня есть программа для создания, и нас просят подсчитать, сколько раз каждая буква появляется в файле.Мы также должны посчитать слова.
Файл гласит:
hello word all is well.
Я разобрался, как считать слова, но я не знаю, как считать частоту.Я занимаюсь этим со вчерашнего дня, и я даже не знаю, как начать.
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
using namespace std;
const int SIZE = 78;
void wordcount(fstream& in, char character[], int& counter);
void freq(fstream& in, char character[], int& counter);
int main()
{
char character[SIZE];
int counter = 0;
fstream in;
wordcount(in, character, counter);
return 0;
}
void freq(fstream& in, char character[], int& counter)
{
}
void wordcount(fstream& in, char character[], int& counter)
{
int word = 0;
counter = 0;
in.open("mytext.dat");
{
while (!in.eof() && counter < SIZE)
{
in.get(character[counter]);
if (character[counter] == ' ' || character[counter -1] == '.')
{
++word;
}
counter++;
}
cout << word << " words" << endl;
//freq(in, character, counter);
in.close();
}
}