Question: #include #include #include #include using namespace std; bool isType1(string word) { return word[0] == '$' && isalpha(word[1]); } bool isType2(string word) { return word[0] ==

#include #include #include #include

using namespace std;

bool isType1(string word) {

return word[0] == '$' && isalpha(word[1]);

}

bool isType2(string word)

{

return word[0] == '@' && isalpha(word[1]);

}

bool isWord(string word) {

if (word.empty())

return false;

if (isType1(word) || isType2(word))

return true;

for (char c : word)

if (!isalnum(c) && c != '_')

return false;

return true;

}

int wordc(string line)

{

int count = 0;

string word;

stringstream ss(line);

while (ss >> word)

if (isWord(word))

count++;

return count;

}

int Type1(string line) {

int count = 0;

string word;

stringstream ss(line);

while (ss >> word); {

if (isType1(word))

count++; }

return count; }

int Type2(string line) {

int count = 0;

string word;

stringstream ss(line);

while (ss >> word) {

if (Type2(word))

count++; }

return count;

}

int main(int argc, char* argv[])

{

if (argc < 2)

{

cout << "NO SPECIFIED INPUT FILE NAME." << endl;

return 0;

}

ifstream infile(argv[1]);

if (!infile.is_open())

{

cout << "CANNOT OPEN THE FILE " << argv[1] << endl;

return 0;

}

int words = 0, type1 = 0, type2 = 0;

string line;

while (getline(infile, line))

{

words += wordc(line);

type1 += Type1(line);

type2 += Type2(line);

}

if (words == 0)

{

cout << "File is empty." << endl;

return 0;

}

if (argc == 2)

{

cout << "Total number of words: " << words << endl; cout << "Number of Type 1 names: " << type1 << endl; cout << "Number of Type 2 names: " << type2 << endl;

}

else if (string(argv[2]) == "-all") {

cout << "Total number of words: " << words << endl; cout << "Number of Type 1 names: " << type1 << endl; cout << "Number of Type 2 names: " << type2 << endl;

}

else if (string(argv[2]) == "-type1") {

cout << "Number of Type 1 names: " << type1 << endl;

}

else if (string(argv[2]) == "-type2") {

cout << "Number of Type 2 names: " << type2 << endl;

}

return 0; }

I need help adding a statement to print out an UNRECOGNIZED FLAG when the flag isnt -all, -type1 , and -type2 and print out NOFLAG when there is no flag value

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!