Question
Quick help! For this assignment, the following definitions apply: Whitespace is a sequence of one or more horizontal or vertical non-printed spaces. A sequence of
Quick help!
For this assignment, the following definitions apply: Whitespace is a sequence of one or more horizontal or vertical non-printed spaces. A sequence of spaces, tabs, newlines, form feeds, etc are whitespace. A character is whitespace if isspace() from cctype is true A word is a sequence of one or more non-whitespace characters, separated by whitespace A goodword is a word that has only letters and numbers in it A realword is a word that has only letters in it A capword is a word that begins with an upper case letter An acronym is a word that contains only uppercase letters
Note that by these definitions:
1.hello is a word, a goodword, and a realword 2.Hello is a word, a goodword, a realword, and a capword 3.Wont is a word and a capword 4.Art3mis is a word, a goodword, and a capword 5.SCUBA is a word, a goodword, a realword, a capword, and an acronym 6.C3PO is a word, a goodword and a capword 7.higgledy-piggledy is a word
The assignment is to write a program that copies from input to output. Based on command line arguments, the program may modify the input before generating output, and may gather and print statistics.
The command line arguments are zero or more flags followed by an optional filename. A flag is a command line argument that begins with a hyphen. If a filename is provided, it must be the last command line argument, and can not begin with a hyphen. If a filename is provided, then the file with that name provides the input to the program. If a filename is not provided, then the program should read the standard input. All output must be sent to the standard output. The program should count the number of characters, lines, words, goodwords, realwords, capwords and acronyms in the input and the output The program may, based on command line flags, print out these counters when it has completed the processing of input files.
The program must also track the longest word, goodword, and realword in the input, and may print out this information based on command line flags. Note that it may be the case that there are multiple words with the same length. The following are the complete set of valid command line flags:
-q | Quiet mode - causes the program to NOT copy input to output |
-s | Squish mode - causes all whitespace to be squished to so that only the last whitespace character in a sequence of whitespace is printed |
-c | Censor mode - causes the program to only print a word if it is a realword. When in censor mode, any whitespace after the realword is also printed. If a word is not a realword, then it is not printed, nor is any of the whitespace after it |
-p | Print statistics mode - causes the program to print the counters it has tallied during the run of the program, in the format given below |
-l | Length mode - causes the program to print out the word length information it has tallied during the run of the program, in the format given below |
The flags are optional. They may not appear at all. They may appear in any order. If a given flag appears multiple times, the program should behave as though the flag only appeared once.
If the program encounters a flag that is not one of the valid flags, it should print the invalid flag followed by a space and the message INVALID FLAG, then terminate. If the program has been asked to run in squish mode and/or censor mode, AND if the program has also been asked to run in quiet mode, this is an error. The program should print the message CONFLICTING FLAGS, then terminate.
If the program is given the name of a file that cannot be opened, the program should print the filename followed by a space and the message CANNOT OPEN, then terminate. If the program is given the name of more than one file, then the program should print the message TOO MANY FILES, then terminate.
When in length mode, the program should print the following after processing all output: Word (length N): wordlist Goodword (length N): wordlist Realword (length N): wordlist Where uppercase N represents the length, and wordlist represents a comma separated list of words of that length, in sorted order. If there are no words of a particular type, then the line for that type of word should be skipped. When in print statistics mode, the program should print the following after processing all output: Characters M in N out Lines M in N out Words M in N out Goodwords M in Realwords M in Capwords M in Acronyms M in Where uppercase M and N represent the integer counts.
In the case where both length mode and print statistics mode are specified, the statistics should be printed first.
You will be provided with a set of test cases, including some input files. The following are the test cases for the program. Note that < file exercises the read from standard input test.
Program compiles | |
Prog1 -x | -x INVALID FLAG |
prog1 -quiet | -quiet INVALID FLAG |
prog1 -s -q | CONFLICTING FLAGS |
prog1 -q -c | CONFLICTING FLAGS |
prog1 badfile | badfile CANNOT OPEN |
prog1 -q badfile | badfile CANNOT OPEN |
prog1 -x badfile | -x INVALID FLAG |
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