Assignment 09

Due: Friday, November 18, 2016, at noon, 100 points

For this assignment, you will submit multiple files containing a program written in C++. You know how to use the submit program by now; I needn't tell you.

The following is a list of topics we wish to address with this assignment:

    • classes

    • more classes

    • some classy classes

    • yet another class

    • everything else you learned up to this point

Resources: www.cplusplus.com Check out the different libraries, especially the iostream library.

Foreground: Programming assignments #9 and #10 are tied together. In this part (#9), you are going to build some of the classes used in the final program. After building them, you will use a main function that will test the functionality of the classes that you have created. This kind of main function is called a "driver". Again, it's only purpose is to test your classes. When you build hw #10, you replace this main with a "real" main that does something useful to solve the given problem. The details of the problem are going to be described in hw #10. For now, you just build some of the classes (described below) and use a driver to test them.

Background: As you all know, Lisa has a problem....ok, a concern....about pollution in the environment and folks in her town who cause it. She's driving herself crazy trying to clean up Springfield because she knows that eventually the EPA will condemn the whole town, seal it up, and then try to destroy it! So, she wishes to have a program that she can use to simulate her life as a "pollution control activist". In hw 9 and hw 10, you will create a 'world' for her to move about in, a 2-D array representing her town. In that town, you will place actors: an activist most likely named Lisa; and a polluting oaf named Homer. The activist will chase the polluter to try to stop him. But, of course, there are problems the activist will encounter in his/her quest: bumping into walls, get disoriented, wander outside town, etc. You will run the simulation several times and collect statistics to enable Lisa to predict the outcome. That is what you will do in hw 10. She will use hw 10 to run simulations on her projected life, and then use it to decide whether she wants to continue on her path to serious mental illness dealing with Springfieldians or terminate her contract with Fox and move to day-time drama. I know this doesn't make any sense at all, but oh well.....

In this, the current assignment (hw 9), you are going to build some pieces of hw 10. You will build three classes and test them. First, you build a town class that is a 2-D array of characters. The first and last columns and the top and bottom rows are used to represent a structure, such as a wall or dome-like-thing, that people can't pass through. Put the letter 'W' (for Wall) in those positions. In one cell in the middle of each row and column, place a 'E' for Exit. That represents a "window" where people can get out. (So, there should be 4 exits, one on each side of the town.) Next, you will build an activist class to represent a person like Lisa wants to be. This type of object will "move" about a town. To do that, the activist must have a location variable(s). An activist will also have a dignity value that starts at 100 and diminishes as he/she bumps into walls and experiences other "indignities" (to come). The activist will also have a toxicity level that changes during his/her journey through town depending on what he/she might consume. (There are a lot of roots scattered about town!) That level of toxicity will also determine whether the activist is normal (like you and me), cool (like Jerry Garcia), or gone (like, say, Timothy Leary or Wavey Gravey) - which means they are so intoxicated that they become dysfunctional, exit reality, and go to listen to jazz music somewhere for the remainder of the day (sorta like being dead). Lastly, create a polluter class to represent the "bad guy". It'll have a member to locate it in the town, and another for name, and finally a member for a character to represent it in the town grid.

Specifications: You are going to create classes in this part of the project for town, activist, and polluter. Here are descriptions of them:

  • town class:

    • member variables:

        • a 2-dim array of chars (statically) declared for MAX size of 25 x 25

        • a short integer describing the actual size of the town ( <= MAX). Your particular town object may not be as big as MAX x MAX, thus using only part of the array.

    • member functions:

        • a constructor that allows you to pass in a grid size and defaults to MAX. This constructor will call private functions that will clear() the grid, then a build() function that will place walls and exits as described in the background above.

        • a print function or the overloaded insertion operator.

        • appropriate accessor/mutator (set/get) functions.

  • activist class:

    • member variables:

        • a member for the activist's level of toxicity (a float ranging from 0 -> 3.0).

        • a member to represent his/her dignity (an integer ranging from 0 -> 100).

        • appropriate variable(s) for his/her location on the grid (in the school).

        • a char for how he/she is to be represented (in the town array).

        • state variable(s) to represent whether he/she is normal, cool, or gone.

        • a string for his/her name

    • member functions:

        • a constructor that takes arguments for character to represent the activist that defaults it to 'A', and a name. His/her toxicity will always start at .05, dignity at 100, and he'll/she'll be normal. Default the start position to (-1,-1).

        • a place_me() function that has a reference parameter of type town. It will determine the dimensions of the town, and from that will place the activist in the town's grid and change the activist's (private) coordinates. Of course, activist always prefers to be in the middle of things.

        • a rand_walk function() that has a reference to a town parameter. It will pick a random direction in which to take a step, and it will change its own coordinates and the location it occupies in the town passed to it.

        • a print() function or overloaded insertion operator.

  • polluter class:

    • member variables:

        • a member (a string) for the object's name.

        • variable(s) for location.

        • a char member for its representation (in the town array).

    • member functions:

        • a constructor that takes a string for name, and it initializes the location variable(s) to (-1, -1) and the character representation to 'P'.

        • a place_me() function to which you pass a town (by ref). It will place the polluter in the town at a random location in the town based on the dimensions of the town and not on top of anything else.

        • a random_move() function much like that for activist. You will need to pass a town object to it for obvious reasons.

Note: For both random move functions above (for polluter and for activist), the object should not be allowed to move to a location in the grid (the 2-D array of the town) already occupied by any other 'thing', like a wall or a polluter or an activist. If something is in the way, then move to a different location. Also, in your code you need to think about the limitations on what size town array (grid) you can create.

Now let's talk about the driver, your main. A driver would need to declare instances of each of the above classes and test their functions. We have decided to supply the driver for you. Sure, this saves you some trouble, BUT now you have to interpret someone else's code and make it work with your code. You can copy the file using wget below just as you did in hw 8 to get the data files. It is also posted along with this assignment under "solution". You would be wise to look at the driver first to understand naming conventions and what the driver will be testing. If you want to name some things a bit differently, that is ok. For example, the driver identifies the polluter as "Polluter". If you prefer "polluter" (lower case p), you can change the driver. You may NOT change the overall functionality of the driver.

wget http://web.mst.edu/~price/1570/hw9driver.cpp

Please understand that the final hw 10 program will be more interesting and fun, but you can only do so much at a time. This much will do for now. There will be objects of type root that the activist may happen upon! What then? Ha ha, it'll be a hoot.

When you submit, just submit and have some roots.