Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this programming assignment, you need to write C++ program that serves as a very basic word processor. The program should read lines from a

In this programming assignment, you need to write C++ program that serves as a very basic word processor. The program should read lines from a file, perform some transformations, and generate formatted output on the screen.

For this assignment, 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 to be displayed in the output. The line length for each output line may be specified as a command line argument.

?A "paragraph" is a collection of lines. There are no blank lines or empty lines in a paragraph.

?An "indent" includes spaces at the very beginning of the first line of a paragraph. The number of spaces to indent each paragraph may be specified as a command line argument.

?"Line spacing" is the space between each line in a paragraph (e.g., single spaced)

?"Paragraph spacing" determines the amount of space above or below a paragraph. Assume the paragraph space is equal to the line spacing

plus one.

?"Word count" is the number of words allowed in a document.

?"End of a paragraph" is defined as one or more consecutive empty or blank lines, or the end of file. The program performs the following transformations:

1.The program writes words in the output separated by a single whitespace character. So, for example, the input "Hello world" should appear as "Hello world" in the output.

2.The output lines must be filled out to a length less than or equal to the specified line length. This may involve combining several lines of input into a single line of output. 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 to be displayed on the outputline.

3.Whitespace at the beginning and end of a line of input should be ignored.

4.The first line of each paragraph is indented the number of spaces specified.

5.Paragraph lines are written in the output separated by the specified line spacing.

6.Paragraphs are written in the output separated by the specified line spacing plus one. Several consecutive empty or blank lines in the input file should cause a single empty line to be generated on output by default (i.e. single spaced).

7.The program will limit the number of words read from the input file to the specified maximum number of words.

8.The program at the end prints the maximum allowed number of words and the word count:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
maximum number of words. 8. The program at the end prints the maximum allowed number of words and the word count. The program is instructed to accept arguments from the command line. These arguments are: Command line argument Description filename Name of the file to be opened and read for input. A filename cannot begin with a dash. -LL=t The line length should be set to t. The value of t must be a positive integer greater than 0. Default value oft = 20. -IN=n The indentation should be set to n. The value of n must be a positive integer greater than 0. Default value of n =5. -WC=m The maximum number of words, m, from the input file that are accepted for processing and display on the output. The value of m must be a positive integer greater than 0. Default value of m = 50 -SP=S The line spacing should be set to s. The value of s must be a positive integer greater than 0. Default value of s = 1 The following error cases must be checked and handled as follows: Error case How it is handled Unable to open a file Print "UNABLE TO OPEN FILE" and exit. Tamanaanimad flan nerment fa flon semimentning Assignment 1 Basic Word Processor (Updated Oct. 1st, 2020) (116 KB) The following error cases must be checked and handled as follows: Error case How it is handled Unable to open a file Print "UNABLE TO OPEN FILE" and exit. Unrecognized flag argument (a flag argument Print "UNRECOGNIZED FLAG flag", and exit. is an argument that begins with a dash) -IN, -WC, or -SP flag does not have = after Print "MISSING = SIGN flag" and exit. IN, WC or IN -IN=n, -WC-n or -SP=n and n is not a Print "VALUE NOT INTEGER greater than 0 flag" and positive integer greater than 0. exit. Number of words exceeds the maximum Print "The read file contains number of words exceeding allowed. the allowed maximum." "It has been truncated accordingly." Example 1: Assume the following file contents for cases 1 and 2 shown below. File 1: "myfile1.txt" contents 3456 george 10. 25 1234 smith 4.5 4321 staci 10.25 278 staci 10.253456 george 10. 25 1234 smith 4.5 4321 staci 10.25 278 staci 10.25 The maximum allowed number of words is 50. The read file contains 12 words. Case 2: Output of "myfile 1.txt" with arguments: -LL=10 -IN-8 -WC=10-SP=3 3456 george 10. 25 1234 smith 4.54321 staci 10. 25 278 The maximum allowed number of words is 10 The read file contains number of words exceeding the allowed maximum. It has been truncated accordingly. Example 2: Assume the following file contents for case 3 shown below. File 2: "myfile2.txt" contents\fsmith 4.5 4321 staci 10. 252222222222222222222222222222222222 278888888888888888888868888888888888888888888888 The maximum allowed number of words is 10. The read file contains number of words exceeding the allowed maximum. It has been truncated accordingly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions