WSQ 12 – Word Count

flickr photo by wiccked https://flickr.com/photos/wiccked/57466134 shared under a Creative Commons (BY-NC-ND) license

What to Do

Create a program that asks the user for a word which will be your search word and the name of a file to open and search for that word. Then create a function that will receive two parameters (both string) representing those two data points. This function returns the number of occurrences of that word in that file.

Details

You will need to open a file and read the text line by line. This is straight forward in Python since you can treat the file as a list of lines (strings) and iterate over that using a for loop. Check the section “Looping over a file object” in this link for an idea but your book also has this information (or on Lynda.com) http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python

For C++ this is similar in solution as for the Python group, this link may help you but feel free to find others: http://www.cplusplus.com/doc/tutorial/files/ Also remember to check the videos you have access to on Lynda.com

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ12 on your post so our blog hub picks that up.

You should include your code as a link to GitHub. You really should start using your GitHub repository now. If you need help on that, just ask Ken or your classmates.

If you have not seen my video yet about the GUI tutorial for GitHub, go check that out: http://youtu.be/YQmlksGFZWY

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC101 so we all see your question posted there.

flickr photo by wiccked https://flickr.com/photos/wiccked/57466134 shared under a Creative Commons (BY-NC-ND) license
flickr photo by wiccked https://flickr.com/photos/wiccked/57466134 shared under a Creative Commons (BY-NC-ND) license

CC BY-SA 4.0 WSQ 12 – Word Count by Ken Bauer is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *