Assignment 09

Due: Friday, November 18, 2011, 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

    • yet another class

    • everything else you learned up to this point

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

Background: homework #7 This gives you the basic layout of the problem. But now you are going to rebuild this entire program using classes. You will create a Object-Oriented version of this program WITH modifications. So, don't stop reading here.

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 write 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 a driver to test them.

The second big changeup for this assignment is that you are going to be allowed to work in groups. You may form a group of no more than 3 individuals to work on both #9 and, eventually, #10 assignments together. This is NOT required; you can do these assignments on your own if you desire. There are two stipulations:

    • You will divide the work equitably. This means no sponging! Everyone codes, everyone documents, everyone tests.

    • All individuals in a group have the same instructor, e.g. if one member is in Price's class, then they all are (regardless of whether section A or E).

Specifications: You are going to create classes in this part of the project for school, janitor, and lunch. Here are descriptions of them:

  • school 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 school ( <= MAX)

    • 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 windows as described in hw #7.

        • a print function or the overloaded insertion operator

        • appropriate accessor/mutator (set/get) functions

  • janitor class:

    • member variables:

        • a member for the janitor's blood alcohol content (bac)

        • a member for the number of bruises

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

        • a char for how he/she is to be represented

        • state variable(s) to represent whether he/she is sober, drunk, or dead

        • a string for his/her name

    • member functions:

        • a constructor that takes arguments for character to represent the janitor and defaults it to 'J', and name. His/her bac will always start at .05, bruises at 0, and he'll/she'll be (alive and) sober. Default the start position to (-1,-1).

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

        • a rand_walk function() that has a reference to a school parameter. It will pick a random direction in which to take a step (or maybe two) as in the hw #7 way, and it will change its own coordinates and the location it occupies in the school passed to it.

        • a print() function or overloaded insertion operator.

  • lunch class:

    • member variables:

        • a member for location

        • a char member for its representation

    • member functions:

        • a constructor that initializes the location variable(s) to (-1, -1).

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

        • a random_move() function much like that for janitor. Yes, the lunch is soo moldy that it has grown legs. You will need to pass a school object to it for obvious reasons.

Now let's talk about the driver, your main. In your main, you will need to declare instances of each of the above classes and test their functions. For school, declare a school object (with a size less than MAX) and print it to see that the print function works and the "stuff" is placed appropriately. Declare a janitor and print him. Then declare another with different parameters and print to see if he is different. Have the objects call their place_me() functions. Have them move and see that it works. You'll need to print the school to see that the moved. Etc.

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 whiskey bottle and coffee thermos that the janitor may happen upon! What then? Ha ha, it'll be a hoot.

When you submit, submit under only one name and be sure to include in your comment header the names of your partners on this project.

As always, if you have questions, don't hesitate to ask your instructor, or ask the lab help in the LEAD guys in the evenings.