Practice

BiMeter

Meter

Design and code a class named Meter that holds information about the hydro-electric energy used by a household.  Upon instantiation, a Meter object receives

• an integer holding an account number,
• a floating-point number holding the basic charge rate per kilowatt-hour,
• a floating-point number holding the excess charge rate per kilowatt-hour and
• an integer holding the threshold number of kilowatt-hours to which the basic charge rate applies and from which the excess charge rate applies.
The object initializes itself to no accumulated charges.  If the object receives an invalid value for any parameter, the object assumes a safe empty state.

• void record(double) - a modifier that receives the kilowatt-hours used since the last recording and accounts for this value.  If the value received is invalid, this modifier ignores the value altogether.
• double charge() - a modifier that returns the accumulated charge recorded since the last initialization and re-initializes the accumulated charge to zero.
• double excess() const - a query that returns the number of accumulated kilowatt-hours in excess of the threshold.
• double excessRate() const - a query that returns the charge rate that applies to kilowatt-hours in excess of the threshold.
• double basicRate() const - a query that returns the charge rate that applies to kilowatt-hours within the threshold.
• an insertion operator that inserts the account number, the kilowatt hours used and the accumulate charge into an output stream in the format shown below.
For example, consider the following program that uses your class and produces the output on the right side
 ``` #include using namespace std; #include "Meter.h" int main ( ) { double payable; Meter m(4538, 0.047, 0.055, 750); m.record(600); cout << m << endl; m.record(250); cout << m << endl; payable = m.charge(); cout << "To be paid \$" << payable << endl; cout << m << endl; return 0; } ``` ``` 4538 600 kwh \$ 28.20 4538 850 kwh \$ 40.75 To be paid \$40.75 4538 0 kwh \$ 0.00 ```

BiMeter

Derive from Meter a class named BiMeter that holds information about the hydro-electric energy used and supplied by a household.  Sources of supply to the hydro-electric grid may include solar panels, windmills and other alternative energy devices.  Upon instantiation, a BiMeter object receives

• an integer holding an account number,
• a floating-point number holding the basic charge rate per kilowatt-hour,
• a floating-point number holding the excess charge rate per kilowatt-hour,
• an integer holding the maximum number of kilowatt-hours to which the basic charge rate applies and from which the excess charge rate applies,
• a floating-point number holding the discount factor to be applied to energy sources in calculating deductions and
• a null-terminated C-style string holding the name of the supplier.
The discount factor only applies to the energy supplied by the household to the hydro-electric grid.  The object initializes itself to no accumulated charges and no deductions.  If the object receives an invalid value for any parameter, the object assumes a safe empty state.  Your class does not impose any limitation upon the size of the string holding the name of the supplier.

In calculating the deductions, your class first applies the excess rate to the kilowatt-hours supplied by the household up to a maximum that is the number of excess kilowatt-hours used and then applies the basic rate to the remaining kilowatt-hours.

• void record(double) - a modifier that receives the kilowatt-hours exchanged since the last recording and accounts for this value.  If the value is positive, this modifier interprets the process as energy supplied by the grid.  If the value is negative, this modifier interprets the exchange as energy supplied to the grid.
• double charge() - a modifier that returns the accumulated charge less the accumulated deduction recorded since the last initialization and re-initializes both the accumulated charge and the accumulated deduction to zero.
• an insertion operator that inserts the account number, the kilowatt usage, the accumulated charge, the kilowatts supplied to the grid and the net accumulated charge after subtracting the accumulated deduction into an output stream in the format shown below.
For example, consider the following program that uses your class and produces the output on the right side
 ``` #include using namespace std; #include "BiMeter.h" int main ( ) { double payable; BiMeter m(4538, 0.047, 0.055, 750, 0.5, "Fred Fox"); m.record(600); cout << m << endl; m.record(250); cout << m << endl; m.record(-50); cout << m << endl; payable = m.charge(); cout << "To be paid \$" << payable << endl; cout << m << endl; return 0; } ``` ``` 4538 600 kwh \$ 28.20 less 0 kwh \$ 28.20 Fred Fox 4538 850 kwh \$ 40.75 less 0 kwh \$ 40.75 Fred Fox 4538 850 kwh \$ 40.75 less 50 kwh \$ 39.38 Fred Fox To be paid \$39.375 4538 0 kwh \$ 0.00 less 0 kwh \$ 0.00 Fred Fox ```