CS 280 Recitation Assignment 2

$35.00 $29.00

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…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

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
End of File marker

 

 

the generated results are as follows:

 

Entered file name

 

 

 

Screen pointer

Enter the name of a file to read from:

infile2.txt

Total Number of Lines: 13

Number of commented lines: 4

Maximum Length of commented lines: 24

Maximum Length of non-commented lines: 17

Commented line of maximum length: “### execute next command”

Non-commented line of maximum length: “run prog1 ”

 

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.

5. If you want to look at the input for one of the test cases, use the linux “cat” command. The cases are in the directory $LIB/public/RA_Spring2023/RA2. You can, for example, look at infile3 by saying “cat $LIB/public/ RA_ Spring2023/infile3”, and you can look at the expected output by saying “cat $LIB/public/ RA_ Spring2023/case3.correct”.
Submission Guidelines

1. Please name your file as “RAx_firstinitial_lastname.cpp”. Where, “firstinitial” and “lastname” refer to your first name initial letter and last name, respectively, and “x” refers to the recitation assignment number (e.g., 1, 2, etc). Your program Submission is to Vocareum environment. Follow the link of Recitation Assignment 2 on Canvas in the Modules or Assignments pages to connect to the current assignment on Vocareum.

2. Submissions after the due date are accepted with a fixed penalty of 25% from the student’s score. No submission is accepted after Wednesday February 1st, 2023, 11:59 pm.

 

Grading Table

Testing Cases
Points
Case 0: File cannot be found
1.0

Case 1: Empty File
1.0

Case 2: General script file 1
1.0

Case 3: All whitespace
1.0

Case 4: Non-commented lines only
1.0

Case 5: General script file 2
1.0

Compiles Successfully
1.0

Total
7

CS 280 Recitation Assignment 2
$35.00 $29.00