promotion image of download ymail app
Promoted
匿名使用者
匿名使用者 發問時間: 電腦與網際網路程式設計 · 1 0 年前

c++ 程式範例

請問一下這題是否有人願意幫忙解釋以及提供程式碼幫幫我?

An employee is paid at a rate of $16.78 per hour for regular hours worked in a week.Any hours over that are paid at the overtime rate of one and one-half times that.From the worker's gross pay,6% is withheld for Social Security tax,14% is withheld for federal income tax, 5% is withheld for state income tax, and $10 per week is withheld for union dues. If the worker has three or more dependents, then an additional $35 is withheld to cover the extra cost of health insurance beyond what the employer pays. Write ap program that will read in the number of hours ouput the worker's gross pay, each withholding amount,and the net take-home pay for the week.

1 個解答

評分
  • 最佳解答

    題意大概是這樣:

    員工的時薪是16.78元, 超時加班的時薪是1.5倍

    總收入的6%是 Social Security tax,

    總收入的14%是federal income tax,

    總收入的5%是state income tax,

    一週10元是union dues,

    若有3個以上的扶養親屬, 則要多扣35元.

    題目要你寫個程式, 可以輸入一週工作時數, 輸出總收入, 各項稅額和淨收入是多少.

    我程式預設每週基本工時是84小時, 同時也會問你扶養親屬有多少人..

    #include "stdafx.h"

    #include <iostream>

    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])

    {

    double fSalaryPerHour = 16.78;

    int iBaseWorkingHours = 84;

    double fUnionDues = 10;

    double ExtraHealthInsurance = 35;

    double fIncome = 0;

    double fGrossIncome = 0;

    double fNetIncome = 0;

    int iWorkingHours = 0;

    int iDependent = 0;

    double fSocialSecurityTax = 0;

    double fFederalIncomeTax = 0;

    double fStateIncomeTax = 0;

    cout << "請輸本週入工作時數 : ";

    cin >> iWorkingHours;

    cout << "\n請輸入扶養親屬人數:";

    cin >> iDependent;

    if(iWorkingHours <= 84)

    fGrossIncome = fSalaryPerHour * iWorkingHours;

    else

    {

    fGrossIncome = (iWorkingHours - 84)*1.5*fSalaryPerHour + iBaseWorkingHours*fSalaryPerHour;

    }

    cout << "\n本週總收入為 : " << fGrossIncome;

    fSocialSecurityTax = fGrossIncome*0.06;

    cout << "\nSocial Security Tax : " << fSocialSecurityTax;

    fFederalIncomeTax = fGrossIncome*0.14;

    cout << "\nFederal Income Tax : " << fFederalIncomeTax;

    fStateIncomeTax = fGrossIncome*0.05;

    cout << "\nState Income Tax : " << fStateIncomeTax;

    fNetIncome = fGrossIncome - fSocialSecurityTax - fFederalIncomeTax - fStateIncomeTax - fUnionDues;

    if(iDependent>=3)

    fNetIncome-=ExtraHealthInsurance;

    cout << "\n本週淨收入為 : " << fNetIncome;

    return 0;

    }

    參考資料:
    • Commenter avatar登入以對解答發表意見
還有問題?馬上發問,尋求解答。