Due: Friday, April 25, 2014 at noon 100 points
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: You've gotten to know Ralph as a cognitively challenged individual, a mental giant amongst Wookies, a fellow of the School of Stupid, Plastic Letters, and a patron of the Arts. Well, maybe not. But Ralph is happy with your work so far. Now, you're going to work for one of Ralph's mentors: Principal Skinner. Mr. Skinner wants you to write a program that is going be a simulation of Ralph's life at school, Springfield Elementary. Most of the fun for this programming assignment will be in hw # 10. But you are going to set things up in the present assignment.
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 classmate class:
member variables:
a string (either type) variable for the object's name.
some way to maintain their location in 2-dimensions. You can either keep two ints for x- and y-coordinates or make a struct for a point....it's up to you.
a variable for the object's intelligence quotient (iq).
member functions:
a constructor to which you can pass a string for the object's name. Default the name to "Bob". This constructor will go on to randomly generate for the object an iq value between and including 50 and 70. Furthermore, it will call the place() function.
a place() function that will give the object a location value for which both x- and y-coords will be chosen randomly between and include 0 and 24.
appropriate set() and get() functions for iq. Be careful how you define them.
an overloaded insertion operator that will output a classmate in the form: <name> has iq <iq_val> and is at <x-loc, y-loc>. For example: Toadie has iq 45 and is at (4, 7). (The name Toadie indicates the class of people we're dealing with.)
a move() function that returns nothing but it will randomly change the location of the object by either decrementing or incrementing its x- or y-coord with an equal chance for any possibility. Be sure that the move() doesn't place the object out of bounds!
The schoolyard class:
member variables:
a 2-Dimensional array of char. Make both dimensions MAX = 25 in the definition of the class. This will represent the maximum size of any schoolyard you declare. Of course, some schoolyards may be smaller than that. So....
a short integer to represent the dimensions (both) of the actual usable size of the schoolyard. This corresponds to how much of the 25 x 25 max yard your particular school yard will use.
a short integer to represent the dimensions (both) of the school building that is in the school yard. This corresponds to how much of the school yard that the building will use. (See info about placement of building in yard below.)
member functions:
a constructor that has parameters for two integers. The first will be the yard_size of the schoolyard. It must be less than or equal to MAX. The second is the building_size (both dimensions) of a school building that sits in the schoolyard with one corner at (0, 0). Again, this integer must be (strictly) less than the size of the schoolyard (yard_size), otherwise the building would take up the whole schoolyard and Ralph and his possum would have no place to play. The constructor should initialize the two member sizes to what is passed for the two sizes. It should then call a private function called build_school().
the build_school() function, called only by the constructor, will do the following:
Place an 'S' in every cell of the school (cells[0-->building_size-1][0-->building_size-1] to establish where the building is.
Place a 'D' (for door) in the cell of the school building opposite the (0, 0) cell.
Place a space everywhere else.
Place a 'T' (stands for trash) in 10% (rounded down) of the blank spaces at random in the yard (outside of the building).
an overloaded insertion() operator that will output the entire schoolyard and building in a nicely formatted way so you can see what it all looks like.
get() functions for both yard_sizes and building_size.
When you submit, there should be no user input. Your driver (main) should create objects of the types you have defined and test their functionality. Use the insertion operators to output the objects for viewing to see that they are what you expected.
In the final programming project, you will modify these classes to interact with each other and other classes to do some really fun. You'll see.