Question: /* * Match: find word matches #include #include #include #include using namespace std; int main(int argc, char* argv[]) { enum MODE { WHOLE, PREFIX, SUFFIX,

![namespace std; int main(int argc, char* argv[]) { enum MODE { WHOLE,](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f533580b326_49566f533577762f.jpg)


/* * Match: find word matches
#include
using namespace std;
int main(int argc, char* argv[]) {
enum MODE { WHOLE, PREFIX, SUFFIX, ANYWHERE, EMBEDDED } mode = WHOLE; bool reverse_match = false;
int c; while ((c = getopt(argc, argv, ":wpsaev")) != -1) { switch (c) { case 'w': // pattern matches whole word mode = WHOLE; break; case 'p': // pattern matches prefix mode = PREFIX; break; case 'a': // pattern matches anywhere mode = ANYWHERE; break; case 's': // pattern matches suffix mode = SUFFIX; break; case 'e': // pattern matches anywhere mode = EMBEDDED; break; case 'v': // reverse sense of match reverse_match = true; break; } } argc -= optind; argv += optind;
string pattern = argv[0];
string word; int matches = 0; while (cin >> word) { if (pattern == word) { matches += 1; cout
the language is C++
What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of cou)? And what was the name of the place where the dinosaur killing asteroid is thought to have landed 65 million years ago? I think it was "cat something" or at least it had "cat" in it One way to find answers to problems such as these is to search a list of words (such as the one available on most Unix systems in the file /usr/dict/words or /usr/share/dict/words) for words matching a given pattern. Then you can easily find answers like as eleven, eyelet, grapevine, antiperspirant and Yucatan. Your task is to write a program, named match, that can find such matches. The program is run from the command line, using this syntax: match [-OPTION].. . PATTERN [FILENAME] The program reads words from standard input (or from each of the named files in turn) and compares them with the pattern specified on the command line. A pattern is composed of letters and underscores (_'). A letter matches itself, an underscore matches any character. The input consists of words separated by whitespace. If an input word matches the specified pattern, the word is written to standard output; otherwise, nothing is written for that word. The program stops when all of the input words have been read and processed. The process of matching is controlled by command-line options: With no options (or with the option -w), a word is matched if it matches the pattern in its entirety. Thus match c t (or match -wc t) would match cat or cut but not cater or scotch. The options -p and -s specify that a word is matched if the pattern occurs as either a prefix (at the beginning) or a suffix (at the end). Thus match -p cat would match catfish or cataclysmic, and match -s cat would match scat or bobcat The option -a allows the match to occur anywhere within a word. Thus match -a cat would match vacate and amplification. The option -e specifies that a word is matched if it is embedded within the pattern. Thus match -e vacate would match cat and ate Normally the letters in a word match only if they agree in case with the patterm. The option -i makes the match ignore the case of the word. Thus match Cat would not match cat, whereas match-1 Cat or match-1 CAT would match cat or CAT or even cAt. What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of cou)? And what was the name of the place where the dinosaur killing asteroid is thought to have landed 65 million years ago? I think it was "cat something" or at least it had "cat" in it One way to find answers to problems such as these is to search a list of words (such as the one available on most Unix systems in the file /usr/dict/words or /usr/share/dict/words) for words matching a given pattern. Then you can easily find answers like as eleven, eyelet, grapevine, antiperspirant and Yucatan. Your task is to write a program, named match, that can find such matches. The program is run from the command line, using this syntax: match [-OPTION].. . PATTERN [FILENAME] The program reads words from standard input (or from each of the named files in turn) and compares them with the pattern specified on the command line. A pattern is composed of letters and underscores (_'). A letter matches itself, an underscore matches any character. The input consists of words separated by whitespace. If an input word matches the specified pattern, the word is written to standard output; otherwise, nothing is written for that word. The program stops when all of the input words have been read and processed. The process of matching is controlled by command-line options: With no options (or with the option -w), a word is matched if it matches the pattern in its entirety. Thus match c t (or match -wc t) would match cat or cut but not cater or scotch. The options -p and -s specify that a word is matched if the pattern occurs as either a prefix (at the beginning) or a suffix (at the end). Thus match -p cat would match catfish or cataclysmic, and match -s cat would match scat or bobcat The option -a allows the match to occur anywhere within a word. Thus match -a cat would match vacate and amplification. The option -e specifies that a word is matched if it is embedded within the pattern. Thus match -e vacate would match cat and ate Normally the letters in a word match only if they agree in case with the patterm. The option -i makes the match ignore the case of the word. Thus match Cat would not match cat, whereas match-1 Cat or match-1 CAT would match cat or CAT or even cAt
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
