Assignment 09

Due: Monday, April 20, 2015 at noon, 100 pts

For this assignment you will submit multiple files in the usual way. These files will contain a C++ program that you have named appropriately, each file with an appropriate name and appropriate extension. Be sure that your program compiles using the g++ compiler before you submit it. To compile a program with multiple files, use the usual fg++ command but instead of the single file you compiled before, compile *.cpp and the compiler will "grab" all the cpp files in that directory. Use cssubmit in the usual way.

Background: These next two (last two for this semester) assignments will work together; hw 10 builds upon the foundation of hw 9. In hw 9, you are going to create your first classes that will become a part of hw 10. In hw 10, you will add classes and structure to produce a simulation of a forensic investigation. We trust it will be a great learning experience and fun too.

Resource: You might want to read this: http://www.cplusplus.com/doc/tutorial/arrays/ . Be sure to read about multidimensional arrays, especially how to pass them to functions.

Specifications: You are going to write the definitions of two classes (and their member functions, of course) and a main function to test them. As you have learned in class, you will have a pair of files (a header and an accompanying implementation file) for each class. Your main we will refer to as the "driver". We call it this because its sole purpose at this time is to test the classes you've created. That means, in the driver (main) you will declare objects of your new types (classes) and demonstrate that they "work" and are what you think they are. Thus, you would declare an object and then output it to the screen to see that indeed it has the attributes you built into its constructor. Then use the member functions and output again to see that something has indeed changed. Test all functions (including constructors).

The classes to create for now are the following:

The resident class has the following:

  • Member variables:

      • a variable for the resident's name.

      • a bool is_alive to signify whether or not this person is alive.

      • a bool is_murderer.

    • an int to represent the person's hair color - values range from 1 -> 10

  • Member functions:

      • a default constructor that will make the person alive and not a murderer, picks their name sequentially (first person created gets the first name, second created gets the second name, etc) from a file of names (see list below), and randomly assigns their hair value.

      • a hair_color_change()function that returns nothing and is passed an integer between and including 1 and 10 that is to be the person's new hair color.

      • a kill_me() function, which will update the is_alive member (that is, updates their aliveness to reflect the fact that they are no longer so). I hope this makes sense. If not, make an appointment with your doctor or clergyman for a consultation on "the human condition".

      • any necessary (and NOT unnecessary) mutator/accessor functions.

      • a overloaded insertion ( << ) operator so that you can easily output the person. e.g. Frank Smith is alive, is not a murderer, has hair color 6

Your crime_room class is to contain the following:

  • Member variables:

      • a bool murder_committed that will indicate as the name implies.

      • an int hair that takes on values of persons' hair colors (1 -> 10). This is to represent the color of the hair of a murderer, but only if murder_committed is true.

      • a string dead_guy for the name of .... well, some dead guy.

  • Member functions:

      • a default constructor that will set murder_committed to false and dead_guy to the empty string with hair color 0 as a default value.

      • a meeting() function to which you pass two resident objects, and it returns nothing. This function will first call the murder() function that will, with a 50% chance, determine that a murder takes place during the meeting. If murder()returns false, that's the end of it. If it returns true, then meeting()will continue by determining which of the two residents committed the murder and which was murdered; each of the two residents have equal probability of being the murderer (and hence the victim is also determined). The residents' member variables will be changed to reflect this decision (hint: think about how to pass these objects.). Further, meeting()will copy the hair color of the murderer into the value of the room's hair variable, copy the name of the murdered resident into dead_guy, and set murder_committed to true.

      • a murder()function that returns a bool, 50% true.

    • a check_room()function that, if murder_committed is true, outputs a message to the screen that "dead_guy has been murdered!"; otherwise does nothing....maybe empties the trash or sweeps the floor....

      • any necessary (and NOT unnecessary) mutator/accessor functions.

Your driver should test your constructions of resident and crime_room. It should do this by declaring at least five residents and then outputting them to see if they are indeed alive, not murderers, have different hair, and have different names. Then use one of them to call its member functions to see if they work (outputting afterwards to prove so). Then declare a room and have it call its meeting() function passing it two of the residents. Call that function several times (I'd say at least 4 times) to see that a murder happens and/or doesn't happen. Be sure to output at appropriate times to prove the functions are working.

You will need to create a file of residents' names. Name it names.dat, or something else devilishly clever like my choice. Put these names in it and add some of your own:

Clayton Price Nate Eloe Katrina Ward Bushra Anjum Roger Rabbit T. S. Elliot Bob Dylan Seymour Butts

When you submit: do so.

As usual, if you have any questions about this assignment, don't hesitate to ask.