Question: Write a C++ program that acts like a simple counting tool for collecting information from textual files of documents prepared for a simple word processing

 Write a C++ program that acts like a simple counting tool

for collecting information from textual files of documents prepared for a simple

word processing software. An input file for the simple word processor includes

three types of data, commented lines, command lines and general text of

Write a C++ program that acts like a simple counting tool for collecting information from textual files of documents prepared for a simple word processing software. An input file for the simple word processor includes three types of data, commented lines, command lines and general text of the document to be formatted. A command line is recognized by the '%' at the beginning of the line and followed by a formatting command. The simple word processor software includes three commands only for formatting textual documents. These are "bold, italic, and regular, which would affect formatting the following text of the document. A commented line is recognized by # at the beginning of the line, and would be skipped by the word processor. The simple counting tool should collect data about the total number of lines read from the file, the number of commented lines, the number of command lines, and the number of bold, italic, and regular commands. Write a C# program for the simple counting tool that reads lines from a file until the end of file. The program should prompt the user for the file name to read from. The program should open the file for reading, and if the file cannot be opened, it should print the message "File cannot be opened ", followed by the filename, and exit. The program should consider the first word following the % character of a command line as a command name. If no word is found, or a word is not recognized as one of the three commands, an error message should be printed out followed by the line number. See the example below for the format of the error message. After reading the contents of the input file, the program should print out the total number of lines, the number of commented lines, the number of command lines, and the number of bold, italic, and regular commands in the file. An example of an input file and the expected results after processing the file are shown below. Given the following file contents, WII DUIDW. Given the following file contents, Line number File contents 3456 george Xbold 10.25 UWN 1 2 3 4 5 6 7. 8 9 10 11 12 End of File marker regular # 4321 staci 12.7 8 italic 67 899 smith 9643.45 00 072 NHO fregular 278 hello +654 the generated results are as follows: Entered file name Enter the name of a file to read from: infile6 Error: Unrecognizable command in line 4 Total lines: 12 Commented lines: 1 Command lines: 5 Bold commands: 1 Italic commands: 1 Regular commands: 2 Screen pointer Notes: 1. The example assumes that the file name is entered from the keyboard. 2. There are 12 lines in this input file. 3. The screen pointer is at a new line after displaying the results. 4. You have to apply the same format in order to have exact match. Points 1.0 1.0 Testing Cases Case 1: File cannot be found Case 2: Empty File W Case 3: All whitespace Case 4: Commented and command lines only Case 5: Textual file Case 6: Textual file with commented & command lines 1.0 1.0 1.0 1.0 Compiles Successfully 1.0 Total 7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!