CS 1500 Class Lab Assignment #10 Read up to at least page 274 in "Tapestry" before preparing this lab. Your job is to write a program that: 1. asks the user to specify a word and a text file, 2. tells the user how many times the word occurs in the file. Here are a few sample runs: ============================================================ tester@alcyone:(~/CS1500/Lab10) a.out Please enter the name of the file you want checked: quotes Please enter the word you want to look for: lion number of times the word "lion" was read = 3 tester@alcyone:(~/CS1500/Lab10) a.out Please enter the name of the file you want checked: quotes Please enter the word you want to look for: goat number of times the word "goat" was read = 2 tester@alcyone:(~/CS1500/Lab10) a.out Please enter the name of the file you want checked: quotes Please enter the word you want to look for: forth number of times the word "forth" was read = 5 tester@alcyone:(~/CS1500/Lab10) a.out Please enter the name of the file you want checked: my_countw2.cc Please enter the word you want to look for: int number of times the word "int" was read = 3 ============================================================ If you want to see a program that does a job similar to the program you are being asked to write for this lab, look at my_countw2.cc in this directory. I want you to get more practice writing functions, so your program must have two functions: one function to get the word and filename from the user, and another function to do the work of counting the occurrences of the word and reporting the count. If you would like to have a "starter program," you may use the file countword.shell in this directory. Just save a copy of countword.shell under the name countword.cc, and add code to it. To write this program you will need to write a loop that reads a word (really, a string) at a time from the input file. Within the body of the loop, use an if-statement to test the latest string read to see if it is equal to the particular word that the user is interested in. If so, a counter should be incremented. GETTING IT RIGHT: Plan your lab program during the week. You don't have to write it out in totally correct C++ before the lab starts. However, you should at least try to write a specific step-by-step description of what your program will do. Write this plan so that it will be easy to translate into C++ when the time comes. Write some C++ statements in advance if you anticipate having difficulty with them. In lab, compare plans with your partner and execute a good compromise plan. Compile, test, and debug repeatedly until the program is working correctly. Use an editor to make a small text file. Pick certain words and put them into the file. Keep track of how many times these words occur in the file. Test your program using your file and the words you picked. This way you can compare the values the program outputs with what you know the values are supposed to be. You will know if the program is making errors. If you make an error in how you write the loop code, there is a possibility that your loop will become a "runaway" or "infinite" loop. If your program takes excessive time to finish, you can force it to abort by typing a control-c. SENDING IT IN: When finished make a script using this command: prompt> script lab10.script next cat your input file. In other words, if the input file you made for testing your program is called my_input then do the command prompt> cat my_input That way, the contents of your input file will be seen in the script. When I look at your script, I need to know what is in your input file so that I will be able to tell if your program got correct results. Next proceed to run the program several times, changing the word you ask to be counted each time. (You'll lose points if you don't do a reasonable testing job as described above.) After exiting the script, filter the script like this: prompt> cat lab10.script | col -b > temp prompt> mv temp lab10.script Next, check that the script is OK by doing this command: prompt> more lab10.script Press the space bar repeatedly to see more and more of the file, if necessary. If the script is OK, then e-mail it to me with this command: prompt> mail -v -s "lab10 script" john@ishi.csustan.edu < lab10.script PLEASE: The -s "lab10 script" part of the command above is very important to me. Reproduce it exactly. Check that the source file is OK by doing: prompt> more countword.cc Above, you have to replace "countword.cc" with whatever the name of your source file is. If the source file is OK then mail a copy of the source file with a command like this: prompt> mail -v -s "lab10 source" john@ishi.csustan.edu < countword.cc Of course, you need to replace "countword.cc" with the name of your source file if it is different.