Assignment 10

Due: Wednesday, May 8, 2013 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. In addition, you have to the option to work on this assignment as a team of two or three coders. The stipulation is that your partner(s) also be enrolled in a section of cs 53 taught by the same instructor (could be a different section). When you submit, submit under only one name, but be sure to put all names in the comment headers of the files.

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.

Background, Presentground, Foreground: As you already know, this assignment is tied in with assignment 09. The constructions you put together for that assignment are the foundation for this one. You are going to modify those classes, add other classes to those, and create a main function that will simulate interaction between these "players". Your players will be the cleaner (assumed to be named Marge), the family members (assumed to be named Homer, Bart, Lisa, and Maggie), pieces of trash, and a trashcan. The simulation will generally work like this: you declare a cleaner and an array of 4 family members. These are passed to the constructor of a house you declare. The house randomly places some number of trash items (representing the initial state of the messy house), then places the cleaner and the family members and the trashcan at random locations (all of which occupy unoccupied locations - don't allow Bart to be placed on top of trash, Homer to be placed in the trashcan where he belongs, Maggie to be placed on top of Marge, etc). Then, to simulate a day's labor cleaning and trashing, in each time unit each of Marge and the family members will move in turn (beginning with the cleaner Marge). Marge will activate her vacuum's vac function to clean up her new location, family members will drop trash (or not). If Marge encounters the trashcan, she empties the vacuum and then continues. The simulation ends when one of the following occurs:

  • Marge is electrocuted by the vacuum which sucked up something that causes a short.

  • Marge is killed by an exploding vacuum which has exceeded its capacity.

  • Marge has nothing else to vacuum.

  • Marge has a (deadly) aneurism due to skyrocketed stress level caused by too much trash.

  • Marge falls out a window while cleaning. (If this happens, the fall kills her.)

Specifications: You will need code the following classes:

    1. First, modify the house class to have its constructor accept an array of family_member instead of just one. Thus, the constructor will set the size of the floor (remember, max 25!), call its private clear() function, call its private scatter_trash() function, randomly place the cleaner and update its location variable, randomly place the family members and update their locations, randomly place the trash can (use 'C'). In addition, you will have the outer cells of the 2-D array representing the floor (house) be walls and windows. Use 'b' for wall, and use 'W' for windows. Place a window every fourth non-corner cell in all four walls, beginning from whichever corner you like. Now, you're going to find that you will have trouble representing with one char what is happening in each cell of the floor. I'd suggest you read over this entire problem statement before you decided exactly what you will have a 2-D array of. An array of chars probably won't cut it. Think about an array of cells (of some struct type) that will "keep" all the info you need.

    2. Second, modify the cleaner class to have another member variable of type vacuum. This type object is described next. The cleaner will also have to have a member to describe her as alive or not. Also, the cleaner will have to have a step() function that determines which is the next cell (adjacent, since cleaner Marge's hair prevents successful flight) she goes to, and then what action she takes next. If the trashcan is there, she empties the vacuum. (You can either have her stand on the trashcan, or remain where she was to empty the bag.) If a piece of trash is there, she activates her vacuum's vac() function and passes the trash to it. If a family member is there, she finds another place to step. And at each step, Marge has to determine if she is done cleaning or if she is due for an aneurism (stress of 100 kills her) , she has been electrocuted, fallen out of a window, or exploded. So where does the trash item come from? Your code will have to create it (declare it) "on the fly". That doesn't mean you create trash with flies on it, it means you have code that declares that item right there in that scope. Then feed it to the vacuum cleaner. You can write your code for the cleaner's step() function however you want. You can make the next location randomly chosen, or chosen some "smart" way. It's up to you. But randomness is really funny! (Remember, next location is up, down, left, or right only.)

    3. Third, modify family_member to have a drop_trash() function that will use their sloppiness_factor to determine whether or not they leave a trash item (place a 't') in their location. They also have a step() function that randomly picks a new location to go (same as cleaner - one cell per step).

  1. Fourth, create a vacuum class:

class vacuum:

data members:

        • an array of trash items called bag sized at 35 (a constant of course, established in the vac class).

        • an int to represent the number of trash items in the trash bag.

        • a member to record its status as shorted out.

member functions:

          • a default constructor that sets the contents to 0 and that it is not shorted out (a good thing).

          • a vac() function that activates the vacuuming action of the device. It will return nothing, but is passed a trash item that it copies into its bag member (array) variable and increments its contents. If you would like to write this function as an overloaded member insertion operator because it seems funny, go ahead. (inserting trash into the vacuum? get it, get it??) This function will also need to determine whether or not the vacuum explodes or shorts out, and what the consequences are and how to implement that is up to you.

          • a empty() function that empties the contents of the bag in to the trashcan. Note: there is no trashcan-type object. When Marge encounters a trashcan ( 'C' ) on the floor, she has her vacuum call its empty() function which displays the contents to the screen while dumping it into a blackhole, i.e. it just goes away, also causing global warming.

          • you might want to included an isExploded() and an isSparky() function that the cleaner can use to determine her/his fate.

4. Fifth, create a trash class:

class trash

data members:

          • a string for the name of the item.

          • an int for the potential to cause a short (0 -> 100)

member functions:

          • a constructor that sets the name of the item and its potential. Potential and name are read from a file.

          • appropriate accessor(s).

In addition, if any player (cleaner or family_member) steps into a window cell, that means they just fell out the window. Who cares if it was a family member; all they ever did was spread trash. They're dead and no longer move about; no zombies in the Simpsons family. If the cleaner falls out, she is dead and the simulation ends. At each time step in this simulation, your code should output the house so that you can see how everyone has moved. When you submit, comment out that line of code so as not to generate a zillion pages of output.

Now, in all the above classes, you may have to add other functions or members to make this all work. Do so, but do it with thought! You might need to add mutators/accessors, but do it only if you need them and code them safely. If you wish to make interesting additional functionality, be sure to write a good comment at the beginning of your main to let the grader know. For example, you might want to allow Marge to vacuum family members. In doing so, you have to decide what happens. Maybe you would like to read from a file what that person "says" when vacuumed, e.g. Homer says "blbllblblblblblbl" to emulate his blubber being caught in the vacuum, Bart might say "don't have a cow, man", etc. Think about who might actually get sucked up into the vacuum. There are many possibilities!

The Driver: You will have your main function declare the objects (in the right order, mind you) and run the simulation of the players' lives in their little house of horrors. So, what is simulation? Clearly, you will have a loop, each iteration of which has everyone taking a step and doing their thing. It stops under the conditions outlined above. Output the final status of the house: who died, and how the cleaner died if he/she expired. Don't comment out the very last floor output.

As we get closer to the submit date, we may change the simulation parameters, such as initial number of trash items to scatter, house size, etc.

Interesting note: Marge's stress level actually goes down when a family member falls out a window and dies!

The trash file: Here's what you will want to start your trash.dat file with:

59 beer can

34 saxophone

4 Maggie poop

19 hairball

23 stink bomb

15 Krustyburger

19 floor-pie

8 pacifier

12 Millhouse

16 Snowball

35 skateboard

67 Lisa's braces

76 bar of radioactive uranium isotope

0 Flanders

4 Ralph Wiggum

10 Quimby's sash

23 Grandpa's dentures

3 Nate Eloe

5 cigarette butts

9 kleenex

10 toilet brush

8 toilet plunger

6 tv remote

12 can of spam

90 wad of steel wool

24 cattle prod

34 electric fencer

13 sling shot

2 a shoe

9 a foot

10 whoopee cushion

50 anti-matter

7 unsigned int

33 keys

2 mustard packet

5 gremlin

6 krusty doll

8 roomba

....and you can add whatever you want.