COP 3503 Project 2– Multi-Set Operations Using Classes
6/8/14

DUE: Tuesday 6/17/14

Description
You will modify your design for basic set operations to handle multisets, then document, implement, and test it. The program will maintain a current multiset and a current verbose state. This time, you are required to implement the multiset and its operations using classes. 

User Input
The user input is the same as for Project 1, but there are some differences regarding the meanings of the commands. 
The numbered commands are as follows:
 0.	exit
 1.	input file <filename>: open and read a list from a file to the current multiset
 2.	union file <filename>: open and union a multiset from a file with the current multiset
 3.	subtract file <filename>: open and subtract multiset from a file from the current multiset
 4.	difference file <filename>: open and find the difference between a multiset from a file and the current multiset
 5.	intersect file <filename>: open and find the intersection between a multiset from a file and the current multiset
 6.	reset current multiset to the empty multiset
 7.	output file <filename>: open and write the current multiset to a file 
 8.	print current multiset to the console
 9.	find <item name>: test if <item name> is in the current multiset
 10.	insert <item name> <count>: add <item name> to the current multiset with number <count> if <item name> is not in the current multiset, or increase <item name>'s number by <count> if it is
 11.	delete <item name>: remove <item name> from the current multiset if it is in it
 12.	reduce <item name> <count>: reduce the number of <item name> by <count>
 13.	verbose output
 14.	normal output
 15.	silent output
 16.	help

File input and output format
Files and output to the console of a list will be in the form of one text string “item” followed by one integer number per line. The string may not have spaces or other white space in it. The number indicates how many of that named item there are in the multiset. It is legal for the same name to appear twice or more in an input file. If this occurs, then the number appearing for the new entry is simply added to the number for the existing entry in the multiset.  

Functionality
The process will maintain a current multiset, and another multiset that is being read from a file as needed. Each multiset may be of any size. You may use vectors to implement multisets. 
Writes to the console prompting for command; item and number; file; or writes indicating command completion are specified for normal mode. In silent mode, none of these are issued. In verbose mode, you may add extra information, such as the number of items in the new current set, the number of items added and/or removed, etc. 
Writes indicating errors (e.g., failure to open a file), will be written to standard error (cerr stream). 

Program Command Line Arguments
The program will read in optional command line parameters for verbosity state (default is normal, -v indicates verbose, and -s indicates silent mode) as well as file input for the initial multiset (using -f <file_name> to indicate the file to read in).
 
