Assignment 09

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.

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.
  • a variable for the name of the burger - as determined by the above contents.

Member functions:

  • a constructor to which you can pass values of all the above member variables except the name. It's name should be constructed based on the contents.
  • 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.
    • 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. This should output all the info about the burger for now. There are lots of ways to do this, some long and some short. You need all the information in order to see if your code is really doing what it's supposed to do. You probably want to make it short and to the point. [Here's one idea: Krusty Blah Blah Blah Burger, (2,1,3,true,true,false) $X.YZ. The values in the parentheses indicate 2-patties,1bacon,3 pickles, has cheese, has sauce, no pathogen.] You will probably modify this in hw 10 to be shorter. For now, output all that information for testing purposes.

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 (U.S. dollars).
  • a member for the customer's weight (in lbs).
  • 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. Or, can pick them at random but without repeats. However you like. You can download a file of names with this: wget http://web.mst.edu/~price/1570/simpson_names.dat You will use this as you did in hw 8.
    • 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 IBUs.
  • 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
*These last two values added only when cheese and sauce are present
  • If the burger eaten has a pathogen, then it will kill the customer.
  • appropriate set and get functions.
  • and, of course, a non-member insertion operator overload. This should display the name, wt, money, cholesterol, and life status. Keep it to one line, such as Marge Simpson weighs 124 lbs, has $45.55, 155 IBU and is ALIVE. (put DEAD or ALIVE in all caps to make it stand out)

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.

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 (to eat) 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.

Assignment 10

Background: Assignment 09

Foreground: Here's the big picture. Your program is going to be a simulation of a burger eating contest at Krusty Burger! In brief, you will have an array of customers (the contestants) eating burgers in multiple rounds of the contest to see who "survives". Sometimes there is a single winner (survivor) and sometimes there are more. You will identify the winners and their stats.

Specifications: In this assignment, you will use your classes from hw #9 and add another class:

A burgermeister class is to contain the following:

Member variables:

  • a name (presumably instantiated w/ "Krusty")
  • monetary holdings

Member functions:

  • a constructor that accepts a string for the object's name and a float for monetary holdings.
  • an overloaded += operator that takes a float (representing money) and adds it to the burgermeister's money. So, you might have Krusty += 5; meaning Krusty just made $5.
  • an overloaded -= operator (for similar purposes).

You may have other members/functions, but that's up to you to decide.

The Customer class will be modified to include a health value that the constructor will randomly assign between 1 and 100, inclusive. A value of 0 is synonymous with death and should not be assigned by the constructor. You may have to add other member variables and/or functions to this class.

