このC ++の質問に対する回答が必要です。私はそれに取り組んでいますが、明らかに何かが欠けているので、これまでの回答も投稿します....
給与明細を計算して印刷するプログラムを作成します。
ユーザー入力は、従業員の名前、勤務時間数、および時給です。
次の 3 つの関数を宣言する必要があります。
1) 入力用。
2) 従業員の給与を計算するもの。と
3) 給与明細を印刷する人
theEmployee
ユーザーは、従業員の名前、勤務時間数、および時給を変数theHoursWorked
およびに入力する必要がありthePayRate
ます。変数employee
は astring
で、他の 2 つの変数は型float
です。theEmployee、theHoursWorked、thePayRate の値がこの関数で変更されるため、reference parameters need to be used
.
計算関数は、勤務時間数と時給を表す 2 つのパラメーターを受け取り、計算を行い、従業員の給与を返します。40 時間を超えて働いた従業員には、残業 1 時間ごとに時給の 1.5 倍の賃金が支払われます。パラメータは関数内で変更されないため、値パラメータにする必要があります。float
この関数は、支払いを表す値を返す必要があります。
出力関数は、従業員の名前、労働時間数、残業時間数、ユーザーが入力した時給、および従業員の給与を表示する必要があります。為に
例:
ピンクパンサーの給与明細
労働時間:43.5時間
残業時間:3.5時間
時給: R125.35
支払う: R5672.09
メイン関数には、ユーザーが 5 人の従業員の給与明細の計算を繰り返すことができる 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;
}