Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment we will write a C++ program that serves as a very rudimentary word processor. Our program will read input and perform some
For this assignment we will write a C++ program that serves as a very rudimentary word processor. Our program will read input and perform some transformations, and generate output. For this assignment, we use the following definitions: A "word" is a sequence of non-whitespace characters. An "empty line" is a line with no characters in it at all. A "blank line" is a line containing only one or more whitespace characters. The "line length" is the number of characters in each line that was output. A "paragraph" is a collection of lines. There are no blank lines or empty lines in a paragraph. An "indent" is spaces at the very beginning of the first line of a paragraph The program reads lines of input and prints out paragraphs. The line length for each output line may be specified as a command line argument. If no command line argument for the line length is specified, the program should use a line length of 40 The number of spaces to indent each paragraph may be specified as a command line argument. If no command line argument for indent is specified, the program should use an indent of 8. Words in the output are separated by a single whitespace character. So, for example, the input "Hello world" should appear as "Hello world in the output. One or more consecutive empty or blank lines, or the end of file, should be interpreted as the end of a paragraph. Several consecutive empty or blank lines should cause a single empty line to be generated on output. The output must be filled out to a length less than or equal to the line length. This may involve combining several lines of input into a single line of output. For example, assume we have an input file like so This is my favorite class. Of all time!! Really, I swear! If the indent is 5, and the line length is 80, then the output will be: This is my favorite class. Of all time! Really, I swear. Notice that we combined the first two lines of input into a single line of output, we deleted the multiple spaces between This and is, we indented 5 spaces, and we combined multiple blank lines into a single line between paragraphs. Whitespace at the beginning and end of a line of input should be ignored. Note that the length of the output line should not exceed the line length. The only exception to this rule is if there is only a single word on the output line. For example, suppose we have an indent value of 10, a line length of 15, and input as follows: Several of us just loooo00000000000ooove C++! The output would be: Several of us just loooooooooooooooooove C++! Observe that we ignored the leading spaces in the first line of input. Note also that the first and third lines of output exceed the line length of 15; because there is only one word in the output line, this is acceptable. The second line of output does not have "loooo00000000000ooove" on the line because adding it would cause the output line to exceed the line length. The program is instructed as to which options it should use by way of command line arguments. Command line argument Meaning -LL=n The output line length should be set to n. The value of n must be a positive integer greater than 0 -IN=n The indentation should be set to n. The value of n must be a positive integer greater than 0 filename Name of the file to be opened and read for input. A filename cannot begin with a dash. If no filename is provided, the program should read from the standard input. You are allowed to have multiple-LL and PIN flag arguments. If you do, the last one specified is used. So, for example, providing the command line arguments "-LL=5-LL=20-LL=100 results in a line length of 100. The following error cases must be checked and handled: Error case How it is handled More than one filename provided Print TOO MANY FILENAMES" and stop Unable to open file Print "UNABLE TO OPEN FILE filename" and stop Unrecognized flag argument (a flag argument Print "UNRECOGNIZED FLAG flag", and stop is an argument that begins with a dash) -LL or -IN flag does not have = after LL or IN Print MISSING = SIGN flag" and stop -LL=n or -IN=n and n is not a positive integer greater than 0 Print "VALUE NOT INTEGER > O flag" and stop For this assignment we will write a C++ program that serves as a very rudimentary word processor. Our program will read input and perform some transformations, and generate output. For this assignment, we use the following definitions: A "word" is a sequence of non-whitespace characters. An "empty line" is a line with no characters in it at all. A "blank line" is a line containing only one or more whitespace characters. The "line length" is the number of characters in each line that was output. A "paragraph" is a collection of lines. There are no blank lines or empty lines in a paragraph. An "indent" is spaces at the very beginning of the first line of a paragraph The program reads lines of input and prints out paragraphs. The line length for each output line may be specified as a command line argument. If no command line argument for the line length is specified, the program should use a line length of 40 The number of spaces to indent each paragraph may be specified as a command line argument. If no command line argument for indent is specified, the program should use an indent of 8. Words in the output are separated by a single whitespace character. So, for example, the input "Hello world" should appear as "Hello world in the output. One or more consecutive empty or blank lines, or the end of file, should be interpreted as the end of a paragraph. Several consecutive empty or blank lines should cause a single empty line to be generated on output. The output must be filled out to a length less than or equal to the line length. This may involve combining several lines of input into a single line of output. For example, assume we have an input file like so This is my favorite class. Of all time!! Really, I swear! If the indent is 5, and the line length is 80, then the output will be: This is my favorite class. Of all time! Really, I swear. Notice that we combined the first two lines of input into a single line of output, we deleted the multiple spaces between This and is, we indented 5 spaces, and we combined multiple blank lines into a single line between paragraphs. Whitespace at the beginning and end of a line of input should be ignored. Note that the length of the output line should not exceed the line length. The only exception to this rule is if there is only a single word on the output line. For example, suppose we have an indent value of 10, a line length of 15, and input as follows: Several of us just loooo00000000000ooove C++! The output would be: Several of us just loooooooooooooooooove C++! Observe that we ignored the leading spaces in the first line of input. Note also that the first and third lines of output exceed the line length of 15; because there is only one word in the output line, this is acceptable. The second line of output does not have "loooo00000000000ooove" on the line because adding it would cause the output line to exceed the line length. The program is instructed as to which options it should use by way of command line arguments. Command line argument Meaning -LL=n The output line length should be set to n. The value of n must be a positive integer greater than 0 -IN=n The indentation should be set to n. The value of n must be a positive integer greater than 0 filename Name of the file to be opened and read for input. A filename cannot begin with a dash. If no filename is provided, the program should read from the standard input. You are allowed to have multiple-LL and PIN flag arguments. If you do, the last one specified is used. So, for example, providing the command line arguments "-LL=5-LL=20-LL=100 results in a line length of 100. The following error cases must be checked and handled: Error case How it is handled More than one filename provided Print TOO MANY FILENAMES" and stop Unable to open file Print "UNABLE TO OPEN FILE filename" and stop Unrecognized flag argument (a flag argument Print "UNRECOGNIZED FLAG flag", and stop is an argument that begins with a dash) -LL or -IN flag does not have = after LL or IN Print MISSING = SIGN flag" and stop -LL=n or -IN=n and n is not a positive integer greater than 0 Print "VALUE NOT INTEGER > O flag" and stop
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