Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CS 280 Spring 2022 Recitation Assignment 4 February 10, 2022 Due Date: Monday, February 14, 2022, 23:59 Total Points: 6 Write a C++ program that should read from a file name specified in the command...

1 answer below »

CS 280
Spring 2022
Recitation Assignment 4
Fe
uary 10, 2022
Due Date: Monday, Fe
uary 14, 2022, 23:59
Total Points: 6
Write a C++ program that should read from a file name specified in the command line as an
argument. However, if no file name is provided, the program should print on a new line "No file
is found.", and exit. If the file cannot be opened, print on a new line "File cannot be opened: ",
followed by the file name, and exit. The program should read from the file characters until the end
of file. In this assignment, an empty file is defined as the file that does not include any non-
whitespace characters. In case the file is empty, print out on a new line the message "File is empty."
and then exit. The program should keep a record of the number of occu
ences of each seen
punctuation characters in the input file. The program should create a simple directory using the
map> container that maps a character to an integer for the occu
ences of each punctuation
character. In this assignment, we follow the (ctype.h) C/C++ header file definition for
the function ispunct(c), which checks whether c is a punctuation character. Punctuation characters
are all graphic characters (as in isgraph() function), that are not alphanumeric (as in isalnum()
function), as defined in the original 127-character ASCII set. For example, the subset of characters
{!"#$%&'()*+,-./} and {:;<=>?@} are considered punctuation characters.
For more details, see the (ctype.h) C/C++ header files definition at:
https:
www.cplusplus.com
eference/cctype
After all input has been processed, the program should
• Print out the total non-whitespace characters in the file.
• Print each punctuation character and the number of times it was seen. The punctuation
characters should be printed in order.
• Determine the punctuation character that has been seen the largest number of times in the
file and print it out.
For example, with an input file of the following contents:
End of File
XXXXXXXXXX * 45 = ???
4321 > 125 < !!!
278 ## 1025 @
45 / 100 = 0.45 == 45%
https:
www.cplusplus.com/isgraph
https:
www.cplusplus.com/isalnum
https:
www.cplusplus.com
eference/cctype
Pruthul

The results are as shown below:
Hints:
1. Include the container.
2. Create a directory using to map a character to an integer. See the recitation class
slides for the use of the methods, or refer to the online documentation for
at: www.cplusplus.com
eference/map/map
3. There are 6 test cases. See the descriptions in the Grading Table below. Test cases 1 and 2
are not associated with any input files. While, test cases 3-6 are associated with the input
files infile1 to infile4. The expected co
ect output for the test cases are in the files with
“.co
ect” extension, and these are: {"nofile" "cantopen" "empty" "allnumbers" "text1"
"text2"}. Download the zipped files for the test cases infile1 to infile4 and the files for the
expected co
ect output with “*.co
ect” extension from Canvas. Your implementation will
e graded based on the expected co
ect output for each test case. Use the test cases to test
your implementation.
4. If you want to look at the input for one of the test cases on Vocareum, use the linux "cat"
command. The cases are in the directory $LIB/public/RA_Spring2022/RA4. You can, for
End of File
Number of characters in the file: 59
Punctuation characters in the file and their occu
ences:
!: 3
#: 2
%: 1
*: 1
+: 1
-: 1
.: 1
: 1
: 1
=: 4
: 1
?: 3
@: 1
The punctuation character with maximum occu
ences is "=" found 4 times.
http:
www.cplusplus.com
eference/map/map
Pruthul
example, look at infile3 by saying "cat $LIB/public/ RA_ Spring2022/ infile3 ", and you
can look at the expected output by saying:
"cat $LIB/public/ RA_ Spring2022/case4.co
ect".
Submission Guidelines
1. Please name your file as “RAx_firstinitial_lastname.cpp”. Where, “firstinitial” and “lastname”
efer 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 cu
ent assignment on Vocareum.
2. Submissions after the due date are accepted with a fixed penalty of 25%. No submission
is accepted after Wednesday 11:59 pm, Fe
uary 16, 2022.
Grading Table

Testing Cases Points
Case 1: No file name is found. 0.5
Case 2: Checking status of opening a file. 0.5
Case 3: Empty File (All whitespace) 1.0
Case 4: All Numeric Data File 1.0
Case 5: Textual File I 1.0
Case 6: Textual File II 1.0
Compiles Successfully 1.0
Total 6

Pruthul
Answered 2 days After Feb 08, 2022

Solution

Nidhi answered on Feb 11 2022
111 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here