Assignment 09

Due: Friday, Apr. 15, 2016, at noon 100 points

For this assignment, you will submit multiple files containing a program written in C++.

Be sure that only the file(s) you want to submit are in that directory - make a directory for every assignment! The submit system runs just the same with multiple files. The submit system will deliver every .cpp and every .h file and every.dat file in the current directory to me. Name your files meaningful names and give them proper extensions.

Foreground: This assignment is going to be a little different from previous assignments. It will work in conjunction with hw #10 in the future. You are laying the groundwork for a bigger program here. Furthermore, this is all about food engineering and the engineering of Ozark Mountain Fastlane Food Eateries

Background: Cletus is tired of trying to be smart. He's now focusing on opening a sandwich restaurant out "in the sticks" where people really appreciate good eatins. He's gonna call it Cletus's Roadkill, and there's a really good reason that he wants that name. You see, Cletus knows that he can find cheap suppliers for this restaurant - cousin Billy, uncle Joe, his kids Randy, Freddy, and Whitney, and more! They all cruise the local byways looking for "possibles." Cletus can really do a lot with organic, sun-dried meats. Mmmmm mm! Bar-b-que! He even envisions eating contests.

But Cletus isn't sure that the idea will work out for certain, so in hw #10 you are going to write a program to simulate that contest. In that program, you will create an array of customers, have them eat Cletus's sammiches in turn, eating until they either die, quit, or win. Nice, eh?

In preparation for this impending carnage, you are going to code up a few classes for this assignment #9. You will also write a main function whose sole purpose is to test the classes you have created. By this we mean that it will declare objects of the types you created and then test their member functions. There is no other purpose to your main function. This type of main is commonly called a driver.

Specifications: In this assignment, you will create two classes. The first is a sammich class.

Your sammich class is to contain the following:

  • Member variables:

      • ints to represent the number of different animals on the sammich, the number of ozs of bacon, and the number of pickles.

      • a variable to indicate whether or not the sammich has cheese.

      • a variable to indicate whether or not the sammich has special sauce.

      • a variable to indicate whether or not the sammich contains a virulent pathogen.

      • a variable for the cost of the sammich

  • Member functions:

      • a constructor to which you can pass values of all the above member variables except cost.

      • a default constructor that will

          • set the int member variables to randomly chosen values adhering to the currently agreed upon maximum acceptable values for said members: 4 animals, 4 oz of bacon, and 4 pickles (Yuck!). A minimum of 0 in each case.

          • randomly set the bool members of the class. For having cheese or special sauce, it should be a 50-50 shot of having them. But for the pathogen, your code should assign true only 10% of the time.

      • appropriate set and get functions.

      • a non-member insertion operator overload.

  • Notes: Each animal costs $0.75, each oz. of bacon costs $0.50, each pickle slice is $0.25, the bread is $0.50 (total for both pieces), cheese on a sammich costs an extra $.25, special sauce is $.10. A virulent pathogen is free of charge, though you WILL pay in the end.

Your customer class has the following:

  • Member variables:

      • a member for the customer's name.

      • a member for their "local monetary holdings" i.e. cash in their pockets.

      • a member for the customer's weight.

      • a short to represent their cholesterol level (this value should normally fall between 30 and 300, inclusive).

      • a variable to indicate whether or not the customer is alive.

  • Member functions:

      • a default constructor that will

          • name the customer by drawing a name from a file of names. You can have your code pick names in the order that they appear in the file; when the list is exhausted, begin from the first name again. Make a file of names and put 15 names from "The Simpsons" in it.

          • randomly assigns them monetary holdings between $25 and $75, inclusive.

          • randomly assigns their weight between 90 lbs and 250 lbs, inclusive.

          • makes them living.

          • randomly assigns a cholesterol level between and including 30 and 300.

      • an eat() function which has as a parameter a sammich. The function should diminish the financial holdings of the customer by the price of the burger passed, increase the customer's cholesterol according to this function:

        • chol gain = 2.5 * B + (PI/2) * P + wt/((K + 1)*10), where B is the number of oz of bacon P is the number of animals K is the number of piKles

      • and increase the weight of the customer according to this formula:

        • wt gain = 0.5*P2 + (1/8)*B2 - K/4 + C + S, where B, P, and K are as above and C is the gain attributed to cheese, currently determined to be 1.2 S is the gain attributed to special sauce, currently determined to be 2.1

      • If the sammich eaten has a pathogen, then it will kill the customer. If the customer doesn't have the money for the sammich, s/he won't eat() the function, but will output a message to the screen: "I can't afford to eat."

      • and, of course, a non-member insertion operator overload.

Note: No customer is to be allowed to have a weight that is negative.

Note: The above descriptions of these classes are bare minimum. You may find it necessary or desirable to add relevant member variables and/or private member functions (to help make the code better). You should NOT add other public functions. Also, since you will be displaying dollar amounts, it's bad form to have $3.50 come out as $3.5. So, put this code at the top of your main after declarations and it will force exactly two decimal places to be shown always.

cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);

We reserve the right to change these classes and the formulas for wt gain and chol gain for hw #10.

Your driver (that's your main function) should declare objects of the types you have defined. It should test the member functions, including the constructors. After declaring these objects, output them to see their initial states. Pass a sammich to a customer and output the customer to see the effects. There should be no interaction with the user of the program. The driver is there merely to test your coding of the classes. Make the testing thorough.

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