Question
In this assignment we will be reading from a file, or from standard input, and performing some analysis based on options given to the program.
In this assignment we will be reading from a file, or from standard input, and performing some analysis based on options given to the program. ! 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: ! i. hello is a word, a goodword, and a realword ii. Hello is a word, a goodword, a realword, and a capword iii. Wont is a word and a capword iv. Art3mis is a word, a goodword, and a capword v. SCUBA is a word, a goodword, a realword, a capword, and an acronym vi. C3PO is a word, a goodword and a capword vii. 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: ! ! 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 -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 "1 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. ! Part 1 (Due Feb 11 @ midnight) (8 points) ! !!! 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 "2 ! Part 2 (Due Feb 18 @ midnight) (16 points) ! All of Part 1 cases plus additional cases.
prog1 -q file file TOO MANY FILES prog1 -q file No output prog1 file Exact copy of file prog1 -s file Exact copy of file prog1 -s file_with_extra_spaces Copy of file, with extra spaces removed prog1 -c file Exact copy of file prog1 -c file_with_many_types Copy of file with only realwords prog1 -s -c file_with_extra_spaces Copy of file with only realwords and with extra spaces removed ! !! Part 3 (Due Feb 25 @ midnight) (24 points) ! All of Part 1 and Part 2 cases plus: prog1 -q -p file Prints statistics only prog1 -q -p -l file Prints statistics and word lengths only prog1 -q < file No output prog1 -q -p -l < file Prints statistics and word lengths only prog1 -s -p file_with_extra_spaces Copy of file, with extra spaces removed, plus statistics prog1 -l -s -p file_with_extra_spaces Copy of file, with extra spaces removed, plus statistics and word lengths prog1 -c -l -s file_with_many_types Copy of file, with extra spaces removed, plus statistics and word lengths prog1 -s -l -c -p < another_file Copy of only goodwords in file, with extra spaces removed, plus statistics and word lengths "3
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