Question
In C++. Add as many comments as possible to make it easier to understand. Both parts need to be done separately Case.txt contains the following
In C++. Add as many comments as possible to make it easier to understand. Both parts need to be done separately
Case.txt contains the following
This file shows all the test case names, and what will be run for each test case
You can run an individual test case by name by saying "runcase NAME", where NAME is the name of the test case. If you type "runcase" it will give you the names of all the test cases.
When a test case runs, it saves the output of your program and compares it to the contents of the correct run of the program. The file containing the correct answer is NAME.correct, where NAME is the name of the test case.
If the test case fails, the Unix "diff" program shows you the differences between your output and the correct output. Lines that begin with are highlighting the differences.
Cases to be tested:
Test case "noargs": prog1
Test case "oneargs": prog1 sub1
Test case "threeargs": prog1 sub1 sub1 sub1
Test case "bf1": prog1 sub1 thisIsNotValid
Test case "bf2": prog1 thisIsNotValid sub1
Test case "nosubs1": prog1 nosubs nosubs
Test case "nosubs2": prog1 nosubs snowy
Test case "ss1": prog1 tsub lwinter
Test case "ss2": prog1 ssub lsnowy
Test case "strange": prog1 strangesubs strangein
Test case "punct1": prog1 punct badlyrics
Test case "badsub1": prog1 nosubs2 snowy
Test case "hardsub1": prog1 extrasub1 simple1
Test case "hardsub2": prog1 ssub snowy
Test case " nosubs": prog1 ssub small
Test case " emptyw": prog1 ssub empty
Test case " eboy": prog1 zevon excitable
For this assignment, we want to process WORDS in input files and, potentially, change some of those WORDS before printing them out. For our assignment, a WORD is a sequence of characters, separated by whitespace (that is, spaces, tabs, newlines, what cctype's isspace) returns true for) It is possible that a WORD may begin and/or end with one or more punctuation characters (what cctype's ispunct) returns true for). Such a WORD therefore has leading and/or trailing punctuation. A SUBSTITUTION is a line containing two WORDS. Your program will process a file containing SUBSTITUTIONS and a file containing WORDS. Each SUBSTITUTION in the first file is a replacement rule for WORDS in the second file. Your program should process the input files and apply the SUBSTITUTIONS to each input WORD before printing it out If a WORD in the input matches the first WORD in a SUBSTITUTION, it is replaced with the second word in the SUBSTITUTION, and then it is printed. If no SUBSTITUTION applies, the WORD is printed unchanged. For example, imagine that we have these SUBSTITUTIONS in the first file: foo many hi hello fish bicycle And suppose we are given this second file: So, hi everyone! This reminds me of foo things. I need a new fish for my birthday The resulting output would be: So, hello everyone! This reminds me of many things. I need a new bicycle for my birthday NUMBER OF CHANGES: 3 There are a few rules about the file of SUBSTITUTIONS 1. Blank lines are ignored 2. Lines that do not have two WORDS are ignored 3. Any leading and trailing punctuation in WORDS in a SUBSTITUTION are discarded 4. All of the letters in the WORDS in the SUBSTITUTIONS file should be converted to lower case 5 lf there are multiple SUBSTITUTIONS with the same first WORD, the last SUBSTITUTION is used, and all prior SUBSTITUTIONS for that WORD are discarded. Because we discard punctuation in the SUBSTITUTIONS, and because we convert to lower case, the following three lines in the SUBSTITUTIONS file all have the same first WORD. According to the rules, the last SUBSTITUTION is the only one that is retained. Hil!l! hello hi" hello Hi Hello When deciding if an input WORD matches a word in a SUBSTITUTION, the following rules should apply: 1. 2. 3. 4. Any leading and trailing punctuation is ignored when deciding if a WORD matches Any difference in case are ignored when deciding if a word matches When performing a replacement, leading and trailing punctuation from the WORD is preserved If the first letter after any leading punctuation in the input WORD is a capital letter, then the first letter in the resulting replacement should also be capitalized At most one replacement should be performed for each WORD 5. For example, imagine that we have these substitutions: foo hi hello fish bicycle And suppose we process this input: "Hi, everyone!" said the boy. "Yeah, hi! I want a brand new fish!" The resulting output would be: "Hello, everyone!" said the boy. "Yeah, hello! I want a brand new bicycle! NUMBER OF CHANGES: 3 The program should keep a count of the number of substitutions applied. If any replacements were made, the last line of output, after processing the entire input file, should be the line NUMBER OF CHANGES: N Where N is the number of replacements that were made The program takes two command line arguments: the first is the name of a file containing SUBSTITUTIONS, and the second is the name of a file containing WORDS. The program should process the SUBSTITUTIONS file according to the rules described above. Then, it should read the file containing WORDS, apply any replacements indicated from the SUBSTITUTIONS, and print out the result. Note that any and all whitespace between WORDS in input is printed unchanged to output If exactly two filenames are not provided, print "TWO FILENAMES REQUIRED, and stop. If a file cannot be opened or read for any reason, print the error message "BAD FILE EILENAME, and stop. It is possible that either or both of the files your program reads may be empty. It is also possible that the second file may contairn no words. Neither of these situations are errors. The program will be submitted and graded in separate parts: Part 1 Recognizing error cases associated with the wrong number of file names and files that cannot be opened. Handling cases with an empty SUBSTITUTIONS file Handling simple substitutions (no punctuation, no case changes). Part 2 Handling more complex cases in SUBSTITUTIONS files (duplicated words, mixed case words, punctuation, etc). Handling cases with punctuation at the start and/or end of WORDS in the WORDS file. Handling cases with mixed case for matches. Handling cases with capitalized WORDSthat are substituted. Note that both in your work" directory, and also on Moodle, there are files: e cases.txt . Cases.tar.gz runcase The cases.bxt file covers all the possible cases, as in what arguments are used for each test case. The cases.tar.gz is a zipped file containing all the input and output files. The runcase file is a shell script that lets you run a single test case. For this assignment, we want to process WORDS in input files and, potentially, change some of those WORDS before printing them out. For our assignment, a WORD is a sequence of characters, separated by whitespace (that is, spaces, tabs, newlines, what cctype's isspace) returns true for) It is possible that a WORD may begin and/or end with one or more punctuation characters (what cctype's ispunct) returns true for). Such a WORD therefore has leading and/or trailing punctuation. A SUBSTITUTION is a line containing two WORDS. Your program will process a file containing SUBSTITUTIONS and a file containing WORDS. Each SUBSTITUTION in the first file is a replacement rule for WORDS in the second file. Your program should process the input files and apply the SUBSTITUTIONS to each input WORD before printing it out If a WORD in the input matches the first WORD in a SUBSTITUTION, it is replaced with the second word in the SUBSTITUTION, and then it is printed. If no SUBSTITUTION applies, the WORD is printed unchanged. For example, imagine that we have these SUBSTITUTIONS in the first file: foo many hi hello fish bicycle And suppose we are given this second file: So, hi everyone! This reminds me of foo things. I need a new fish for my birthday The resulting output would be: So, hello everyone! This reminds me of many things. I need a new bicycle for my birthday NUMBER OF CHANGES: 3 There are a few rules about the file of SUBSTITUTIONS 1. Blank lines are ignored 2. Lines that do not have two WORDS are ignored 3. Any leading and trailing punctuation in WORDS in a SUBSTITUTION are discarded 4. All of the letters in the WORDS in the SUBSTITUTIONS file should be converted to lower case 5 lf there are multiple SUBSTITUTIONS with the same first WORD, the last SUBSTITUTION is used, and all prior SUBSTITUTIONS for that WORD are discarded. Because we discard punctuation in the SUBSTITUTIONS, and because we convert to lower case, the following three lines in the SUBSTITUTIONS file all have the same first WORD. According to the rules, the last SUBSTITUTION is the only one that is retained. Hil!l! hello hi" hello Hi Hello When deciding if an input WORD matches a word in a SUBSTITUTION, the following rules should apply: 1. 2. 3. 4. Any leading and trailing punctuation is ignored when deciding if a WORD matches Any difference in case are ignored when deciding if a word matches When performing a replacement, leading and trailing punctuation from the WORD is preserved If the first letter after any leading punctuation in the input WORD is a capital letter, then the first letter in the resulting replacement should also be capitalized At most one replacement should be performed for each WORD 5. For example, imagine that we have these substitutions: foo hi hello fish bicycle And suppose we process this input: "Hi, everyone!" said the boy. "Yeah, hi! I want a brand new fish!" The resulting output would be: "Hello, everyone!" said the boy. "Yeah, hello! I want a brand new bicycle! NUMBER OF CHANGES: 3 The program should keep a count of the number of substitutions applied. If any replacements were made, the last line of output, after processing the entire input file, should be the line NUMBER OF CHANGES: N Where N is the number of replacements that were made The program takes two command line arguments: the first is the name of a file containing SUBSTITUTIONS, and the second is the name of a file containing WORDS. The program should process the SUBSTITUTIONS file according to the rules described above. Then, it should read the file containing WORDS, apply any replacements indicated from the SUBSTITUTIONS, and print out the result. Note that any and all whitespace between WORDS in input is printed unchanged to output If exactly two filenames are not provided, print "TWO FILENAMES REQUIRED, and stop. If a file cannot be opened or read for any reason, print the error message "BAD FILE EILENAME, and stop. It is possible that either or both of the files your program reads may be empty. It is also possible that the second file may contairn no words. Neither of these situations are errors. The program will be submitted and graded in separate parts: Part 1 Recognizing error cases associated with the wrong number of file names and files that cannot be opened. Handling cases with an empty SUBSTITUTIONS file Handling simple substitutions (no punctuation, no case changes). Part 2 Handling more complex cases in SUBSTITUTIONS files (duplicated words, mixed case words, punctuation, etc). Handling cases with punctuation at the start and/or end of WORDS in the WORDS file. Handling cases with mixed case for matches. Handling cases with capitalized WORDSthat are substituted. Note that both in your work" directory, and also on Moodle, there are files: e cases.txt . Cases.tar.gz runcase The cases.bxt file covers all the possible cases, as in what arguments are used for each test case. The cases.tar.gz is a zipped file containing all the input and output files. The runcase file is a shell script that lets you run a single test case
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started