Dado un número básico entero y un grado de carácter que denota el salario básico y el grado de una persona respectivamente, la tarea es encontrar el salario bruto de la persona.
Salario bruto: El salario final calculado después de las adiciones de DA, HRA y otras asignaciones. La fórmula del Salario Bruto se define de la siguiente manera:
Salario bruto = Básico + HRA + DA + Permitir – PF
Aquí, HRA = 20% de Básico
DA = 50% de básico
Permitir = 1700 si grado = ‘A’
Permitir = 1500 si grado = ‘B’
Permitir = 1300 si grado = ‘C’
FP = 11% del básico
Ejemplos:
Entrada: básico = 10000, calificación = ‘A’
Salida: 17600Entrada: básico = 4567, grado = ‘B’
Salida: 8762
Enfoque: La idea es encontrar la asignación sobre la base del grado y luego calcular la HRA, DA y PF sobre la base del salario básico. A continuación se muestra la ilustración del cálculo de HRA, DA y PF:
- HRA: House Rent Allowance es el 20% del salario base:
HRA = Salario Base * 0,20
- DA: La Asignación Diaria es el 50% del salario base:
DA = Salario Base * 0.5
- PF: Caja de Previsión es el 11% del salario base.
FP = Salario Base * 0,11
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to implement // the above approach #include <bits/stdc++.h> using namespace std; // Function to calculate the // salary of the person int computeSalary(int basic, char grade) { int allowance; double hra, da, pf; hra = 0.2 * basic; da = 0.5 * basic; pf = 0.11 * basic; // Condition to compute the // allowance for the person if (grade == 'A') { allowance = 1700; } else if (grade == 'B') { allowance = 1500; } else { allowance = 1300; } int gross; // Calculate gross salary gross = round(basic + hra + da + allowance - pf); return gross; } // Driver Code int main() { int basic = 10000; char grade = 'A'; cout << computeSalary(basic, grade); }
Java
// Java program to implement // the above approach import java.util.*; import java.lang.*; class GFG{ // Function to calculate the // salary of the person static int computeSalary(int basic, char grade) { double allowance; double hra, da, pf; hra = 0.2 * basic; da = 0.5 * basic; pf = 0.11 * basic; // Condition to compute the // allowance for the person if (grade == 'A') { allowance = 1700.0; } else if (grade == 'B') { allowance = 1500.0; } else { allowance = 1300.0; } double gross; // Calculate gross salary gross = Math.round(basic + hra + da + allowance - pf); return (int)gross; } // Driver Code public static void main (String[] args) { int basic = 10000; char grade = 'A'; // Function call System.out.println(computeSalary(basic, grade)); } } // This code is contributed by jana_sayantan
Python3
# Python3 program to implement # the above approach # Function to calculate the # salary of the person def computeSalary( basic, grade): hra = 0.2 * basic da = 0.5 * basic pf = 0.11 * basic # Condition to compute the # allowance for the person if grade == 'A': allowance = 1700.0 elif grade == 'B': allowance = 1500.0 else: allowance = 1300.0; gross = round(basic + hra + da + allowance - pf) return gross # Driver code if __name__ == '__main__': basic = 10000 grade = 'A' # Function call print(computeSalary(basic, grade)); # This code is contributed by jana_sayantan
C#
// C# program to implement // the above approach using System; class GFG{ // Function to calculate the // salary of the person static int computeSalary(int basic, char grade) { double allowance; double hra, da, pf; hra = 0.2 * basic; da = 0.5 * basic; pf = 0.11 * basic; // Condition to compute the // allowance for the person if (grade == 'A') { allowance = 1700.0; } else if (grade == 'B') { allowance = 1500.0; } else { allowance = 1300.0; } double gross; // Calculate gross salary gross = Math.Round(basic + hra + da + allowance - pf); return (int)gross; } // Driver Code public static void Main (String[] args) { int basic = 10000; char grade = 'A'; // Function call Console.WriteLine(computeSalary(basic, grade)); } } // This code is contributed by jana_sayantan
Javascript
<script> // JavaScript program for // the above approach // Function to calculate the // salary of the person function computeSalary(basic, grade) { let allowance; let hra, da, pf; hra = 0.2 * basic; da = 0.5 * basic; pf = 0.11 * basic; // Condition to compute the // allowance for the person if (grade == 'A') { allowance = 1700.0; } else if (grade == 'B') { allowance = 1500.0; } else { allowance = 1300.0; } let gross; // Calculate gross salary gross = Math.round(basic + hra + da + allowance - pf); return gross; } // Driver code let basic = 10000; let grade = 'A'; // Function call document.write(computeSalary(basic, grade)); // This code is contributed by splevel62. </script>
17600
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por sakalkar77 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA