我需要爲這個℃的答案++的問題,我已經在它的工作,但很明顯,我在想念的東西,我會後我的答案迄今太....功能具有不同的返回類型和parameteres C++
寫計算並打印工資單。
用戶輸入是員工姓名,工作小時數和小時工資率。
你必須聲明三個功能:
1)一個用於輸入;
2)一個用於計算員工工資;和
3)一個打印工資單
用戶必須輸入員工的姓名,工作小時數和小時工資率成變量theEmployee
,theHoursWorked
和thePayRate
。變量employee
是string
,其他兩個變量的類型爲float
。作爲員工的價值觀,小時工和payRate將在此功能中更改,reference parameters need to be used
。
計算功能將接收兩個參數,這兩個參數表示工作小時數和小時工資率,進行計算並返回員工的工資。工作時間超過40小時的員工每小時加班工資的時薪爲工資的1.5倍。由於參數在函數中沒有改變,它們應該是值參數。該函數應該返回代表薪水的float
值。
輸出功能必須顯示員工的姓名,工作的小時數,加班時間的數量和用戶輸入的小時工資率以及員工的工資。對於
例子:
的工資條爲粉紅豹
工時:43.5小時
加班時間:3.5小時
小時工資率:R125.35
收費:R5672.09
主要功能包括一個for循環,允許用戶重複計算五名員工的工資單。
int main()
{
string theEmployee;
float theHoursWorked;
float thePayRate;
int thePay;
for (int i = 0; i < 5; i++)
{
getData(theEmployee, theHoursWorked, thePayRate);
thePay = calculatePay (theEmployee, theHoursWorked, thePayRate);
printPaySlip(theEmployee, theHoursWorked, thePayRate, thePay);
}
return 0;
}
這是什麼他們得到,這是我迄今爲止所做的,我想我正在努力與參考參數?
#include <iostream>
#include <string>
using namespace std;
int getData (string & theEmployee , float & theHoursWorked, float & thePayRate)
{
cout<< "Enter your name and surname: "<< endl;
getline(cin, theEmployee);
cout << "Include the numbers of hours you worked: " << endl;
cin >> theHoursWorked;
cout << "What is your hourly pay rate?" << endl;
cin >> thePayRate;
return theEmployee, theHoursWorked, thePayRate;
}
float calculatePay(string & theEmployee, float & theHoursWorked, float & thePayRate)
{
float tempPay, thePay, overtimeHours;
if (theHoursWorked > 40)
{
tempPay = 40 * thePayRate;
overtimeHours = theHoursWorked - 40;
thePay = tempPay + overtimeHours;}
else
thePay = theHoursWorked * thePayRate;
return thePay;
}
int printPaySlip(string & theEmployee, float & theHoursWorked, float &
thePayRate, float thePay)
{
float overtimeHours;
cout << "Pay slip for " << theEmployee <<endl;
cout << "Hours worked: "<< theHoursWorked << endl;
if (theHoursWorked > 40)
overtimeHours = theHoursWorked - 40;
else
overtimeHours = 0;
cout << "Overtime hours: "<< overtimeHours << endl;
cout << "Hourly pay rate: " << thePayRate << endl;
cout << "Pay: " << thePay << endl;
cout << endl;
}
int main()
{
string theEmployee;
float theHoursWorked;
float thePayRate;
int thePay;
for (int i = 0; i < 5; i++)
{
getData(theEmployee, theHoursWorked, thePayRate);
thePay = calculatePay (theEmployee, theHoursWorked, thePayRate);
printPaySlip(theEmployee, theHoursWorked, thePayRate, thePay);
}
return 0;
}
此外,您並沒有正確計算加班時間的工資率 - 您應該將問題描述的工資率倍數乘以1.5倍,而不是簡單地將其加到工資中。 – riv 2013-04-08 11:40:38