The Problem
A client is interested in exactly what percentage of the time her air conditioning is running. One way to measure this is to keep a temperature logging device right by an AC vent. The device measures the temperature every 30 seconds. If the temperature drops at least .5 degrees Fahrenheit between readings, it’s a good bet that the AC unit just turned on. Likewise, if the temperature rises at least .5 degrees Fahrenheit between readings it’s likely that the AC unit just turned off. (For example, if the reading at 1:30:00pm was 74.7 degrees F and the reading at 1:30:30pm was 74.1 degrees F, then we would assume for the 30 seconds starting at 1:30:00pm and ending at 1:30:30pm, the AC was on. If there is no big rise or fall in a 30 second interval, we assume the state of the AC was whatever it was in the previous 30 second interval. We will assume that the AC is always off at midnight.
You will be given the temperature readings from one logging device for a whole day (24 hours). Using this information, you must calculate the percentage of time the air was on for the day and produce a bar graph with houry data.
Input File Format (temp.txt)
This file will have exactly 2881 doubles, one per line, indicating readings of temperatures (in Fahrenheit) starting at midnight and ending at midnight the next day. The readings are taken every 30 seconds. The start of a file might look like this:
78.6
78.6
78.5
78.5
The Output
First, output a line with the following format:
The AC was running X percent of the time.
where X is a percentage rounded to 2 decimal places, corresponding to how often the AC was running throughout the whole day.
After this line of output, skip a blank line and output a bar graph with a similar format to the one in the posted file.
Each bar corresponds to the percent of time the AC was running during that hour. Since the bars are shown with 5% increments, only display a star if the percentage for that hour equals or exceeds the marked percentage. Here’s the basic idea in how to create it.
First, store the data in an array of size 24, where each entry indicates the percentage of time the AC was running in that hour. (For example, the entry in index 0 stands for the amount of time the AC was running from midnight to 1 am.)
Now, print each row in order, first the row for 100%, then 95%, then 90%, etc. all the way down to 5%. While you are printing a row, for each column, you must ask yourself the question,