Divide and conquer.
Separate your task into smaller subtasks and engage them one by one.
I will show example of such subtasks for your first assigment (I'll remove some parts which I do not completely understand or which are not used later)
Find a text of 10000 words, count letters of each word, save the words and letters in map type container they need to be lined from shortest to longest word.
The results than have to be showed in a txt file. Find 100 most often used words. Use iostream, string and map libraries. Has to be done in OOP style. |
So problems are:
1)
Open input file. Decide if file name would be hardcoded, received as command line parameter or entered by user. Depending on what you choose, this task can spawn subtasks. I will assume that name is hardcoded.
2)
Read words. It moght be easy or hard depending on file contents. I will assume that it is just bunch of words separated by whitespace, no punctuation.
3)
Save the worlds in a map. You need to find most frequent words, so word will be the key and amount of times word is encountered will be value. As you have a requirement: "
they need to be lined from shortest to longest word", then you need to provide your own comparison function which does that which spawns a subtask:
a)
Create a comparison function. It needs to sort words first by length, then lexicographically (default sorting).
4)
Find 100 most used words. There are differnt ways to do that, try to think one yourself.
5)
Open output file. Again, I will assume that filename is hardcoded.
6)
Write to output file. First decide how your output will look like. Then code it. Outputting in file is no different from outputting on screen actually.
With these smaller tasks it should be easier for you to think and search reference for hints. If something still looks complex to you, divide it further.
Ask if you have concrete questions or problems regarding your actual code.