Assignment 09

Due: Friday, April 26, 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.

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: You've done well to help Marge in so many ways. Now, you are going to do something new and much more fun. You're going to write a program that will help Marge understand just how she fits into her world. You're going to write a program that is a simulation of life in the Simpsons' household from the Marge point of view. This program will work in conjunction with hw 10. The classes you create in this assignment will be expanded/extended/modified/added to in hw 10. Assignment 9 is the "testing ground" for basic classes for the simulation, and assignment 10 will be a real (unreal) hoot!

Here's a brief summary of what assignments 9 and 10 will entail. You will create a house class whose primary data member is a 2-D array that represents the floor plan of the house object. You will have different "actors" that will interact with each other in a simulation of life in the Simpson's household. A "cleaner" object (named Marge) will move about with her vacuum trying to keep up with all the mess her family makes. There will be trash strewed about, family members adding trash, etc.

So, in this part of the project, you will create classes and then test them. You'll have to define the classes and their functionality, then declare objects of those types, then have them call their member functions to see that they work.

Specifications: You are to create the following classes. Remember to put the definition of each class in its own header, and the definitions of member functions in their own .cpp files. One class per file, two files per class.

class cleaner:

data members:

    • name

    • stress level (an integer between and including 0 and 100)

    • location (on the floor, in the house)

member functions:

    • a constructor that has two parameters: a string or ntca that will be the object's name; some construct(s)1 that will establish the object's location in a 2-D array, defaulted to (0,0). This constructor will set the object's name and location using the args passed. It will also give the object an initial stress level of 0.

    • a calc_stress() function that returns nothing, but has one parameter of type house. This function will "scan" the house argument passed and set the stress_level member accordingly. The stress_level will be set to the rounded down proportion of the house's floor plan that is covered with trash. Thus, if the house is a 2-D array 25 x 25, and there are 42 pieces of trash, then stress_level is (42/(25*25)) * 100% rounded = 18 6. But, wait, there's more! Every instance of a person the cleaner finds in the scan will add two points to this calculation. So, in this same example, if there were two people in the house, then the stress_level would be 10. This calculation is not to exceed 100, of course.

    • an overloaded insertion operator that will output the object in this format: < name> is at <location> stressed at level <stress_level>. You can make this a 'print()' function until we show you how to overload the insertion operator for classes.

    • appropriately needed accessor and mutator functions.

class family_member:

data members:

  • a name (ntca or string).

  • a location

  • an (integer) sloppiness_factor on a scale of 0->100.

member functions:

  • a constructor that initializes the location to a default location (0,0). Furthermore, it will access an input file named "family_member.txt" in order determine the objects name and sloppiness_factor, this done by randomly choosing one such pair (see file below).

  • an overloaded insertion operator that will output the object in the format: < name > is at < location > has sloppiness < sloppiness_factor > You can make this a 'print()' function until we show you how to overload the insertion operator for classes.

  • appropriately needed accessor and mutator functions.

class house:

data members:

  • a 2-D array of characters with maximum size of 25 x 25. (Make a constant in this class's header file to be used for creating this array.) We'll refer to this as the "floor".

  • an unsigned short to represent the size of a particular house object. Call this member "size"; it should never be bigger than 25, the max size of a house.

  • an unsigned short to represent the initial number of trash items on the floor (in the house).

member functions:

  • a constructor that has parameters for the size of the house, and the number of trash items. This constructor will also be passed a cleaner object, and a family_member object, both of which it will place at random locations on the floor by placing a letter in that location. The letter used for each will be the first letter of the object's name member variable. For example, if the cleaner's name is "Marge", then place a 'M' where Marge is located. The constructor then calls the scatter_trash function. When each thing is placed on the floor, it should not be place on top of another person or piece of trash....or anything else. Once the people are placed, their location member needs to updated to reflect their new location value.

  • an overloaded insertion operator that will output the house (floor grid) to show where the cleaner, trash, and family_member(s) are. You can make this a 'print()' function until we show you how to overload the insertion operator for classes.

  • a private function called scatter_trash that will place the initial trash items at random locations in the house. The constructor should call this function. The function should place a 't' in random locations on the floor.

Now that you have your classes, write a main function that will create a cleaner named "Marge", then a family_member, and a house that you pass cleaner and family_member to. Output the house, then the cleaner, and then the family_member. Have Marge call her calc_stress() function and output Marge again.

Note: you should have at least 8 files for this programming project.

Family_members file: This is the data that should be in your family_members file: (name followed by sloppiness_factor)

Homer 98

Bart 73

Lisa 2

maggie 37

When you submit: do it.

1It will be up to you how you want to represent the location of an object in the house (a 2-D array). You can either make a struct point, or keep two values for coordinates......you choose.