Answered step by step
Verified Expert Solution
Link Copied!

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 calculate_bill(char *in_file, 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 4.4.
The formula to calculate the bill b per row is given by
b =0.01 n +0.02 s +0.06 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
01/01/2000|Science|5|3.3|71|2/6
01/01/2000|Engineering|1|1.3|25|1/3
01/02/2000|Science|7|1.5|97|4/15
for customer Science, the total bill is 3.72.
int generate_network_usage_report(
char *in_file, char *customer, int year, char *out_file
);
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 4.4.
The format of the output is given below:
01:
02:
03:
...
12:
For example, for the input file
01/01/2000|Science|5|3.3|71|2/6
01/01/2000|Engineering|1|1.3|25|1/3
01/02/2000|Science|7|1.5|97|4/15
02/02/2000|Science|7|1.5|54|4/15
03/02/2000|Science|7|1.5|61|4/15
Page 3
Homework 2 CS 240- Spring 2024
04/02/2000|Science|7|1.5|30|4/15
05/02/2000|Science|7|1.5|19|4/15
06/02/2000|Science|7|1.5|59|4/15
07/02/2000|Science|7|1.5|49|4/15
08/02/2000|Science|7|1.5|83|4/15
09/02/2000|Science|7|1.5|73|4/15
10/02/2000|Science|7|1.5|0|4/15
for customer Science and year 2000, the output should be
Science
01:168
02:54
03:61
04:30
05:19
06:59
07:49
08:83
09:73
10:0
11:0
12:0
2000
int get_storage_usage(char *in_file, 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 4.4.
int get_network_usage(char *in_file, 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 4.4.
Note: Make sure to return the appropriate error code right away if an argument is invalid.
4.2 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:
mm/dd/yyyy|college|num_server|hours|network|bytes/blocks
mm/dd/yyyy|college|num_server|hours|network|bytes/blocks
...
mm (int)- Month of the record. Must be between 1 and 12, both inclusive.
dd (int)- Day of the record. Must be between 1 and 30, both inclusive.
yyyy (int)- Year of the record. Must be non-negative.
Page 4
Homework 2 CS 240- Spring 2024
college (char [MAX ID LENGTH]) : The Purdue college (customer).
num server (int) : Number of servers run by the customer. Must be non-negative.
hours (float) : Number of hours that the customer ran their service. Must be non-negative.
network (int) : Total amount of network consumed in megabytes. Must be non-negative.
bytes (int) : Total amount of storage consumed in megabytes. Must be non-negative.
blocks (int) : Total amount of storage consumed in SSD blocks. Must be non-negative.
4.3 Header Files
We provide a header file, hw2.h, 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.
4.4 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 1 and 12(both
inclusive), the day between 1 and 30(both inclusive), and the year non-negative 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() and program in C language

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

IBM Db2 11 1 Certification Guide Explore Techniques To Master Database Programming And Administration Tasks In IBM Db2

Authors: Mohankumar Saraswatipura ,Robert Collins

1st Edition

1788626915, 978-1788626910

More Books

Students also viewed these Databases questions

Question

analysis of ir, provide significant infromation

Answered: 1 week ago

Question

What is electric dipole explain with example

Answered: 1 week ago