Assignment 10

Due: Wednesday, December 10, 2014 at noon 100 pts ..... remember that this assignment will represent 10% of your final cs 1570 average!!

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, B or D).

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

Background: hw #9

Foreground: Here's the big picture. Your program is going to be a simulation of Dr. Eloe "administering medical expertise" to a group of patients. Thus, your main function will have an array of 10 patients, a doctor, six hospital rooms each with its own machine. Your program will have the doctor escort each of the patients from room to room (you pick the order, 'cause I doubt it will matter!) and "admit" them. The doctor and patient will interact with the room/machine until they have passed through each room. Then the doctor gets the next patient and begins his duty again. This continues until all patients have visited each of the six rooms. Now, every time a patient is admitted to a room, your code will apply the machine (if appropriate) and then output the patient and the number of times the machine was used on them. (You need to make this output very succinct - one or two lines.) And if the doctor vomits, output that too. After a patient has visited all machines, output the doctor's status. At the end of the whole simulation, you are to output the number of patients who died along the way and the how much money the doctor made. Be sure to put blank lines or a divider line between groups of output to make it easy to understand. Since you will have a lot of output, make the output of a patient one single line in this (or similar) format:

Joe weighs 155 lbs w/ MH = 23 and PH = 66 and has $4560.00

Likewise for the doctor.

Specifications: In this assignment, you will create other classes to add to the classes outlined in hw 9 and you will modify those in hw 9 appropriately:

First, you are to add a class for the doctor.

Your doctor class has the following:

  • Member variables:

    • a string for his/her name.

    • a short for the number of ozs of Schraut he/she has consumed.

    • a float for the amount of money he/she has. The doctor gets half of the income for each application of the machine.

  • Member functions:

    • a constructor that will have a single parameter for the name of the doctor. It will set his/her Schraut content and money to 0.

    • a puke function that will be called automatically whenever his Schraut content exceeds or equals 25 ozs. The net effect will be that his Schraut content will decrease to 0 (empty stomach!).

    • any other functions necessary to carry out the functionality described below.

To repeat clarify, every time a machine is used, the patient is charged (for each use for just one use, even if the machine is applied multiple times) and the doctor gets half the income. The other half goes to the hospital, but we won't keep track of that. Thus, as an example, if a patient is gets 4 lobotomies, he only pays for one.

Next, modify the patient to have a second health value, a mental_health value. It will also range from 0 to 100, inclusive. Also, add a member variable for weight of patient. Have the constructor also randomly assign the patient a mental state and weight between 120 and 220 lbs.

Next, you are to template the hospital room class on the type of machine that will be in a room. Name the template parameter T_machine. Thus, your hospital room will look like this:

template <class T_machine> class hospital_room { private: T_machine m_the_machine; ... };

    • Member functions:a default constructor that:

      • sets num_uses to 0

      • sets the cost of use to $200.

  • a charge_patient function.

  • an apply function that will increase the patient's mental health by 10 and physical health by 3. It also has a 3% chance of turning the patient into a vegetable (mental health = 0). It also has a 10% chance that the patient can no longer remember his/her name and thus picks another random name from the file. Rather than replace the patient's name, concatenate it onto his/her original name. (Doing so will make it very evident at the end of the simulation who has suffered this problem.)

  • an overloaded insertion operator so that you can output the state of the machine.

  • any necessary (and NOT unnecessary) mutator/accessor functions.

A organ_donor class is to contain the following:

  • Member variables:

      • a float cost_per_use.

      • a short num_uses.

  • Member functions:

      • a default constructor that:

          • sets num_uses to 0

          • sets the cost of use to $100.

      • a charge_patient function.

      • an apply function that will increase the patient's mental health by 10, but will decrease his/her physical health by a random value from the interval [0, 20]. It also has a 2% chance of killing the patient (physical health = 0). And, of course, it will decrease the patient's weight by 10 lbs.

      • an overloaded insertion operator so that you can output the state of the machine.

      • any necessary (and NOT unnecessary) mutator/accessor functions.

