This program will ensure that you can write a small program that uses arrays to keep track of some simple information. The program will then be expanded to use a class called maps instead of arrays. There are two parts, due at midnight on Friday March 21 and at 9am on Wednesday, Apr 2. Please note that our next programming quiz is also during recitation on April 2.
This is an open assignment, so you may consult with with others. However, you need to understand everything that you turn in (otherwise you'll do poorly on later assignments and quizzes), and you must clearly list the names of all others that you consult with.
Some students have asked for a clearer indication of what we want from your programming style. I have posted a summary of the most important issues at the top of our Programming Style Guide.
Due at midnight on Friday, March 21. Submit your program to Dora in the usual way. Late work will be accepted with a penalty through Wednesday, April 2.
Write a program that opens a file called words.txt. The program reads every word in the file, storing the word in a string variable called word. After reading a word, it should be printed on a separate line to cout. When the program finishes reading all the words in the file, it should print a 26-line table that indicates how many words began with each of the different letters 'a' through 'z' (lowercase letters only). At the end of the table, the program prints one more line to indicate how many words began with some character other than 'a' through 'z'.
I would like for you to read each word into a variable of type string. We will learn more about the string class in April. For this program, you need to know only a few things about strings:
wordin >> word; // word is a string variable wordin.ignore( );
Due at 9am on Wednesday, April 2. Submit your program to Dora in the usual way. Late work will be accepted with a penalty through Monday, April 7.
Modify your program from Part I so that it no longer prints each word as it is read. The table at the end is still printed. After printing the table, the program goes into a mode where it queries the user to type words. Each time the user types a word, the program prints the number of times that that exact word appeared in the input file.
I am requiring you to use a class called map to implement Part II of the assignment. I will produce a few written notes on how to use the map class, but you will need to get most of your information from me in class on March 18 through Mar 20. If you miss these lectures or recitation, then please try to get the needed information from another student.
The basic ideas:
map<string, int> words;
words["cheshire"] = 42; cout << words["cheshire"] << endl;
When you are developing your program, you should use a short test file that you create yourself with emacs. Once the program is working, you might use this story by Edgar Allan Poe for your input file.