CS19 Spring 2017
Assignment 5 (Dining Philosophers)
You are the chief paparazzi at Philosophical Enquirer magazine and are tasked with directing your photographers to catch philosophers. Since all philosphers have to eat, you've decided to stake out local area restaurants. (Technically, LSRs "limited service restaurants".) You will watch every restauraunt, and record data for each philospoher (where they eat) and each restauraunt (who eats there.) This program is an exercise in using inheritance, command line arguments, and STL Maps.
Create a class named Philosopher. This class will have a string name, and a Vector of strings, named dining, containing the names of each place that the philosopher has dined. Duplicates are allowed as the philosopher may have a favorite restauraunt where they dine often. Create a class named FamousPhilosopher that inherits from Philosopher and adds a string quote. Names for philosophers and famous philosophers will always be a single word. Add other members to these classes that you deem necessary.
Create a class named Restaurant. This class will have a string name, and a Vector of strings named patrons, containing the names of each Philosopher that has dined there. Names for Restaurants will always be a single word.
Example Philosophers file
SPIN LOR IK BGB JB THUL StY EPIC
Example FamousPhilosophers file
GL nothing truer than happiness FN great minds are skeptical S there is only one good, knowledge, and one evil, ignorance RD I think therefore I am JSM liberty consists in doing what one desires BR philosophy is what you don't know A happiness is the highest good PROTAG man is the measure of all things
Example Restaurants File
McD BK TB KFC SUB PHUT DUND WEN STAR
Possible Program parameters
-p filename -fp filename -r filename
Program will get input from STDIN. Input will either represent a sighting or a querry. A sighting consists of a restauraunt name followed by a philosopher name. (example "KFC FN") Your program will repond to a sighting by recording the information as described above. (Do nothing in the case of a non-existing philosopher and/or restaurant) A sighting results in no output. A querry consists of a question mark and the name of a philosopher or an exclamation point and the name of a restaurant. The character can come before or after the name, and can be optionally seperated by a space. (examples "EPIC?", "JB ?", "?SPIN", "! BK", "WEN!", "DUND !") Do nothing on a querry of the philosopher or restaurant does not exist. (Not appearing in one aspect doesn't prevent being recorded in another aspect.) Otherwise print the name, followed by a colon, and then a space seperated list of the results. Famous Philosophers will also display their quote in quotes.
Create a "main program" with two STL Maps. One map will be indexed (key'd) with the string name of the philosopher, and the other will be indexed with the name of the restaurant. The main function will hadle the i/o as described above. Main will accept an even number of parameters between zero and six. paramters will be one of "-p", "-fp", or "-r" followed by a filename. Open the listed files and record their information into the appropriate map. Your program only records information for "known" philosophers or restauraunts, so if no paramters are provided, or all of the files are legal but empty, then your program will "discard" all input and have no output as a consequence.
Sample Run using the above exmple files
[steveh@pengo ~]$ ./p5 -p philos -fp philos-a -r lsrlist BK N KFC SPIN KFC S WEN JSM WEN IK SUB A McD S S? S "there is only one good, knowledge, and one evil, ignorance": McD SUB WEN! WEN: IK JSM LOR ? LOR: ?IK IK: WEN SH? [steveh@pengo ~]$
Add an optional "-x" command line parameter that can appear in any order (but not between a filename switch and a filename.) This puts your program into eXclusive mode, where you only record a philosophers visit to a restauraunt if that philosopher appears in the philosopher map, and only updates the list of restaurants that a philosopher has been to if that restaurant appears in the restaurant map. As with all program project extra credit, only attempt this step after the rest of the program is complete and fully tested.