RA 2 Counting Lines & Words (Fall 2023)

pdf

School

New Jersey Institute Of Technology *

*We aren’t endorsed by this school

Course

280

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

3

Uploaded by ColonelElementDeer29

Report
CS 280 Fall 2023 Recitation Assignment 2 Counting Lines and Words September 14, 2023 Due Date: Monday, September 18, 2023, 23:59 Total Points: 7 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 t he 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 textual words to be formatted, 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 s of a command line as a command name. The three commands are recognized by the command words whether they are in lowercase or uppercase. If no word is found, or a word is not recognized as one of the three command words, 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 formatted words, 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, Line number File contents 1 2 3 4 5 6 7 8 9 10 11 12 //regular formatting by default 3456 george 10.25 ##BOLD This text needs to be in bold. ## font 14 ##regular // perform italic only ## italic 67899 smith 9643.45 // return to regular text only ##regular
the generated results are as follows: Notes: 1. The example assumes that the file name is entered from the keyboard. 2. There are 15 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, infile1, that does not exist. 4. There are 6 test cases, case1 through case6. Each test case file includes a file name similar to what you would type from the keyboard. Case1 includes a non-existing file, infile1, while case2-case6 files include infile2 through infile6 for existing files. Expected correct outputs are included in the files case1.correct-case6.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_Fall2023/RA2. You can, for example, look at infile3 13 14 15 End of File marker ## Bold 278 hello - +654 Enter the name of a file to read from: infile6 Error: Unrecognizable command in line 5 Total lines: 15 Commented lines: 3 Number of words in the Text to be formatted: 17 Bold commands: 2 Italic commands: 1 Regular commands: 2 Entered file name Screen pointer
by saying "cat $LIB/public/ RA_ Fall2023/infile3", and you can look at the expected output by saying "cat $LIB/public/ RA_ Fall2023/case3.correct". Submission Guidelines 1. Please name your file as RAx_firstinitial_lastname.cpp ”. Where, “first initial 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 September 20, 2023, 11:59 pm. Grading Table Testing Cases Points Case 1: File cannot be found 1.0 Case 2: Empty File 1.0 Case 3: All whitespace 1.0 Case 4: Commented and command lines only 1.0 Case 5: Textual file only 1.0 Case 6: Textual file with commented & command lines 1.0 Compiles Successfully 1.0 Total 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help