Assignment 10

HOMEWORK #10

CS 53

Due: Wednesday, Dec. 5, 2012, at noon 100 points

For this assignment, you will submit multiple files containing a program written in C++. Also, for this assignment you are going to be allowed to work in groups. You may form a group of no more than 2 individuals to work on assignments #10 together. This is NOT required; you can do this assignment on your own if you desire. There are two stipulations:

    • You will divide the work equitably. This means no sponging! Everyone codes, everyone documents, everyone tests.

    • All individuals in a group have the same instructor, e.g. if one member is in Price's class, then they all are (regardless of whether section A or B).

When you submit your work, submit under only one name, but be sure to put all names in the comment headers.

Background: background

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 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!

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 heartattack, 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.

    • There are 4 ways for a contestant to die.

        1. their weight gain during the contest is 80 lbs or more - bursting is a terrible way to go.

        2. their cholesterol exceeds 300, resulting in a heartattack.

        3. their health level goes to 0. ..... Bummer.

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

    • Now, for the contest, output a line of dashes 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. Indent the burger 2 spaces so it's easier to read. Anytime a contestant pukes, (s)he must "say" something - create a file of "barf calls" that you randomly choose from (you can make them up). But it should be indented several spaces after the burger and should be of this format: "Homer pukes....BLAHHH GLPRP", i.e. include the name. Anytime a contestant throws a burger, (s)he also has to say something. Implement this any way you want; format the output similar to the puke-call.

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

When you submit: Run the simulation once.

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.

1DON'T use the word 'throw' for a function name since it is a reserved word.