Objective: The goal of this assignment is to refresh your memory of 1-dimensional arrays, in preparation for the following lab on multi-dimensional arrays.
Assignment: A gas station is planning to run an advertising campaign where it will distribute coupons for cheaper gasoline. The station will only distribute these coupons during the hour of the day when it has the highest revenue (i.e., the largest value of the gasoline sold). The gas station needs your help to identify the hour of the day that it will run its campaign.
In each transaction, we record the time (in hours, 0, 1, ..., 23) and the amount of gas sold. To store all this information, we will use two one-dimensional arrays:
Assume that the data is stored in a file, each transaction in a separate line.
Example. Assume that we had 3 transactions, $10.00 worth sold at 1 am, $5.20 sold at 1 pm (13 hrs), and $3.90 sold at 1 pm. In this case, the input file is as follows:
1 10.00 13 5.20 13 3.90Then, the first array will have the values 1, 13, and 13, and the second array will have the values 10.00, 5.20, and 3.90. This means that:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 0 10.00 0 0 0 0 0 0 0 0 0 0 0 9.10 0 0 0 0 0 0 0 0 0 0Thus, the hour with the largest sales is 1 hr.
For extra credit: Modify your program taking into account that in real life, the the price of the gallon can change during the day, and so, the gas station may want to select the hour when its profit is the largest, i.e., the difference between its revenue and what it paid for the gas. For that, let us assume that each transaction also stores the amount of gas sold (in gallons). We assume that we are given the price (e.g., $2.00 per gallon) that the station paid for the gas. Then, the profit of each transaction can be computed as the difference between the price paid by the customer and the price paid by the gas station.
For example, if at 1 am, the customer paid $10.00 for 3.8 gallons, and the station paid $2.00 per gallon, then the station's profit for this transaction is $10.00 - 3.8 * $2.00 = $10.00 - $7.60 = $2.40.
In this case, we need two additional arrays: to store the amount of gas per transaction, and to store the profit per transaction.
Deliverables: Your TA will instruct you.