Using the user define functions C++ Program to take a value from the user as input electricity unit charges and calculate total electricity bill according to the given condition: 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 unit above 250 Rs. 1.50/unit………An additional surcharge of 20% is added to the bill…….Using user define functions.

Explanation:

  1. 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.
  2. Pass-by-Reference (calculateBillByReference):
    • Function Definition: void calculateBillByReference(double units, double &totalBill)
    • This function also receives the units but takes a reference to totalBill to store the result.
    • It performs the same calculations as calculateBillByValue but updates the totalBill variable directly.
    • An additional surcharge of 20% is applied to the calculated bill.
  3. 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: