SPA 1: Fluid Tracking

A key health indicator for hospitalized patients is ratio of fluid intake (IVs, drinks, Popsicles, etc.) to fluid output (urine, blood loss, etc.). This metric is useful because it can identify dangerous issues such as dehydration and renal failure without requiring expensive, invasive tests. See this site for more details if you are interested. For this assignment, you are going to write a program which keeps a running tally of intakes and output and flags when the differential is 1 liter or more, a commonly used value. This will give you experience with writing basic loops and doing simple computations in C++.

Unlike most other assignments, it is fine to work together with another student on this assignment. That is, we will not be examining your solutions for plagiarism. It would be good to document who you worked with in your code (as described in the integrity policy), but we will not check for this assignment.

The input to your program will be a simple log for a given patient. Each log entry is on its own line and will have the form

        time item amount in milliliters
For example:
        7:00 iv 200
        7:30 orange_juice 100
        8:00 iv 300
        13:15 water 150
        14:05 urine 100
        15:05 bloodloss 50
        15:30 soup 400
        15:30 coffee 200
        15:50 diarrhea 350
(You have to respect those who do these measurements!) For simplicity, you can make the following assumptions: The program reads the data (with no prompt) and prints a message of the form
        after consuming UUU at VVV, intake exceeds output by XXX ml
whenever the accumulated total is greater than 1000 milliliters (one liter). In this output, UUU is the item name, VVV is the time, and XXX is the accumulated total. After all data is read, print a message of the form
        the final fluid differential is YYY ml
where YYY is the final total. As an example, running your program on the above input will result in the output
        after consuming soup at 15:30, intake exceeds output by 1000 ml
        after consuming coffee at 15:30, intake exceeds output by 1200 ml
        the final fluid differential is 850 ml
You should do some quick addition (by hand) on the above example to confirm these numbers are correct! Some further notes:

Stage 1

We will be consistent about providing multiple stages for assignments. You can receive credit for each stage even if nothing else works. You are advised to complete your solution in stages, but a working solution will pass all stages.

Stage 1 of this assignment is complete when you can read one line of input and print the fluid intake of that one line using the format of the expected final message. You can assume this line is an intake (rather than an output), so you do not need to use if statements or while loops to get this stage working. For example, if the text file contains just the line

        10:30 coffee 175
then the output would be
        the final fluid differential is 175 ml
You can implement this just by reading two strings and an integer and printing the integer in the above format. Test 1 will confirm this case. You can receive 40% credit on this assignment simply by passing test 1.

Stage 2

Extend your solution to process the full input. That is, write an end-of-file controlled loop that reads the data. Remember that the general pattern for such a loop in C++ is

        read
        while ( cin ) {
          process
          read
        }
It is important to read both before the loop header and at the end of the loop. Do not try to have just a single read.

A well-documented bug in CLion (and other JetBrains products) is that there is no way to mark the end of input (that is, no way to generate end-of-file). A simple solution is to set up the run configuration to take the input from a file. With your project open in CLion, click on the three vertical dots next to the debug symbol, select Edit... (for the run configuration), select the Redirect input from box, and browse to a file like 2.in. Then you can run and debug your code as usual with the input coming from this file instead of the console (that is, instead of the keyboard).

Submitting

Common Issues