The contest will proceed as follows: There will be as many rounds as is necessary, ending when there are no contestants still eating burgers. You will start with an array of 15 customers; these are the contestants. In each round, every contestant is fed a burger if (s)he can eat it. Being able to eat a burger is determined by whether or not the contestant is alive, can pay for the burger, and is still a contestant. After the start of the contest, a contestant can become a non-contestant by either dying or angering the burgermeister so that (s)he disqualifies him/her (this is described later). When a contestant eats a burger, (s)he pays the burgermeister -- ok, I'm going to call him Krusty and you really should too -- the cost of the burger. Now things get interesting. As in hw 9, the customer's weight and cholesterol are adjusted accordingly. In addition, their health value is decremented by 2 points. Also, if a burger with a virulent pathogen is consumed, then the customer will either die or sicken and vomit. To determine which, "roll a 101-sided die"; if the value that comes up is greater than the customer's health value, they die; if the value is equal to or less than his/her health value, they vomit and their health is halved. If a contestant (let's call him Alpha) vomits, then there is a 50% chance that his neighbors will also vomit. So, if Alpha vomits, your code will have to first walk down the array of contestants determining (with a 50% chance) if the next contestant vomits....and if so, then the next....and if so, then the next....until you reach the bottom end of the array or someone doesn't vomit or the next guy/gal is dead. (Note: even alive non-contestants can puke.) After walking down the array, you will need to walk up the array doing the same until reaching the top of the array or someone doesn't vomit or you reach a dead contestant (thank God dead guys don't puke!). Now, in both cases (going down and going up), if the chain-reaction vomiting ends by someone just not vomiting, then that contestant has a 70% chance of starting a food fight. This means that (s)he throws a burger at another contestant or Krusty. Their target is chosen at random and can include themselves (stupid, yes, how stupid can you get - eating KrustyBurgers). When another contestant is hit by a burger, they have a 80% chance of continuing the fight by randomly choosing a target and throwing a burger. Each thrown burger has to be paid for by the thrower, but the thrower's health increments by 2 points. The food fight stops when someone decides not to throw, can't afford the burger to throw, a dead contestant is the target, or if Krusty is hit. If Krusty is hit, he gets angry and disqualifies the guy who hit him with a burger, and robs the thrower of all his cash. After the food fight ends 1) in the lower end of the array, continue checking for pukers in the upper end of the array; 2) in the upper end of the array, continue to the next round of feeding! The contest ends when no one can eat another burger - they are dead, out of the contest, or can't afford the burger.

Details:

  • The burgers that the contestants eat or throw are created "on the fly". That doesn't mean that they have flies on them (but probably do since they are Krusty Burgers). It means that your code will create a burger in that scope and the customer will eat() it or toss() it.1 (This is opposed to the concept of having, say, an array of burgers from which the contestants eat().)
  • There are two ways for a contestant to be disqualified (become a non-contestant). One is that he hits Krusty with a burger. You might find this unfortunate. But look at the positive side: they avoid exploding from eating too much, dying of a heart attack, and eating a pathogen. The other way is to die during the contest. Note: just because a contestant fails to eat during a round because they can't afford the burger, doesn't disqualify them.
  • If a contestant eats a contaminated burger, his health value is halved. Of course, if he dies then who cares. I certainly won't.
  • There are 4 ways for a contestant to die.
    • their weight gain during the contest is 80 lbs or more - bursting is a terrible way to go.
    • their cholesterol exceeds 300, resulting in a heart attack.
    • their health level goes to 0. ..... Bummer.
    • they eat a tainted burger.....really tainted.
  • The burgermeister shall be Krusty. Any other name would indicate that you just don't get it.
  • Krusty will start with $100 at the beginning of the contest.
  • Krusty collects the price of each burger. But, Krusty has to pay $5 each time a contestant vomits, and pays $35 every time a contestant dies during the contest ($30 for body disposal, $5 for flowers for the bereaved). If Krusty hasn't enough money to pay these fees, then he simply doesn't. Your code will not allow him to run a deficit. (Of course, this is not an option for customers.)
  • If Krusty is hit with a burger, he not only disqualifies the thrower, but also steals all his money.
  • The contest can end with one contestant still alive but hasn't eaten burgers for a round or more. This happens when they can't afford the burger given them and the others can, eating until their deaths. Running out of money can be a good strategy! Alternatively, there may be two or more still living at the end,and in this case, the winner is the one who ate the most burgers. If they have eaten the same number, the winner is the contestant who gained the most weight.
  • Your output: Make your output of burgers fit on one line if possible. Likewise with a customer. Put "DEAD" at the end of the output of a customer if they are indeed dead. I envision output that looks like this:
Begin the Contest!!!

The Contestants are
Marge Simpson 134 lbs ...
Barney Gumble 56 lbs ...Image result for flying hamburgers
etc

------------------------ ROUND #1 -------------------


Marge Simpson eats Krusty Veggie Burger wt 144, chol 188, ... ALIVE
Barney Gumble eats Krusty Double Blah Blah Burger wt 77, chol 305 ... DEAD
Chief Wiggum eats Krusty Single Yadi Yadi Burger wt 300, chol 221 ... ALIVE and barfs!
Bart barfs GAGGGG! BLAHHHCCCH
Lisa barfs BARBARA STREISAND!!
Lenny doesn't barf
Lenny tosses burger at Chief Wiggum
Chief Wiggum tosses burger at Homer Simpson
Homer Simpson tosses burger at Homer Simpson
Principle Skinner barfs
Edna Krabappel doesn't barf
Priciple Skinner eats Krusty ...... Burger wt 212, chol 34, .... ALIVE
ETC

-------------------------ROUND #2 ---------------------

Marge Simpson eats .........
ETC
  • So, you see that the indentation separates the different "activities" of the contest to make it easy to understand what's going on. Thus, you output a line of dashes and blank line or two between every round. Begin by outputting the list of contestants before anything happens. And, as the contest proceeds, output only the contestants that are eating, and then the burger they ate in that round. Anytime a contestant pukes, indent the puke "roster" like above. Annndddd, if the customer pukes, (s)he must "say" something. We want you to implement this as follows: make a constant array of strings with initial values like "BLAHHH BLURP GLRFMP". You make up 4 of these for your array of "puke oaths". Then, randomly index into the array when needed.
  • After the last round, identify the surviving contestants along with their stats. Proclaim a winner. Also, output Krusty's state - how much money he made or lost, whether or not he went broke, etc.
  • Any other output you come up with that makes this fun to see, go ahead and include it.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.