Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that acts like a simple counting tool for collecting information from textual files of documents prepared for a simple scripting language

Write a C++ program that acts like a simple counting tool for collecting information from textual files of documents prepared for a simple scripting language interpreter. An input file for the simple scripting interpreter includes two types of data, commented lines and scripting code lines. A commented line is recognized by either the two characters ## or // at the beginning of the line, which would be skipped by the scripting interpreter. All other non-commented lines are considered as part of the scripting code, including any blank lines with whitespace.

The program for the simple counting tool should read 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.

After reading the contents of the input file, the program should print out the total number of lines, the number of commented lines, the maximum length of commented lines, the maximum length of non-commented lines, the commented line of maximum length delimited by double quotes, and the non-commented line of maximum length delimited by double quotes. An example of an input file and the expected results after processing the file are shown below. Given the following file contents,

Line number File contents

1 run prog1

2 //

3 delete

4 ### execute next command

5 delete myfile

6

7

8 copy file1 file2

9

10 // welcome to cs 280

11 print myfile

12

13 // terminate script

the generated results are as follows:

Notes:

1. The example assumes that the file name is entered from the keyboard.

2. There are 14 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.

Hints:

1. You can use get() or getline() functions for reading from the input file. However, it is recommended that you use getline() to read an entire line into a string.

2. A string can be treated like an array of characters.

3. Download the zipped file for the test cases from Canvas. These are the test cases you will be graded against on your submission to Vocareum. Use the test cases to test your implementation. Note that case 1 is not included in the set. Your program will be checked against a file name, infile0, that does not exist.

4. There are 6 test cases, case0 through case5. Each test case file includes a file name similar to what you would type from the keyboard. Case0 includes a non-existing file, infile0, while case1-case5 files include infile1 through infile5 for existing files. Expected correct outputs are included in the files case0.correct-case5.correct.

Please help in coding this program ASAP. The language to be used in coding is C++ Language.

Thank You!

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

More Books

Students also viewed these Databases questions

Question

Discuss the tools used by public relations professionals.

Answered: 1 week ago