Answer the question
In order to leave comments, you need to log in
A program for calculating the relative frequency of occurrence of a word in a text. How should she look?
Hello, I want to say right away that you don’t need to write anything for me, I just want a consultation. Dali write a program:
The relative frequency of occurrence of each word in the text is calculated, the boundaries of words are symbols: dot, comma, colon, semicolon, space, brackets, dash, question and exclamation marks.
The text is entered from the keyboard, it should be possible to write it to a file; output of results to the screen, and at the request of the user to the printer or to a file.
How do you see it, and how do you think the result of the program execution should look like?
The program must be in Delphi.
I imagine the program like this:
There is a text field (Memo), text is inserted into it, a button is pressed - calculate.
The result will look like this:
1. Я - 2 раза.
2. и - 3 раза.
3. машина - 1 раз.
... //И так все слова в тексте
Answer the question
In order to leave comments, you need to log in
If we abstract from the programming language and the language of the text, then here is an example: Frequency analyzer of English words, written in... . Look at the code, you might get some ideas for yourself.
You are generally thinking correctly, but instead of ordinary arrays, it is better to use a data structure like HashMap. This is similar to an array, but the key may not be a number, but a string. Those. the key is the word, the value is the frequency. Then getting and changing the frequency word by word will be faster than bypassing a regular array.
I don't know if Delphi has its own map, but in my opinion, TStringList can be adapted for this case: www.delphibasics.ru/TStringList.php
You can look for some other options, but HashMap is basically what you need. Good luck.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question