By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,407 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,407 IT Pros & Developers. It's quick & easy.

Count frequency of prepositions from input text

P: 10
here' s the description:
================================================== =======
You are asked to develop a C++ program that reads a text Żle given by the user (e.g. test.txt), and output
the frequency of the prepositions contained in the text Żle on the screen. Your program shall provide a simple
interface for the user to input the name of a text Żle and exit the program.
================================================== =======
I don't expect you to write the code for me...
Just tell me what is the idea of the uqestion,OK?
Jun 4 '07 #1
Share this Question
Share on Google+
8 Replies


P: 31
here' s the description:
================================================== =======
You are asked to develop a C++ program that reads a text Żle given by the user (e.g. test.txt), and output
the frequency of the prepositions contained in the text Żle on the screen. Your program shall provide a simple
interface for the user to input the name of a text Żle and exit the program.
================================================== =======
I don't expect you to write the code for me...
Just tell me what is the idea of the uqestion,OK?
For instance, you can take each word, one by one from the text file, and compare it with a list of english prepositions, you have to count how many have been found, think about something that serves as a list and a counter of each member...



(I DIDN'T WANT TO REPORT, I MISSED THE LINK FOR THE REPLY, SO SORRY)
Jun 4 '07 #2

AdrianH
Expert 100+
P: 1,251
(I DIDN'T WANT TO REPORT, I MISSED THE LINK FOR THE REPLY, SO SORRY)
??? As long as you didn't hit the 'send report' button, you didn't actually report, so relax. ;)


Adrian
Jun 4 '07 #3

AdrianH
Expert 100+
P: 1,251
here' s the description:
================================================== =======
You are asked to develop a C++ program that reads a text Żle given by the user (e.g. test.txt), and output
the frequency of the prepositions contained in the text Żle on the screen. Your program shall provide a simple
interface for the user to input the name of a text Żle and exit the program.
================================================== =======
I don't expect you to write the code for me...
Just tell me what is the idea of the uqestion,OK?
What Sieira said sounds right. You may wish to look up the STL map class to help you do this fairly easily.


Adrian
Jun 4 '07 #4

P: 21
here' s the description:
================================================== =======
You are asked to develop a C++ program that reads a text Żle given by the user (e.g. test.txt), and output
the frequency of the prepositions contained in the text Żle on the screen. Your program shall provide a simple
interface for the user to input the name of a text Żle and exit the program.
================================================== =======
I don't expect you to write the code for me...
Just tell me what is the idea of the uqestion,OK?
Well, what i would do is, but it might be a bit to much of topic, i don't know that for sure, so you be the judge ^^.
Thinking about reusability and a nice design i'd try something like this.

You can read in two files: one file of prepositions and another one containing the text you have to search.
Read all the prepositions and put them in a list of records ( or structs, or classes with the instructions to increment occurences, setters and getters etc. ) containing for example, a string and a int counter
Every 'node' you insert in the 'list' has a string specified and that counter. Every time you find a word that's in your list you increment the counter. of that specific word.

Offcourse you could also use an array to store the prepositions but then you'd have to you'd either have to:
-make a constant for the array size
-run the preposition file two times, one time to count the number of prepositions and one time to actually add them in the (dynamic) array.
-Put at the top of the prepositions file the number of prepositions specified in the file.

Offcourse how you want to implement it is totally our choice. But i do believe this has some nice potential. I like the object oriënted design and the classes, and it has some nice potential for reusability ! :D
I believe, depending on the number of prepositions it might be better to use arrays ( as they the number of propositions becomes considerably larger ) though i don't think it'll matter anything for such few elements.
Offcourse if you really want to top it you could even hold an extra, small array that holds the last 10 occurences of words also immediately specifying their index in the big array/list of prepositions so that more common prepositions won't require the 'long' search of the big array/list anymore.
But the last bit is just over the top ^^

Well i hope this gives you an idea of how you could implement such a program, it's allways good to give it some thought before you actually implement it. :)

Hope this helps.
Cheers,
-Tom
Jun 4 '07 #5

P: 31
[...]I believe, depending on the number of prepositions it might be better to use arrays ( as they the number of propositions becomes considerably larger ) though i don't think it'll matter anything for such few elements.[..]
-Tom

one list of prepositions cannot become large, Anyway, Tom's solution looks much more elegant
Jun 5 '07 #6

P: 21
one list of prepositions cannot become large, Anyway, Tom's solution looks much more elegant
Thanks ! :D

And yes, the list of prepositions indeed can't become larger, but when you start using the file to recognize other paterns than only prepositions it could become bigger, but i shouldn't have used the word prepositions there :D.
Jun 5 '07 #7

AdrianH
Expert 100+
P: 1,251
I would still use a map to store your prepositions (key) and your count (value). That way it is fast and you don't have to reinvent some search mechinism.


Adrian
Jun 5 '07 #8

P: 21
I would still use a map to store your prepositions (key) and your count (value). That way it is fast and you don't have to reinvent some search mechinism.


Adrian
[hijack_post]
Hmm, what's the map ? Is it built in in C++ ? :)
Because, i have programming experience in Oberon, but i'm quite new to C++ so i'm not all that familiar with all it's possibilities yet.
Could you explain how to use a map please ? :D
Thanks in advance :)
[/hijack_post]

-Tom

PS: Hijack is spelled like that right ?
Jun 5 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.