word counter

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2005
Posts: 3
Reputation: sapex is an unknown quantity at this point 
Solved Threads: 0
sapex sapex is offline Offline
Newbie Poster

word counter

 
0
  #1
Sep 15th, 2005
hye...
can anybody help me to make a program that will allow the user to make a list of the words that occur in the text along with a count for each word of how many times it occurs....tq..
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Solved Threads: 5
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: word counter

 
0
  #2
Sep 15th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: word counter

 
0
  #3
Sep 15th, 2005
Scroll down to the bottom of this page and check out the Similar Threads.
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 3
Reputation: sapex is an unknown quantity at this point 
Solved Threads: 0
sapex sapex is offline Offline
Newbie Poster

Re: word counter

 
0
  #4
Sep 15th, 2005
actually i know to make a program that count the number of word..but now i don't know how to count a word that occur many times.so can you help me?..tq..
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Solved Threads: 5
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: word counter

 
0
  #5
Sep 15th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 3
Reputation: sapex is an unknown quantity at this point 
Solved Threads: 0
sapex sapex is offline Offline
Newbie Poster

Re: word counter

 
0
  #6
Sep 15th, 2005
ermm..i'm still in learning process of c++..but my lecturer ask me to do that program and submit today..so if you don't mind can you write a simple program that will count a word that occur many times 4 me?..thank you..
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Solved Threads: 5
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: word counter

 
0
  #7
Sep 15th, 2005
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.

  1. class wrdCnt
  2. {
  3. public:
  4. wrdCnt(){CString="";count=0;}
  5. CString getWord(){return _word;}
  6. int getCount(){return _count;}
  7. void setWord(CString word){_word=word;}
  8. void plusOne(void){_count++;}
  9. private:
  10. CString _word;
  11. int _count;
  12. };

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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 2884 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC