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