Matches Programming Assignment Help

Assignment 2: Word Matching

What’s a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of a pine grave? Or how about a word that starts and ends with an ant (other than the ant itself, of course)? 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/user/dict/words or user/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 us run from the command line, using this syntax:


The program reads words from standard input (or from each of the named files in turn) and compares them 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 input words match 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 w c_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 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.
  • The option e specifies that a word is matched if it is embedded within a pattern. Thus match e vacate would cat and ate.
  • Normally the letters in a word match only if they agree in case with a pattern. The option I make the match ignore the case of the word. Thus match cat would not match cat, whereas match I Cat or match i CAT would match cat or CAT or even cAt.
  • Normally the pattern is matched exactly. However, if option j (for jumble) is specified, the pattern is considered matched if any rearrangement of the pattern is matched. Thus match j cat would also match act.
  • The option v reverses the sense of the match. The output will therefore consist of all of the words that do not match the pattern.
  • The option n takes an argument that specifies constraints on the length of the matching words. By default, any length word is permitted. However match n3, 8-p cat would match words that begin with cat and that contain between 3 and 8 letters. As a special case, a minimum or maximum length of 0 (or an omitted length) indicates no restriction.

All options come before any other arguments, but more than one option can be specified. The w,p,s,a, and e options are mutually exclusive, if more than one is specified, the last-specified option takes precedence. Thus match p a cat is equivalent to match a cat. The other options are independent and can be specified in any order and any combination.

Hire Assignment Writers

Function point:-

1 Extend the program so that it correctly handles the w,-p, and a options

2 Extend the program so that it correctly handles the s and e option

3 Extend the program so that it correctly handles the v options

4 Extend the program so that it correctly handles the I option

5 Extend the program so that it correctly interprets patterns that contain underscores.

using namespace std;

int main(int args, char* argv[]) {

enum MODE {


} 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;


case 'p': // pattern matches prefix

mode = PREFIX;


case 'a': // pattern matches anywhere

mode = ANYWHERE;


case 's': // pattern matches suffix

mode = SUFFIX;


case 'e': // pattern matches anywhere

mode = EMBEDDED;


case 'v': // reverse sense of match

reverse_match = true;




argc -= optind;

argv += optind;

string pattern = argv[0];

string word;

int matches = 0;

while (cin >> word) {

if (pattern == word) {

matches += 1;

cout << word << endl;



return (matches == 0) ? 1 : 0;


6 extend the program so that it correctly handles the -n option. For this level, you can assume that the option argument will not omit length values. That is, you can assume that it will explicitly specify the minimum and maximum length (either of which might be 0).

7 extend the program so that it handles missing or incomplete arguments.

8 extend the program so that if one or more filenames is specified on the command line, input is taken from each file in turn rather from standard input. If a file cannot be open, the program should display the following error message on cerr and exit with status 2.

Can’t open file <<name of the file>>

9 extend the program so that it correctly interprets the j option when the pattern does not contain underscores.

10 extend the program so that it correct interprets the -j option for all patterns.



You are encouraged to work on these assignments in pairs. If you work as a pair, you must both hand in a solution, which should be identical. All work handed in will be checked using a similarity checker; if more than 2 solutions appear similar,marks will be withheld pending investigation

Automatic Assessment

The function points for this task will be assessed automatically using the demo and try programs under the task name match.


Because the program makes extensive use of command-line arguments, you will probably find it easiest to test at the command line (It’s possible to run programs with command-line arguments in NetBeans, but it’s not convent.)

As the program takes its input from the standard input stream, you can test it by typing words on the keyboard. However, you might find it more convenient to redirect standard input to come from a file containing test data;

$>match s cat < test.txt

And because the program acts as a filter, you can pipe it a dictionary file of words to find the answers to those questions at the start. Or even solve today’s 9 letters word search:

$>cat words.txt | match e_e_e_



$>cat words.txt | match j Pinegrove


$>cat words.txt | match n4 p ant | match s ant


$>cat words.txt | match n3 e j Pinegrove | match a i











Need any programming Assignment Help or the above one? Contact us right now.