Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Art & Interaction in New Media
Homework 5 — Strings and Files
In preparation for this assignment, read Chapter 11 of the textbook.
Write a program that opens and reads one or more files containing English text, scans each one to accumulate a list of individual words appearing in that file, and then, when each input file has been scanned, writes to another file the list of unique words appearing in the entire set of input files — in alphabetical order — along with the number of occurrences of each word. Your pro- gram must also write the total number of words read (including duplicates).
Your program must ignore the cases of words. For example, ‘This’ and ‘this’ are the same word. On the other hand, singular and plural words are usually different — for example ‘file’ and ‘files’
— as are different verb forms such as ‘eat’ and ‘eats.’
Hyphenated words must be treated as one word:– for example, ‘deep-seated’ is different from the words ‘deep’ and ‘seated.’ You must also take into account possessives and contractions such as “don’t” and “Bob’s”. Note that “Bob’s” is a separate word from “Bob”. Numbers such as 10,000 or $50 or 45¢ should also be treated as words. You may assume that words do not break across lines.
A sample output file should be in a format resembling the following (continued on the next page):–
This is a traditional problem in C and C++ courses. The solution is Python is much simpler than in C. This problem is discussed in §11.6.3. However, there are significant differences between this assignment and the solution pre- sented in that section of the textbook.
20 Number of distinct words 790 Total words read
To allow for very long input files, the field width of the number of occurrences of each word should be at least five decimal digits. The counts need to be right-justified in the output. You print the number of distinct words and the total number of words read. All of the words should be in lower case.
For debugging, you may use the following text files:–
Resources/Kennedy.txt Resources/MartinLutherKing.txt
For fun, you may use any of Shakespeare’s plays, which can be downloaded from the Internet.