#C4014. Billing System
Billing System
Billing System
You are required to implement a billing system that manages services and customers. The system must be able to add new services with a certain rate per unit, register customers, record the usage of services, and calculate the customer bills.
The total bill for a customer is computed using the formula: \( bill = \sum_{i} (rate_{i} \times units_{i}) \), where each service's cost is the product of its rate and the number of units used.
The system should read a sequence of commands from the standard input (stdin) and print outputs (stdout) accordingly.
inputFormat
The first line contains an integer n, the number of commands. The following n lines each contain a command. Each command will be in one of the following formats:
add_service <service_name> <rate_per_unit>
: Adds a new service with the given name and rate (a floating point number).register_customer <customer_name>
: Registers a new customer with the given name.record_usage <customer_name> <service_name> <units_used>
: Records the usage (an integer) of a specified service by the customer. If the service or customer does not exist, an error will be output and the program terminates.calculate_bill <customer_name>
: Calculates and prints the total bill for the given customer. If the customer does not exist, an error message is printed and the program terminates.
Commands are read from stdin.
outputFormat
For each calculate_bill
command, output a single line with the total bill for the specified customer. In case of an error (such as service or customer not existing), output the appropriate error message (Error: Service not found
or Error: Customer not found
) and terminate the program immediately.
6
add_service Internet 10.0
add_service Electricity 0.2
register_customer Alice
record_usage Alice Internet 5
record_usage Alice Electricity 100
calculate_bill Alice
70.0
</p>