Assignment 09

Due: Friday, Nov. 8, 2019, at noon 100 points

For this assignment, you will submit multiple files containing a program written in C++. 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 Dr. Nick, fictional medical equipment, and what happens when you go to the Springfield (not Missouri...some other unknown state) hospital.

Background: Dr. Nick doesn't care about almost anything ... but himself and his money. But what does he care what you think? Anyway, he's going to automate his medical practice and wants you to write a program that will simulate his ideas so that he will have some idea of how it will work out for him. Ultimately, hw 10 will be a simulation of a doctor (presumably Dr. Nick) and a patient entering the hospital and moving from room to room to see what happens. Patients will enter the hospital and be accompanied by the doc from room to room to receive "treatment". The simulation will end when, ... well, you'll see. For this assignment, you will build some of the pieces.

Specifications: In this assignment, you will create three classes. The first is the x_rayer class. This represents an x-ray machine that will be placed in a hospital room for use by the good doctor...or the bad doctor as the case may be. The other classes include the hospital_room and the patient. Below, we will describe what will define an x_rayer, a hospital_room,and a patient. You will also create a main function in which you will create an object of type x_rayer and an object of type hospital_room and an object of type patient to test the functionality of your new user-defined types. This kind of main is called a driver, since it is used solely to test something (new). In that driver, you will create enough objects of your new type(s) in order to adequately test their functions. We leave it up to you to do this properly.

Your x_rayer class is to contain the following:

  • Member variables:

      • a float to represent the cost for each use. Name this member cost_per_use.

      • a short called num_uses that represents the number of times that particular machine has been used.

  • Member functions:

      • a default constructor that:

          • sets num_uses to 0

          • sets the cost of use to $550.

      • a charge_patient function that returns nothing. It must be passed a patient object by reference, and this patient is "charged" the cost of use of the machine (had his/her assets diminished).

      • an apply function that returns nothing. This function will modify the health of the patient that is passed to it (by reference, of course) not at all most of the time. However, as you know, x-ray machines are dangerous sometimes. So, make it so that, with a probability of 0.1, this machine will halve the patient's condition value. Bummer! ah well, what can you do..... The sad part is that the patient is charged anyway!

      • an overloaded (actually, non-member) insertion operator so that you can output the state of the x-ray machine.

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

Your patient class has the following:

  • Member variables:

      • a float for the amount of money he/she has.

      • a bool is_alive to signify whether or not death has set in.

      • an int condition that ranks the patient's overall health (0 = dead and 100 = perfect health, with gradations in between).

      • a variable for the patient's name.

  • Member functions:

      • a default constructor that will randomly assign the patient's monetary resources (how much money they have between $0 and $4000), their condition and hence whether or not they are alive (again, chosen at random from between 0 and 100), and picks their name at random from a file of names (see below).

      • a pay_out function that will reduce their monetary assets by the amount passed.

      • a modify_health function that will add to the patient's condition member the value that is passed to it. This function will also call a private member function of this class described as ...

      • the kill function, which will update the is_alive member if condition is 0 (that is, updates their aliveness if they're dead). I hope this makes sense. If not, make an appointment with your doctor or clergyman for a consultation on "the human condition". If your doctor is Dr. Nick, disregard this advice.

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

      • a overloaded insertion operator (yes, a non-member) so that you can easily output the state of the patient.

Your hospital_room class is to contain the following:

  • Member variables:

      • a x_rayer called the_machine.

      • a float to represent the number of ounces of gin Dr. Nick keeps in each room.

  • Member functions:

      • a default constructor that will set the number of ozs of gin to 10.0.

      • a admit function that returns nothing. This function will be passed a patient object by reference and will call the machine's charge_patient and apply functions, passing the patient to them.

      • an overloaded insertion operator that will output the state of the room. Now, this means that it will output the x_rayer member using it's insertion.

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

Your driver (that's your main function) should declare a hospital_room and 3 patients. Note: the room you declare contains a x_rayer member variable, so it will be created automatically when the room is created (by calling the default ocnstructor for the machine. After declaring these objects, output them to see their initial states. Then pass (admit) the first patient to the room 5 times and output the objects again to see how things have changed. Facts of concern:

    • did your patient survive?

    • did the patient get better, or worse?

    • did the patient end up in the poorhouse?

    • is this a stupid program?

    • just what is the meaning of life?

Note: In this program, you may allow your patient's funds to dip below 0. You'll take care of this issue in hw 10. There will, of course, be other modifications/additions in hw 10. Also notice that the patient is passed by reference to the member functions of the room and machine. If you did not do this, then the patient object would be copied and the original would not be affected by the "stuff" that the room does. (This could be good, but I digress. Besides, cloning is a myth.)

As with all previous assignments, you will be graded based on proper use of constants that may very well change in the next homework. Further, parameters to functions that will not change in the function should be constant. Member variables should be accompanied with appropriate getters/accessors and setters/mutators.

To Obtain the data file: Create the directory where you are going to make your hw 9 program, and then change to that directory. Then, at the unix prompt, type wget http://web.mst.edu/~price/1570/names.dat

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 CS1570 homework. Do not ask your CS1580 instructor to clarify these instructions or provide help in "correctly" writing a solution to this homework.

1Don't be concerned about the gin. It's there for the doctor and will be used in hw #10.