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

{

cout

return 0;

}

ifstream infile(argv[1]);

if (!infile.is_open())

{

cout

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

return 0;

}

if (argc == 2)

{

cout

}

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

cout

}

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

cout

}

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

cout

}

return 0; }

Checked for test cases for Infile3(img below) and it does not open properly#include #include #include #include using namespace std; bool isType1(string word) { return

word[0] == '$' && isalpha(word[1]); } bool isType2(string word) { return word[0]

\begin{tabular}{l|l} Line number & File contents \\ \hline 1 & # Various operations on scalar (string) variables. \\ 2 & \$fred = "Fred here"; \\ 3 & \$barney = 56; \\ 4 & \$sum = 10+ \$barney; \\ 5 & print 'The variable \$fred' ." contains \$fred. "; \\ 6 & print "Sum is \$sum. ; \end{tabular} The displayed output for executing the program with the "-all" flag would be as shown below

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!