A cell phone provider charges customers $45.00 a month for up to 10 GBytes of data usage. Additional data usages is $5.00 per GB. Any amount over the 10 GB limit will charge at least $5.00, and all additional data charges are in $5.00 increments. So, if someone used 11.2 GB of data they would be charged for 12 GB of data usage.
Write a function 'charges' that computes the total charge for a customer based on the GB of data the user uses per month. The function should also calculate the average cost per MByte of data (rounded to the nearest cent). Pass the needed information to the 'charges' function and return the results by reference (that is using a pointers).
Write a second function 'user_data_read' that takes as reference a file pointer to the file usage.txt , reads in the user data and stores the data by reference into the location of a variable that the main function can use. Then write a third function 'user_data_write' (this function should be called from main) that prints the customer data to a file charges.txt. All data should be passed by reference to 'user_data_write'. Your program should be capable of reading in at least 1000 different customers from one file.
The data file format is as follows:
Line 1: current month and year as two integers
Other lines: customer number (a 5-digit number) and GB's used
Here is a sample of the data file and the corresponding output file:
usage.txt
10 2009
15362 4.2
42768 11.1
12352 12.9
charges.txt
Customer Data Usage (GBs) Total Cost ($) Cost per MB ($/MB)
15362 4.2 45.0 0.0045
42768 11.1 ................................ (and so on)