A placaeboizer class is to contain the following:

  • Member variables:

      • a float cost_per_use.

      • a short num_uses.

  • Member functions:

      • a default constructor that:

          • sets num_uses to 0

          • sets the cost of use to $500 ... what a rip-off!

      • a charge_patient function.

      • an apply function that will do nothing at all to the physical well-being of the patient. However, the patient's mental health value will increase by an amount equal to half the difference between their current mental health and the maximum mental health. [ MH += (100-MH)/2; ] So, the more this machine is applied, the closer to euphoria becomes the patient! Also, since they are so happy, they gain weight....add 50 lbs to their weight.

      • an overloaded insertion operator so that you can output the state of the machine.

      • any necessary (and NOT unnecessary) mutator/accessor functions.

A pharmacy class is to contain the following:

  • Member variables:

      • a float cost_per_use.

      • a short num_uses.

      • a short num_pills.

  • Member functions:

      • a default constructor that:

          • sets num_uses to 0

          • sets the cost of use to $150.

          • sets the number of pills to a random value between 50 and 100.

      • a charge_patient function.

      • an apply function that will decrement the number of pills in the pharmacy (object). That pill (is presumably administered to the patient and) has a 25% chance of doing one of the following:

          1. physical health increases by 10, mental health decreases by 10.

          2. physical health increases by 20, mental health set to 0.

          3. physical health set to 50.

          4. mental health set to 100 and weight increased by 100 (the "fat and happy" pill).

      • If the machine runs out of pills, then the machine dispenses a cotton ball and the patient stupidly eats it. This causes mental distress to the order of -23 and amazing weight gain of ... um ... 44 lbs. Don't ask us how to explain this; none of us are doctors! (By the way, you do NOT need to introduce a cotton_ball class.)

      • an overloaded insertion operator so that you can output the state of the machine.

      • any necessary (and NOT unnecessary) mutator/accessor functions.

A liposuctionizer class is to contain the following:

Member variables:

    • a float cost_per_use.

    • a short num_uses.

Member functions:

      • a default constructor that:

        • sets num_uses to 0

        • sets the cost of use to $750.

    • a charge_patient function.

    • an apply function that will reduce the patient's weight by 10%, but will also increase their mental state by 20. However, it does have a problem. After every 61 times that it is used, it will kill a patient. Bummer!

    • an overloaded insertion operator so that you can output the state of the machine.

    • any necessary (and NOT unnecessary) mutator/accessor functions.

As always, if you have questions, don't hesitate to ask your instructor or the LEAD guys. This is a CS1570 homework. Do not ask your CS1580 instructor to clarify these instructions or provide help in "correctly" writing a solution to this homework.

Furthermore, as we show you in class, you will put the implementations of the functions for this class in a .hpp file that is included at the bottom of the .h file for the class. In what follows, you will see that you are to create 5 more different types of medical machine classes. So, creating a hospital room with the template parameter instantiated with a particular machine is like building a room containing one of those machines.Now, as before, the hospital_room class will have an admit function to which will be passed not only the patient, but also the doctor. If the patient is not alive or does not have the requisite money to pay the machine's fee, both the patient and the doctor leave the room and go on to the next machine. Otherwise, this function will:

    1. Charge the patient its fee.

    2. Have the doctor consume 1, 2, or 3 ozs of Schraut. This amount is chosen at random each time the doc enters a room. If the room's bottle of Schraut has less than what the doctor desires to drink, he drinks what is there.

    3. Apply the functionality of the machine in the room to the patient in accordance with the following rule:

        • if the doctor was able to consume any Schraut, then the number of applications of the machine that the doctor subjects the patient to is the number of ozs of Schraut contained in the doctor minus 5. (This simulates the irrational behavior of a drunk Dr. Eloe.) So, for example, if the doc has consumed 16 ozs of Schraut so far, then he applies the machine to the patient 11 times.

        • if the doctor was not able to consume any Schraut because that room's bottle was empty, then double the number of applications described in the first part. (This simulates the doc getting mad because his Meds bottle was empty.)

        • assuming the patient isn't dead and has enough money, the machine will be applied at least once.

You are to also add the following machines:

A lobotomizer class is to contain the following:

  • Member variables:a float cost_per_use.

  • a short num_uses.