C++ Program to take a value from the user as input the basic salary of an employee and calculate its Gross salary according to the following: Basic Salary <= 10000: HRA = 20%, DA = 80%………………………………..Basic Salary <= 20000 : HRA = 25%, DA = 90%………………………………Basic Salary > 20000 : HRA = 30%, DA = 95%.

Explanation:

  1. Pass-by-Value (calculateGrossSalaryByValue):
    • Function Definition: double calculateGrossSalaryByValue(double basicSalary)
    • This function receives a copy of the basicSalary.
    • It calculates the HRA (House Rent Allowance) and DA (Dearness Allowance) based on the salary brackets:
      • <= 10000: HRA = 20%, DA = 80%
      • <= 20000: HRA = 25%, DA = 90%
      • > 20000: HRA = 30%, DA = 95%
    • It then computes the gross salary and returns it.
  2. Pass-by-Reference (calculateGrossSalaryByReference):
    • Function Definition: void calculateGrossSalaryByReference(double basicSalary, double &grossSalary)
    • This function receives the basicSalary and a reference to grossSalary.
    • It calculates the HRA and DA similarly but stores the result directly in the grossSalary reference.
    • The grossSalary variable in the main function is updated with the computed value.
  3. Main Function (main):
    • The program prompts the user to input the basic salary.
    • It calculates the gross salary using both methods and prints the results.

Example Outputs:

Example 1:

Input:

  • Basic Salary: 12000

Output:

Example 2:

Input:

  • Basic Salary: 25000

Output:

Example 3:

Input:

  • Basic Salary: 9000

Output: