| | |
word counter
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 244
Reputation:
Solved Threads: 5
Sure, if you post the code (copy and paste it inside of (code) (/code) tags, but use [ and ] rather than ( and ) ), we'll help you.
One thing that will help you on your way is to consider how you, as a human, count words. Typos aside, most words are separated by spaces, aren't they?
And punctuation is not part of a word. Gotta watch out for that. But, it generally defines a word's end.
One thing that will help you on your way is to consider how you, as a human, count words. Typos aside, most words are separated by spaces, aren't they?
And punctuation is not part of a word. Gotta watch out for that. But, it generally defines a word's end.
Scroll down to the bottom of this page and check out the Similar Threads.
http://img118.imageshack.us/img118/59/similar3db.th.gif
http://img118.imageshack.us/img118/59/similar3db.th.gif
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jul 2005
Posts: 244
Reputation:
Solved Threads: 5
Ahhh... I hope you're using C++, that'll make things much easier than in C...
Make a struct or class that stores the word and a counter, and put them in a vector or somewhere.
Why not store the words you encounter, and check if they are new?
If they are, add them and increment a count for them once.
If they aren't, only increment the appropriate value.
Then, read through your stored words at the end and display the word and the tally.
Make a struct or class that stores the word and a counter, and put them in a vector or somewhere.
Why not store the words you encounter, and check if they are new?
If they are, add them and increment a count for them once.
If they aren't, only increment the appropriate value.
Then, read through your stored words at the end and display the word and the tally.
•
•
Join Date: Jul 2005
Posts: 244
Reputation:
Solved Threads: 5
No.
It's far better to fail in the attempt than to not understand what you're doing.
Also: There's a topic at the top of the forum that states:
"We only give help to people who show effort."
If you post code that looks like you've really tried, then we'll help you with it.
Why don't you try this, though:
Write the program that counts words.
Then, put this in it.
I think that should work.
That's what you'll need to start storing things. What can you do with it? Make an array of them, if you know how many different words you'll have ahead of time.
Otherwise, put it in a linked list, if you know how to modify the class. Or, figure out how to modify the class to put it in a vector.
And now, I'm off work. Gotta bus ta catch.
Good luck!
It's far better to fail in the attempt than to not understand what you're doing.
Also: There's a topic at the top of the forum that states:
"We only give help to people who show effort."
If you post code that looks like you've really tried, then we'll help you with it.
Why don't you try this, though:
Write the program that counts words.
Then, put this in it.
C++ Syntax (Toggle Plain Text)
class wrdCnt { public: wrdCnt(){CString="";count=0;} CString getWord(){return _word;} int getCount(){return _count;} void setWord(CString word){_word=word;} void plusOne(void){_count++;} private: CString _word; int _count; };
I think that should work.
That's what you'll need to start storing things. What can you do with it? Make an array of them, if you know how many different words you'll have ahead of time.
Otherwise, put it in a linked list, if you know how to modify the class. Or, figure out how to modify the class to put it in a vector.
And now, I'm off work. Gotta bus ta catch.
Good luck!
![]() |
Similar Threads
- word counter, frequency, percentage (Java)
- letter and word counter (C)
- need help on word counter (C++)
Other Threads in the C++ Forum
- Previous Thread: Newbie to C++
- Next Thread: Building DLLs in VC++
Views: 2884 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






