Explanation:
- Pass-by-Value (
calculateBillByValue
):- Function Definition:
double calculateBillByValue(double units)
- This function receives a copy of the
units
as input. - It calculates the electricity bill based on the given unit rates:
- For the first 50 units: Rs. 0.50/unit
- For the next 100 units: Rs. 0.75/unit
- For the next 100 units: Rs. 1.20/unit
- For units above 250: Rs. 1.50/unit
- An additional surcharge of 20% is applied to the calculated bill.
- The function returns the final bill amount.
- Function Definition:
- Pass-by-Reference (
calculateBillByReference
):- Function Definition:
void calculateBillByReference(double units, double &totalBill)
- This function also receives the
units
but takes a reference tototalBill
to store the result. - It performs the same calculations as
calculateBillByValue
but updates thetotalBill
variable directly. - An additional surcharge of 20% is applied to the calculated bill.
- Function Definition:
- Main Function (
main
):- The program prompts the user to input the number of electricity units.
- It calculates the total bill using both methods and prints the results.
Example Outputs:
Example 1:
Input:
- Units:
120
Output:
Example 2:
Input:
- Units:
300
Output:
Example 3:
Input:
- Units:
80
Output: