Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Functions you will write double calculate _ bill ( char * in _ file, char * customer ) ; This function will open the file
Functions you will write
double calculatebillchar infile, char customer;
This function will open the file named in file, read the data, and calculate and return the
bill of the customer specified by customer. In case of errors, your function should return an
appropriate error code as described in section
The formula to calculate the bill b per row is given by
b n s x t
where n is the network usage in megabytes, s is the storage usage in blocks, x is the number of
servers used, and t is the number of hours the service is run. The bill is simply the sum of the
bills of each relevant row.
For example, for the input file
Science
Engineering
Science
for customer Science, the total bill is
int generatenetworkusagereport
char infile, char customer int year, char outfile
;
This function will open the file named in file, read the data, generate a monthly report for
the customer specified by customer for the year given by year, and output it to the file named
out file. Your function should return an appropriate error code as described in section
The format of the output is given below:
:
:
:
:
For example, for the input file
Science
Engineering
Science
Science
Science
Page
Homework CS Spring
Science
Science
Science
Science
Science
Science
Science
for customer Science and year the output should be
Science
:
:
:
:
:
:
:
:
:
:
:
:
int getstorageusagechar infile, char customer int year;
This function will open the file named in file, read the data, and calculate and return the
sum of storage used in megabytes for the customer specified by customer for the year given by
year. In case of errors, your function should return an appropriate error code as described in
section
int getnetworkusagechar infile, int month, int year;
This function will open the file named in file, read the data, and calculate and return the
sum of network used in megabytes for the specified month and year. In case of errors, your
function should return an appropriate error code as described in section
Note: Make sure to return the appropriate error code right away if an argument is invalid.
Input Files
Each input file will contain the compute, network, and storage usage information for all customers
on certain dates. The files will be formatted as follows:
mmddyyyycollegenumserverhoursnetworkbytesblocks
mmddyyyycollegenumserverhoursnetworkbytesblocks
mm int Month of the record. Must be between and both inclusive.
dd int Day of the record. Must be between and both inclusive.
yyyy int Year of the record. Must be nonnegative.
Page
Homework CS Spring
college char MAX ID LENGTH : The Purdue college customer
num server int : Number of servers run by the customer. Must be nonnegative.
hours float : Number of hours that the customer ran their service. Must be nonnegative.
network int : Total amount of network consumed in megabytes. Must be nonnegative.
bytes int : Total amount of storage consumed in megabytes. Must be nonnegative.
blocks int : Total amount of storage consumed in SSD blocks. Must be nonnegative.
Header Files
We provide a header file, hwh for you. It contains prototypes for each of the functions that you
will write as well as #defines for the constants. You should not alter this file. We will replace it
with the original when grading.
Error Codes
SUCCESS: Indicates a successful execution.
FILE READ ERR: Indicates that a file cannot be opened for reading.
FILE WRITE ERR: Indicates that a file cannot be opened for writing.
BAD RECORD: Indicates unexpected characters or fields, or the wrong data type in a record.
Use for all invalid entries other than date use BAD DATE for that instead
BAD DATE: Indicates that a date is invalid or that a date argument passed as an input to a
function is invalid. You may assume that any date with the month between and both
inclusive the day between and both inclusive and the year nonnegative is valid.
NO DATA POINTS: Indicates that the function would operate on no data. This includes if an
input file itself has no data or for functions that take in arguments, if a file does not have
any data for the specified argument combination.
you should just use
fopen fscanf and fprintf
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started