Q#1: How is the information about employees’ gross salaries obtained in the program, and what is the role of the numEmps variable?
Answer: The program obtains employees’ gross salaries through a function that inputs the values. The numEmps variable, entered by the user, represents the total number of employees. It determines the size of the array used to store gross salaries, ensuring the correct number of salaries is input.
Q#2: Explain the process of calculating net salaries in the program. How are tax deductions applied based on different salary brackets?
Answer: Net salaries are calculated by a function that applies tax deductions according to salary brackets. For each gross salary, a corresponding percentage of tax is deducted depending on the bracket:
- 0–5000
- 5001–10000
- 10001–20000
- 20001 and above
The resulting net salary is computed after applying the appropriate deduction.
Q#3: What is the significance of the lucky array, and how is it used to identify unlucky employees in the program?
Answer: The lucky array is used to identify “unlucky” employees. A function marks employees as unlucky if their net salary is equal to or higher than others in a lower tax bracket. The lucky array stores this information and is later used to print the employee numbers of those identified as unlucky.
Q#4: Explain the concept of passing parameters by reference and by value in the context of the sal array and the numEmps variable.
Answer:
- The
salarray is passed by reference to functions likecalcNetSal, so any changes inside these functions directly modify the original array. - The
numEmpsvariable is passed by value to the input function, meaning changes made to it inside the function do not affect the original variable inmain. This ensures global array updates while keepingnumEmpsunchanged outside the function.