Program to calculate gross salary of a person

16 Apr, 2021
Given an integer basic and a character grade which denotes the basic salary and grade of a person respectively, the task is to find the gross salary of the person.
Gross Salary: The final salary computed after the additions of DA, HRA and other allowances. The formula for Gross Salary is defined as below:
Gross Salary = Basic + HRA + DA + Allow – PFHere, HRA = 20% of Basic DA = 50% of basic Allow = 1700 if grade = ‘A’ Allow = 1500 if grade = ‘B’ Allow = 1300 if grade = ‘C’ PF = 11% of basic
Examples:
Input: basic = 10000, grade = ‘A’Output: 17600
Input: basic = 4567, grade = ‘B’Output: 8762
Approach: The idea is to find the allowance on the basis of the grade and then compute the HRA, DA, and PF on the basis of the basic salary. Below is the illustration of the computation of HRA, DA, and PF:
HRA: House Rent Allowance is 20% of the basic salary:
  
HRA = Basic Salary * 0.20
 
DA: Daily Allowance is the 50% of the basic salary:
  
DA = Basic Salary * 0.5
 
PF: Provident Fund is the 11% of the basic salary.
  
PF = Basic Salary * 0.11
 
Below is the implementation of the above approach:
C++
Java
Python3
C#
Javascript
// C++ Program to implement// the above approach #include <bits/stdc++.h>using namespace std; // Function to calculate the// salary of the personint 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 Codeint main(){    int basic = 10000;    char grade = 'A';     cout << computeSalary(basic, grade);}
// Java program to implement// the above approachimport java.util.*;import java.lang.*; class GFG{ // Function to calculate the// salary of the personstatic 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 Codepublic 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 program to implement# the above approach # Function to calculate the# salary of the persondef 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 codeif __name__ == '__main__':         basic = 10000    grade = 'A'         # Function call    print(computeSalary(basic, grade)); # This code is contributed by jana_sayantan
// C# program to implement// the above approachusing System; class GFG{ // Function to calculate the// salary of the personstatic 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 Codepublic 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
<script> // JavaScript program for// the above approach // Function to calculate the// salary of the personfunction 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
Time Complexity: O(1) Auxiliary Space: O(1) 
jana_sayantan
splevel62
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Algorithm to solve Rubik's Cube
Program to print prime numbers from 1 to N.
Merge two sorted arrays with O(1) extra space
Segment Tree | Set 1 (Sum of given range)
Fizz Buzz Implementation
Python Dictionary
Reverse a string in Java
Arrays in C/C++
Introduction To PYTHON
Interfaces in Java