DUE: Tuesday, May 18 before 11:00pm
Collaboration is strictly FORBIDDEN. Programs must represent YOUR OWN original work. Sharing code or team-coding are not allowed for this assignment. Copying code from ANY source (any book, current or past students, past solutions, the web, etc.) is not allowed. Cooperation to the extent of helping to debug, or discussing the general approach to solving the problem is encouraged, but should never involve communicating code or even pseudo-code or explicit algorithms. Your code must be unique -- if it is not, we will find out, and will treat it as a case of flagrant academic dishonesty.
You must turn in a C++ source file (and only a C++ source file). The name for your source file should be as6.cpp.
Turn in online to the appropriate folder for your lab section (e.g., as6_sec20 for students enrolled in lab section 20). If you turn your assignment in to the wrong folder, your assignment may not be graded. If it is graded, you will lose 2 pts (out of 10).
Remember to include the header as it is in the template provided on the class website.
Write a program that takes an input file, input.txt and rewrites it to an output file, censored.txt, but with all 4-letter words replaced by ****. Also, the output file must have as close to 40 characters per line as possible without going over 40.
A member function of the string class called length() will come in handy. If you have a string variable named word, calling the member function of this object will return the length of the string. For example, if word has the value "Kris", calling word.length() will return the value 4.
You should also have a separate output file, words.txt, that is a list of all 4-letter words that were replaced. Finally, you should output to the screen how many 4-letter words were replaced.
You may use this input file, input.txt, to help you test your program. For reference, I have supplied the following 2 output files that should be generated given this sample input file:
The replaced 4-letter words may include words like "pay," which include punctuation. Also, you may ignore words like "such," that are 4-letter words, but because they have punctuation at the end appear to be 5-letter words.
The following is what should output to the screen if you use the sample input file given.
23 words were censored!For 1 pt BONUS don't replace words like "pay," and do replace 4-letter words like "such," that have punctuation after them. Of course, you would still need to add the punctuation to the end of the replacement (i.e., "****," would replace "such,")
If your program does not compile, it will not be graded. Compile your code often. Only write a small portion of code before checking that it still compiles. This way when you get a syntax error, you can be fairly certain the error is in the part you just wrote.
5 pts: Correct output
- (1 pt) censored.txt has no more than 40 character's per line.
- (1 pt) censored.txt has as many words as possible for each line
up to 40 characters without going over 40 characters.
- (1 pt) All 4-letter words have been replaced in censored.txt.
- (1 pt) words.txt has all 4-letter words that were replaced.
- (1 pt) The number of words replaced is output to the screen.
3 pts: File I/O
- (1 pt) File objects connected (opened) correctly.
- (1 pt) Program exits (with error message) if a file open failed.
- (1 pt) File objects disconnected (closed).
2 pts: Style
- (.5 pts) Good variable/function names
- (.5 pts) Proper indentation/spacing
- (.5 pts) Good comments (including header and function comments)
- (.5 pts) No line wraps