User Interface Commands 
The input operation will empty the current multiset and fill it with the multiset read from the specified file, and write “New multiset loaded” to the console. 
Union will read in the multiset from the file; if item “X” with number n is read from the file, and item “X” is not in the current multiset, then “X” will be added to the current multiset with the count n; otherwise if item “X” has current count m, its count is updated to m+n. When the union operation is done, the system will print “<file> union completed” to the console. 
Subtract will read in the multiset from the file; if item “X”  with number n is read from the file, and item “X” with count m > n is in the current multiset, then “X” will be remain with count m-n; if n >= m, then “X” is removed from the current multiset; otherwise nothing happens. When the subtract operation is done, the program will print “<file> subtraction completed” to the console. 
Difference will read in the multiset from the file (note that multiple appearances of the same item must be handled upon reading the file in). If item “X” with number n is read from the file, and item “X” is not in the current multiset, then “X” will be added to the new current multiset with number n; likewise, if “Y” is in the current multiset with number m and “Y” is not in the multiset read from the file, then “Y” with number m will be added to the new current multiset. If “X” with number n is read in, and “X” with number m is in the current multiset, then the new current multiset will have “X” with the number |m – n| unless m = n, in which case “X” is not in the new current multiset. When it is done, the program will print “<file> difference completed” to the console. 
Intersect will read in the multiset from the file; if item “X” with number n is read from the file, and item “X” with number m is  in the current multiset, then “X” with the number min(m, n) will be added to the current multiset, otherwise “X” is not in the new current multiset. When it is done, the program will print “<file> intersection completed” to the console. 
Reset will remove all items from the current multiset and will print “Reset completed” to the console. 
Output will save the current multiset into a file in the same format as a multiset read from a file. When it is done, it will print “Save to <file> completed” to the console. 
Print will perform this operation to the console, but will print “Current multiset:” followed by a newline, then the items, rather than the completion statement. 
Find <item> will search the current multiset and print “Item <item> found with count <count>” if <item> is in the current multiset with number <count>; otherwise it will print “Item <item> not found”. 
Insert <item> <count> will add <item> to the current multiset with number <count> if it is not already in the current multiset, and will change the number to m + <count> if <item> is already in the multiset with number m. The program will print “Item <item> inserted with count <m'>” where m' is the final value of the number. 
Delete <item>  will remove <item> from the current multiset if it is present, and will print “Item <item> deleted”, or will print “Item <item> not in multiset” otherwise. 
Reduce <item> <count> will reduce the number m associated with <item> by <count>, or will remove <item> if the resulting number m - <count> is less than or equal to zero. The program will print “Item <item> count reduced to <m – count>” if the new number is greater than zero, or will print “Item <item> removed” if the new number is less than or equal to zero, or will print “Item <item> not in multiset” otherwise. 
In all cases, the output line will be followed by a newline. 
Verbose will cause the current state of output prompt to remain verbose until changed. The default state is normal. In verbose state, the user prompt shall include a short list of all commands (i.e., the numbers and a one-word description along with parameter if any). In verbose state, additional information as you see appropriate (and at least some additional information for each of the commands that change the state of the current multiset) shall be printed to the console. 
Normal will cause the current verbosity state to remain normal until changed. In normal state, the user prompt shall be “> “ on a new line without a newline at the end. This prompt will also be printed in verbose state. In both cases, the feedback indicated for each command above will be printed to the console. 
Silent will cause the current verbosity state to remain in silent mode until changed. In silent mode, there is no prompt and there is no output to the console. Remember that error messages are printed to standard error.
Help prints a more complete description of the commands and their meanings, followed by the regular “> “ prompt (once), regardless of the current verbosity mode. 
 
Errors
Your program must detect and handle in a reasonable way typical errors. All warnings are printed to standard error (cerr). These include but are not limited to:
 1.	File <filename> does not exist – print warning 
 2.	File <filename> exists but cannot be opened in the desired mode – print warning
 3.	File is not in correct format – print warning. Items that are not in correct format must be discarded, with additional warning to the console in verbose mode
 4.	Item <item name> <count> is not in correct format on user input line – issue warning to standard error and print help on correct format to the console
 5.	Command is invalid – issue warning to standard error and print verbose prompt to console

Examples
In the following, three files are mentioned. They are 
A.txt:
fish 7
mother 1
bicycle 2

B.txt:
dog 1
cat 2
fish 3
snake 1

C.txt:
bicycle 
car truck 5

The README.txt says to compile using g++ and run using ./a.out.
The system prompt is $.
$ ./a.out 
> 16
Commands: 0=exit, 1=input file, 2=union file, 3=subtract file, 4=difference file, 5=intersect file, 
                     6=reset, 7=save, 8=print, 9=find item, 10=insert item count, 11=delete item, 
                     12=reduce item count, 13=verbose, 14=normal, 15=silent, 16=help
> 8
Current multiset:
> 10 bird 4
Item bird with count 4 inserted
> 8
Current multiset:
bird 4
> 2 A.txt
A.txt union completed
> 8
Current multiset:
bird 4
fish 7
mother 1
bicycle 2
> 9 mother
Item mother found with count 1
> 9 father
Item father not found
> 3
B.txt
B.txt subtraction completed
> 8
bird 4
fish 4
mother 1
bicycle 2
> 12 bird 3
Item bird reduced by 3
> 11 father
Item father not found
> 11 fish
Item fish deleted
> 8
bird 1
mother 1
bicycle 2
> 1 C.txt
Error: Item bicycle has no count
Error: Item car has no count
> 8
bird 1
mother 1
bicycle 2