Assignment 09

HOMEWORK #9

CS 53

Due: Friday, Nov. 16, 2012, at noon 100 points

This line is blinking

The line above this one is annoying

For this assignment, you will submit multiple files containing a program written in C++. Remember, to electronically submit a program for this course, first change to the directory in which the file(s) resides and then type in, at the UNIX prompt, the command:

cssubmit 53 section_letter assignment_number

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 The Krusty Corp., LLC, a fictional global network of Burger Producers and Gastrointestinal Distress Experts.

Background: Krusty Burgers are reportedly at the top of the "Most Evil Foods Ever" list, a list of commonly eaten pseudo-foods kept by the Division of Eatable Alternatives To Health, Federal Oversight Organization on Digested Stuff (DEATHFOODS for short). But, no matter ... Krusty and his Krusty Burger restaraunt hold a burger eating contest every year in Springfield. In hw #10, you are going to write a program to simulate that contest. Your program will create an array of customers, have them eat burgers 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.

Leanground: NOT!

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

Your burger class is to contain the following:

  • Member variables:

      • ints to represent the number of patties, the number of ozs of bacon, and the number of pickles.

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

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

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

  • Member functions:

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

      • a default constructor that will

          • set the int member variables to randomly chosen values adhering to the currently agreed upon acceptable values for said members. Note: the currently acceptable values are stated in hw #3 but are hereby modified: it is now allowable to have 4 patties, 4 bacons, and 4 pickles (Yuck!), but YOU will have to invent the names/labels for those burgers. You had better think about modifiers to the burger names given that they have cheese and/or special sauce, also.1

          • 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: Cheese on a burger 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. 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 burger. 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 patties 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 burger eaten has a pathogen, then it will kill the customer.

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

Note: The above descriptions of these classes are bare minimum. You may find it necessary or desirable to add relevent member variables and/or private member functions (to help make the code better). You should NOT add other public functions.

We reserve the right to change these classes and the formulas for wt gain and chol gain for hw #10. We have yet to code this up to see what happens; it's hard to guess, but we want it to be fun and interesting.

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 burger 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.

1You probably should not add to the name of a burger if it happens to have a virulent pathogen in it. Customers might be disuaded from purchasing a burger under the name "Krusty Deadly Koronary Burger" or even "Krusty Single Health-Master Garden-Fresh But-May-Kill-You Burger".

As always, if you have questions, don't hesitate to ask your instructor or the tutor in the lab in the evenings. This is a CS53 homework. Do not ask your CS54 instructor to clarify these instructions or provide help in "correctly" writing a solution to this homework.