Question
Write a C++ program that identifies and counts words and special names in a textual file. There are two kinds of special names considered, called
Write a C++ program that identifies and counts words and special names in a textual file. There are two kinds of special names considered, called Type 1 and Type 2 names. Counting is applied on all occurrences of words and specialized names.
A word is defined as a sequence of one or more non-whitespace characters separated by whitespace. The special names of Type 1 and Type 2 are identified by a special character at the beginning of the name. Type 1 names must start by a $ character, while Type 2 names must start by @ character. All Type 1 and Type 2 names should consist of a letter following the special start character, followed by zero or more letters, digits or underscores. For example, $value, @val9, $num_234_ten, and @num_45 are valid Type 1 and Type 2 names, but $9val, and @_num, $num$ are not.
The program may accept one or two command line arguments. The format of the command line arguments is specified as follows:
The first argument must be a file name.
The second optional argument is for one of the following flags:
-all: the program displays the total number of words, the number of Type 1 names, and the number of Type 2 names.
-type1: the program displays the number of Type 1 names only.
-type2: the program displays the number of Type 2 names only. If no file name is provided, the program should print on a new line " NO SPECIFIED INPUT FILE NAME.", and exit. If the file cannot be opened, print on a new line " CANNOT OPEN THE FILE", followed by the file name, and exit. The program should read from the file lines until the end of file is found. If the input file is empty, it prints out the message "File is empty." on a new line and then exits. In case the command line does not include any of the optional flags, the program should display the total number of words, and the total of Type 1 and Type 2 names. If an optional flag argument is not recognized, the program should print out the message UNRECOGNIZED FLAG.
Hints:
1. Use functions such as: isdigit(), isalpha(),isalnum() to check for digit characters, alphabetic characters, or alphanumeric characters, respectively.
2. You can use getline() method for reading from the input file.
3. Convert the read line from the file into an input string stream, then read words from the input string stream. See the slides for details.
4. 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. There are 3 input files: infile1, infile2, and infile3. There are 8 test cases, see the designation of each case in the grading table below.
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/RA3. For example, case 6 file is all.correct. You can look at all.correct file by using the command "cat $LIB/public/ RA_Spring2023/ all.correct ".
Please help solve for nine test cases using C++ coding language.
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started