Salary Calculation using Inheritance in C++


A manufacturing company has classified its executives into four levels for the benefit of certain perks. The level and corresponding perks are shown by Table-1 stated below. An executive’s gross salary includes basic pay, house rent allowance at 25% of basic pay and other perks. Income tax is withheld from the salary on a percentage basis, which is explained in the Table-2 stated below. Write a program that will read and executive’s job number, level number, and basic pay and then compute the net salary after withholding income tax.
(সি প্রোগ্রামিং” এর মাধ্যমে একটি নির্মাণ কোম্পানির কর্মচারীদের মোট বেতন তৈরির সোর্সকোড
লিখতে হবে যার শর্তগুলো নিন্মে টেবিল আকারে দেওয়া হয়েছে। প্রোগ্রামটি প্রথমত কোম্পানিতে বর্তমান
নির্বাহীদের চাকুরির আই.ডি.-নং ইউজার এর নিকট থেকে সংগ্রহ করবে এরপর লেভেল-নং এবং সর্বশেষে
মূল বেতন (Basic Salary) নেবে। ইনপুট গুলো নেবার পর আয়কর (income tax
নিয়ম অনুযায়ী কর্তন করা হবে এবং চূড়ান্ত মোট বেতন (net pay) নির্নয় করবে। কোম্পানির 
বেতন দেবার এবং আয়কর কর্তনের নিয়ম নিন্মে টেবিল (Table-1 এবং Table-2) আকারে দেওয়া
হলো ।) 

Table-1:

Level
Perks
Conveyance Allowance
Entertainment Allowance
1
1000
500
2
750
200
3
500
100
4
250
0
 
 
 













Table-2:

Gross Salary
Tax Rate
Gross <= 2000
No tax deduction
2000 < Gross <= 4000
3%
4000 < Gross <= 5000
5%
Gross > 5000
8%

7 comments:

  1. using C++

    #include
    using namespace std;

    class Base
    {
    public:
    int numOfEmp;
    void takeNumOfEmp(int i);
    void printIdLvl(int i);
    void empDetails();
    protected:
    int proNumOfEmp;
    double transEmpData[20][2];
    double basicPay[20];
    };

    void Base::takeNumOfEmp(int i)
    {
    proNumOfEmp = numOfEmp = i;
    }
    void Base::printIdLvl(int i)
    {
    if (i == 0)
    cout << "Enter Employ Id --: ";
    else if (i == 1)
    cout << "Enter Employ Level --: ";
    }
    void Base::empDetails()
    {
    for (int i = 0; i < numOfEmp; i++){
    for (int j = 0; j < 2; j++){
    printIdLvl(j);
    cin >> transEmpData[i][j];
    }
    }

    for (int i = 0; i < numOfEmp; i++){
    cout << "Enter Basic Pay For id " << transEmpData[i][0] << " --: ";
    cin >> basicPay[i];
    }
    }

    class Derive: public Base
    {
    public:
    double perks[4][2] = {{1000, 500}, {750, 200}, {500, 100}, {250, 0}};
    double store[20];
    double home[20];
    void showBasicPay();
    void calculateBill();
    void showPay();
    };

    void Derive::showBasicPay()
    {
    double sum = 0, give;
    for (int i = 0; i < proNumOfEmp; i++){
    sum = basicPay[i];
    give = sum*0.25;
    home[i] = give;
    store[i] = (sum-give);
    }
    }

    void Derive::calculateBill()
    {
    for (int i = 0; i < proNumOfEmp; i++){
    double total = 0;
    if (store[i] <= 2000){
    store[i] = store[i];
    }
    else if (store[i] <= 4000){
    total = store[i]*0.03;
    store[i] = store[i]-total;
    }
    else if (store[i] <= 5000){
    total = store[i]*0.05;
    store[i] = store[i]-total;
    }
    else if (store[i] > 5000){
    total = store[i]*0.08;
    store[i] = store[i]-total;
    }
    }
    }

    void Derive::showPay()
    {
    for (int i = 0; i < proNumOfEmp; i++){
    int sum = 0;
    if (transEmpData[i][1] == 1){
    sum = store[i] + perks[0][0] + perks[0][1] + home[i];
    store[i] = sum;
    }
    else if (transEmpData[i][1] == 2){
    sum = store[i] + perks[1][0] + perks[1][1] + home[i];
    store[i] = sum;
    }
    else if (transEmpData[i][1] == 3){
    sum = store[i] + perks[2][0] + perks[2][1] + home[i];
    store[i] = sum;
    }
    else if (transEmpData[i][1] == 4){
    sum = store[i] + perks[3][0] + perks[3][1] + home[i];
    store[i] = sum;
    }
    }
    for (int i = 0; i < proNumOfEmp; i++){
    cout << "Total payable bill with out TAX for ID " << transEmpData[i][0] << " --: " << store[i] << endl;
    }
    }

    int main()
    {
    Derive object;
    int numOfEmp;
    cout << "Enter how many employ data do you want to Entry --: ";
    cin >> numOfEmp;
    if (numOfEmp > 20)
    cout << "You Can Add Maximum 20 Employs Data --SORRY--.";
    else{
    object.takeNumOfEmp(numOfEmp);
    object.empDetails();
    object.showBasicPay();
    object.calculateBill();
    object.showPay();
    }
    return 0;
    }

    /*

    Taking input how many employs data want to entry.
    Taking Employ ID and LEVEL & store in a array.
    Taking basic salary by given ID & store it in another array.
    Separate home rent and another allowance from the basic salary for all Employ and storing in another array.
    Minus the tax from the bill and reset the array where basic bill stored.
    From the given level set the total amount and also adding the home rent and others.
    Now showing the total bill by given ID.

    */

    ReplyDelete
  2. #include
    using namespace std;

    class hamid
    {
    public:
    int num;
    void takeNumOfEmp(int i)
    {
    proNumOfEmp = i;
    num = i;
    }
    void il(int i)
    {
    if (i == 0)
    cout << "Enter Id ";
    else if (i == 1)
    cout << "Enter Level ";
    }
    void empDetails()
    {
    for (int i = 0; i < num; i++){
    for (int j = 0; j < 2; j++){
    il(j);
    cin >> transEmpData[i][j];
    }
    }

    for (int i = 0; i < num; i++){
    cout << "Enter bill For id " << transEmpData[i][0] << " ";
    cin >> basicPay[i];
    }
    }

    protected:
    int proNumOfEmp;
    double transEmpData[20][2];
    double basicPay[20];
    };

    class hamidTwo: public hamid
    {
    public:
    double perks[4][2] = {{1000, 500}, {750, 200}, {500, 100}, {250, 0}};
    double store[20];
    double home[20];
    void showBasicPay()
    {
    double sum = 0, give;
    for (int i = 0; i < proNumOfEmp; i++){
    sum = basicPay[i];
    give = sum*0.25;
    home[i] = give;
    store[i] = (sum-give);
    }
    }

    void tax()
    {
    for (int i = 0; i < proNumOfEmp; i++){
    double total = 0;
    if (store[i] <= 2000){
    store[i] = store[i];
    }
    else if (store[i] <= 4000){
    total = store[i]*0.03;
    store[i] = store[i]-total;
    }
    else if (store[i] <= 5000){
    total = store[i]*0.05;
    store[i] = store[i]-total;
    }
    else if (store[i] > 5000){
    total = store[i]*0.08;
    store[i] = store[i]-total;
    }
    }
    }

    void showPay()
    {
    for (int i = 0; i < proNumOfEmp; i++){
    int sum = 0;
    if (transEmpData[i][1] == 1){
    sum = store[i] + perks[0][0] + perks[0][1] + home[i];
    store[i] = sum;
    }
    else if (transEmpData[i][1] == 2){
    sum = store[i] + perks[1][0] + perks[1][1] + home[i];
    store[i] = sum;
    }
    else if (transEmpData[i][1] == 3){
    sum = store[i] + perks[2][0] + perks[2][1] + home[i];
    store[i] = sum;
    }
    else if (transEmpData[i][1] == 4){
    sum = store[i] + perks[3][0] + perks[3][1] + home[i];
    store[i] = sum;
    }
    }
    for (int i = 0; i < proNumOfEmp; i++){
    cout << "Total payable bill " << store[i] << endl;
    }
    }
    };

    int main()
    {
    hamidTwo object;
    int i;
    cout << "Enter how many employ data want to Entry ";
    cin >> i;
    object.takeNumOfEmp(i);
    object.empDetails();
    object.showBasicPay();
    object.tax();
    object.showPay();
    return 0;
    }

    ReplyDelete
    Replies
    1. plz do not copy and lose your credit/number

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. #include
      using namespace std;

      class Father
      {
      public:
      int rony(int num4,int num5,int num6)
      {
      num7=num4;
      level=num5;
      num9=num6;
      }
      protected:
      int num7;
      int level;
      int num9;

      };
      class Child :public Father
      {
      public:
      double sum1=0,sum2=0;
      double func()
      {
      if(level==1)
      {
      sum1=num9+(num9*0.25)+500+1000;
      if (sum1<=2000)
      {
      sum2=sum1;
      cout<<"The employee net salary is : "<5000)
      {
      sum2=sum1-(sum1*0.08);
      cout<<"The employee net salary is : "<5000)
      {
      sum2=sum1-(sum1*0.08);
      cout<<"The employee net salary is : "<5000)
      {
      sum2=sum1-(sum1*0.08);
      cout<<"The employee net salary is : "<5000)
      {
      sum2=sum1-(sum1*0.08);
      cout<<"The employee net salary is : "<>num1;
      cout<<"Enter employee level number: ";
      cin>>num2;
      cout<<"Enter employee basic salary: ";
      cin>>num3;
      Child obj;
      obj.rony(num1,num2,num3);
      obj.func();
      return 0;

      }

      Delete
  4. ID : 201620195
    https://www.dropbox.com/s/303dg5ltcvg6ovb/02.cpp?dl=0

    ReplyDelete
    Replies
    1. Polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. Most important thought is hierarchy of classes.

      Delete

Comment Here