Question: I ' m having issues with this prompt below. I included my code and can only pass 4 / 8 test cases / Fix the

I'm having issues with this prompt below. I included my code and can only pass 4/8 test cases/ Fix the other 4 test cases without failing the first 4 asap. THanks.
Prompt:
Write a C++ program that accepts one command line argument for a file name, and ignores any extra command line arguments that may be provided after the first one. 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.
The program should count the number of lines, the number of non-blank lines, the number of words that contain 5 or less characters, the number of words that contain more than 5 characters, the number of names (special names), and the number of unsigned integers, seen in the file.
A word is defined as a sequence of one or more non-whitespace characters separated by whitespace. A word is defined as a name if it starts by a letter and followed by zero or more letters, digits, underscores _, or @ characters. For example, value, val@l9, num234ten are valid names, but 9val, _num_45 and @num are not. A word is defined as an unsigned integer if it starts by a digit and followed by zero or more digits (ignoring signed integers). For example, 2345 is an unsigned integer word, while 44.75,-345 and 4today45 are not unsigned integers. Note that a line having only whitespace characters is a non-blank line as well.
#include
#include
#include
#include
#include
using namespace std;
bool isName(const string& word){
static const regex nameRegex("^[a-zA-Z][a-zA-Z0-9_@]*$");
return regex_match(word, nameRegex);
}
bool isUnsignedInteger(const string& word){
static const regex unsignedIntegerRegex("^\\d+$");
return regex_match(word, unsignedIntegerRegex);
}
int main(int argc, char* argv[]){
if (argc 2){
cout "NO SPECIFIED INPUT FILE NAME." endl;
return 0;
}
ifstream file(argv[1]);
if (!file){
cout "CANNOT OPEN THE FILE: " argv[1] endl;
return 0;
}
string line;
int totalLines =0, nonBlankLines =0, wordsWithFiveOrLessChars =0, wordsWithMoreThanFiveChars =0;
int namesCount =0, unsignedIntegersCount =0;
while (getline(file, line)){
bool hasNonWhitespace = regex_search(line, regex("\\S"));
if (hasNonWhitespace) nonBlankLines++;
totalLines++;
stringstream ss(line);
string word;
while (ss >> word){
if (word.length()=5) wordsWithFiveOrLessChars++;
else wordsWithMoreThanFiveChars++;
if (isName(word)) namesCount++;
else if (isUnsignedInteger(word)) unsignedIntegersCount++;
}
}
if (totalLines ==0){
cout "File is empty." endl;
} else {
cout "Total Number of Lines: " totalLines endl;
cout "Number of non-blank lines: " nonBlankLines endl;
cout "Number of Words with 5 or Less Characters: " wordsWithFiveOrLessChars endl;
cout "Number of Words with More Than 5 Characters: " wordsWithMoreThanFiveChars endl;
cout "Number of Names: " namesCount endl;
cout "Number ofTotal Number of Lines: 6
Number of non-blank lines: 0
Number of Words with 5 or Less Characters: 0
Number of Words with More Than 5 Characters: 0
Number of Names: 0
Number of Unsigned Integers: 0
2,4c2,4
Number of non-blank lines: 0
Number of Words with 5 or Less Characters: 0
Number of Words with More Than 5 Characters: 0
> Number of non-blank lines: 4
> Number of Words: 0
> Number of Integers: 0
6c6,7
Number of Unsigned Integers: 0Number of Words Greater Than 5 Characters: 0
RESULT: allspaces [01]
RUNNING infile3
Total Number of Lines: 8
Number of non-blank lines: 4
Number of Words with 5 or Less Characters: 5
Number of Words with More Than 5 Characters: 3
Number of Names: 0
Number of Unsigned Integers: 2
2,4c2,4
Number of non-blank lines: 4
Number of Words with 5 or Less Characters: 5
Number of Words with More Than 5 Characters: 3
> Number of non-blank lines: 5
> Number of Words: 8
> Number of Integers: 2
6c6,7
Number of Unsigned Integers: 2Number of Words Greater Than 5 Characters: 3
RESULT: intsonly [0??1
RUNNING infile4
Total Number of Lines: 4
Number of non-blank lines:
 I'm having issues with this prompt below. I included my code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!