Raised This Month: $ Target: $400
 0% 

C++ help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jheshka
Senior Member
Join Date: Dec 2005
Old 03-11-2009 , 13:00   C++ help
Reply With Quote #1

I have to accomplish this:

Quote:
Create a wordCount application that displays the number of words and the average word length in a text file named source.txt. Consider a to be any sequence of letters terminated by nonletters. For example, forty-nine is two words.
I don't want anyone to do it for me, because it's for a course, but my teacher can't really provide any help, because he doesn't know C++.
Main reason my teacher can't really help me, is because this is supposed to be a java course, and I'm doing C++, because I've already done java, extensively.
If anyone could link me to a few useful sites, I'd appreciate it a lot.
(I've tried google, and nothing was too spectacular)

I don't think I'll have much trouble with the file writing... But the string manipulation is going to be a bit of a pain.
__________________
James

Last edited by Jheshka; 03-11-2009 at 13:03.
Jheshka is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-11-2009 , 13:04   Re: C++ help
Reply With Quote #2

http://www.yolinux.com/TUTORIALS/Lin...ringClass.html
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Jheshka
Senior Member
Join Date: Dec 2005
Old 03-11-2009 , 13:06   Re: C++ help
Reply With Quote #3

Quote:
Originally Posted by Hawk552 View Post
You, sir, are full of win.
Thank you very much.
__________________
James

Last edited by Jheshka; 03-11-2009 at 13:13.
Jheshka is offline
Jheshka
Senior Member
Join Date: Dec 2005
Old 03-11-2009 , 13:31   Re: C++ help
Reply With Quote #4

Mostly basic C++ functions... Using cygwin, so I guess that's considered a linux platform.



Got a quick question though..
How can I have the
str.length() function return the length of the entire string, not stopping after a space.

Using cin << to get the string.
__________________
James
Jheshka is offline
BAILOPAN
Join Date: Jan 2004
Old 03-11-2009 , 14:03   Re: C++ help
Reply With Quote #5

cin stops at a space, not length().
__________________
egg
BAILOPAN is offline
Jheshka
Senior Member
Join Date: Dec 2005
Old 03-11-2009 , 14:09   Re: C++ help
Reply With Quote #6

I see.. How should I go about getting a string input then?
__________________
James
Jheshka is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-11-2009 , 14:22   Re: C++ help
Reply With Quote #7

For starters, you'll need the file stream header (fstream.h). If you haven't learned how to open files using this, look it up.

Use a while loop which keeps gathering each word, then stop when it returns 0. Each time you iterate through the loop, get the string length and then add that value to a total length variable. Divide this total length variable by the number of iterations and print out this average value as well as the number of iterations.

Done.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode