📜  计算一个人的总薪金的程序

📅  最后修改于: 2021-04-22 01:50:32             🧑  作者: Mango

给定一个基本整数和一个字符等级,分别表示一个人的基本工资和等级,任务是找到该人的总工资。

工资总额:在加上DA,HRA和其他津贴后得出的最终工资。工资总额的公式定义如下:

例子:

方法:想法是根据等级找到津贴,然后根据基本工资计算HRA,DA和PF。下面是HRA,DA和PF的计算说明:

  • HRA:房屋租金津贴为基本工资的20%:
  • DA:每日津贴是基本工资的50%:
  • PF:公积金是基本工资的11%。

下面是上述方法的实现:

C++
// C++ Program to implement
// the above approach
 
#include 
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


输出:
17600

时间复杂度: O(1)
辅助空间: O(1)