C PROGRAM TO INPUT THE BASIC SALARY OF AN EMPLOYEE AND CALCULATE ITS GROSS SALARY BY USING THE IF-ELSE STATEMENT – Salary Program

Explanation

1. Pass-by-Value (calculateGrossSalaryByValue Function)

  • Definition:


    • Parameters: Takes the basic salary as input by value.
    • Operation:
      • The function calculates the House Rent Allowance (HRA) and Dearness Allowance (DA) based on the basic salary using an if-else statement:
        • If the basic salary is less than 10,000, HRA is 20% of the basic salary, and DA is 80%.
        • Otherwise, HRA is 25%, and DA is 90%.
      • The gross salary is calculated as the sum of the basic salary, HRA, and DA.
      • Displays the basic salary, HRA, DA, and gross salary inside the function.
    • Effect:
      • Since the function uses pass-by-value, the original basicSalary variable in main remains unchanged after the function call.

2. Pass-by-Reference (calculateGrossSalaryByReference Function)

  • Definition:


    • Parameters:
      • basicSalary: The basic salary of the employee.
      • grossSalary: A reference to a double variable that stores the gross salary.
    • Operation:
      • The function calculates HRA and DA similarly to the pass-by-value function.
      • The gross salary is calculated and assigned to the grossSalary variable.
      • Displays the basic salary, HRA, DA, and gross salary inside the function.
    • Effect:
      • Since the function uses pass-by-reference, the grossSalary variable is directly updated with the calculated gross salary after the function call.

Sample Output:

Key Points

  • Gross Salary Calculation:
    • The gross salary is the sum of the basic salary, House Rent Allowance (HRA), and Dearness Allowance (DA).
    • The HRA and DA are calculated based on conditions:
      • If the basic salary is less than 10,000:
        • HRA = 20% of the basic salary
        • DA = 80% of the basic salary
      • Otherwise:
        • HRA = 25% of the basic salary
        • DA = 90% of the basic salary
  • Pass-by-Value:
    • The function receives a copy of the actual argument.
    • Changes made inside the function do not affect the original variable.
  • Pass-by-Reference:
    • The function receives a reference (alias) to the actual argument.
    • The grossSalary variable is directly modified based on the calculations inside the function.
  • If-Else Statement:
    • The if-else statement is used to control the calculation of HRA and DA based on the basic salary.