Assignment 10

Due: May 7, 2014 at noon

Points Possible: 100 pts.

Instructions: For this assignment you will submit multiple files, but not quite in the usual way. These files will contain a c++ program that you have named appropriately with appropriate extensions. You should have a file for your main (driver), a header for each class definition, an implementation file for each class. Submit using the cssubmit script. For this final project, you are going to be allowed to work in groups of 0 to 2; that means 0, 1, or 2. We encourage you to work with someone, but discourage you from an uneven distribution of workload. NO SPONGERS! A group of 0 is suboptimal. Since we allowing you to work in groups, you will submit only under one name for the group. Be sure to put all group members' names on every file.

The school_yard class:

  1. It will need accessors and mutators for the cells of the 2-D array, which we will henceforth refer to as the schoolyard. These functions will naturally need to be passed the location of the cell to be accessed.

  2. The school_yard needs some way to keep track of how much trash is in the yard at any time. This can be done in more than one way, but one way is to have a member variable and a accessor function.

  3. The school_yard's constructor will randomly place 'H' (for Hoover) in the schoolbuilding not in the doorway.

Specifications: Modifications first....

Before enumerating the changes/additions, let's briefly discuss the purpose of this program. The idea here is that your program will simulate classmates, initially placed at random in the school yard (outside the school building) wandering about the grounds picking up junk in an effort to create a viable science project. Eventually, he/she/it will enter the school building and, after encountering the teacher, will be assigned a grade for the project based on what they collected. When all classmates have received a grade, a MOST INTELLIGENT STUDENT AWARD will be given and the winner recognized .... the more likely to go to college.

Background: The background for this assignment is pretty much what you have learned about Ralph (click on images here and below), our intrepid hero, during the course of this class and its assignments. Ralph is, well, intellectually underdeveloped. In this assignment, you're going to find out just how 'under' his development really is. You are going to start with the classes that you developed in hw #9. If you are unfamiliar with hw #9, it's the one just after hw #8 and just before this one. But you are going to modify them and add other class(es).

Remember: This program will represent 10% of your final grade.

When you submit: Submit a program with yard_size 20, building_size 5, classmates named "Ralph" and "A Possum". Also, scatter only trash enough to cover 5% of the empty space in the yard.

Now, this next information is really important. There is no telling how many iterations your program will go through before your scholars make it into the school building to have their junk piles graded, so the output could be rather large. So, just before you submit, put a conditional statement in your code before the "display school_yard" code in the simulation that will make it display ONLY THE FIRST 10 LOOPS (showing how both classmates have moved 10 times). After the loop, display it one more time. Your conditional is simply

if (counter <= 10)

cout<<my_school<<endl;

As you develop your program, leave the if out. That way you can watch what is happening.

The Trash file:

12 dead cat 7 beer can

2 cigarette butt 10 Wookie hair matted with gum

4 used gum 11 digital watch

17 glue 9 helicopter rotor

5 tire iron 2 calculus text

1 dell Optiplex 7010 14 c++ text

8 bar of plutonium 3 hairspray

7 1966 Ford Mustang 8 dried lizard

3 bowl of oatmeal w/o the bowl 7 a living toad

9 dolphin liver 3 Krusty Burger

5 GNU compiler 5 Barney

6 Milhouse's glasses 9 vitamin C

You are welcome to add to the file. Remember to make the first entry in the file the number of items.

The classmate class:

  1. Replace the place() function with a go_to_school() function that is passed a school_yard object by reference. The classmate object will call its go_to_school() function, which "places" the classmate object in an empty cell of the school_yard at random. "Places" means that the chosen cell is given a value of 'C' (for classmate) and the student's location is set to the cell's location.

  2. Each classmate object will have pockets into which he/she/it puts trash objects encountered in their travels about the schoolyard. Implement the pockets using an array of Trash type objects (Trash is described below). Make the max number of items a classmate can hold 10. Naturally, the classmate will also need to keep track of how many pieces of trash they have.

  3. The move() function will be modified as follows. It will have to have a school_yard as a reference parameter. The classmate object will move one step (one cell) per call. If the classmate steps on a cell that is labeled 'T', they pick up the trash and put it in their pocket (array of trash). So, where does the Trash item come from? Your code will generate a Trash item using its default constructor "on the fly" - meaning it is created at that time the item is picked up; there are no pre-existing trash items. If the classmate's pockets are full, then the lowest valued item in the pockets is discarded and the new item replaces it (unless, of course, it is the most worthless crap he has picked up so far). Any discarded item just vanishes.....maybe it was eaten. Any glue picked up, gets eaten and the classmate's iq is diminished by 2 points. (Hence, no glue ends up in a pocket!) A classmate can NOT move out of the schoolyard, can NOT move through a school building wall, and can NOT move onto another classmate. You can code the movement of your classmate objects any way you want - random, smart, stupid, searching, whatever. But, once the school_yard has no more trash, a classmate object must move towards and onto the Door of the school building. Once in the building, the classmate can encounter the teacher and have their project (contents of their pockets) judged and scored. Again, the classmate's movements in the building can be random or targeted (go for the teacher), and if they step outside again, they will realize there is no trash and must reenter the building. Also, as the classmate moves about in the building, he/she/it must replace a cell marker with 'C' to show where they are and then replace that cell marker when they move further. Once a classmate receives a grade/score, they are removed from the grid so as to not block access to the teacher by any other classmate. It is left up to you to determine how smart a classmate's movements are. In summary, your classmate objects will move about the school_yard picking up trash until they go in the building; and they must go inside when no more trash exists. You decide when they go inside otherwise.

  4. You will need to have the classmate maintain whether they are actively moving, what their grade is, etc.

  5. The score that a classmate receives for their project will be the sum of values of the contents of their pockets divided by their iq. This makes sense; the smarter the student, the lower their grade for handing in a pile of refuse for a grade! Imagine if Einstein did this!! he should certainly get a lower grade than Ralph. Right?

The Trash struct:

    1. Trash will have a member variable for its name, and one for its value (a positive integer).

    2. It will have a constructor that will connect to a file of trash items and will pick at random an entry to instantiate the values of the trash item. The first data item in the file will be the number of items in the file. The format is:

value(int) name(string)

The simulation (main):

Your main function will declare a school_yard object, then two classmate objects named "Ralph" and "Possum". Each classmate will call their go_to_school() function, placing them at random in the schoolyard. At this point, your main starts a simulation (a loop) that has each classmate take turns moving until both are assigned a grade/score and a winner is declared. The winner's project must be output for inspection; we don't want any cheaters! Thus, a pseudo-code of your main might look like this:

start main

declare school_yard

declare classmate1,classmate2

classmate1.go_to_school()

classmate2.go_to_school()

display school_yard

initialize loop counter

start simulation - loop on trash gathering

classmate1.move()

classmate2.move()

display school_yard

increment loop counter

end simulation - end loop - all classmates scored

declare/display winner and number of moves to finish

end main

Optionals: There are many things you can do with this assignment that can make it even more interesting/funnier/harder/satisfying than it already is. If you have an idea that will add some kind of value to it, go ahead and implement it. Put a big comment at the start of main explaining any additions. Here are some good ideas:

  1. include a speak() function with the classmate class. Each time a classmate object pockets trash, have them say something. For example, have the possum obj simply say "hhssssssssss" regardless of what it picks up. Have Ralph say "I found a <name of trash obj>!" Then follow that with a randomly chosen statement from the file of Ralphisms from hw 8.

  2. Place a hole in the fence for any school_yard whose yard is smaller than MAX, so as to create a no-man's land outside the fenced part of the yard but inside the array. Scatter mines out there. If a classmate goes through the hole, well ......

  3. Create a teacher class with functionality that makes life interesting for classmates.