我需要这个 C++ 问题的答案,我已经解决了,但显然我错过了一些东西,到目前为止我也会发布我的答案......
编写一个程序来计算和打印工资单。
用户输入的是员工姓名、工作小时数和小时工资率。
您必须声明三个函数:
1) 一个用于输入;
2) 一、计算员工工资;和
3)一张打印工资单
用户必须在变量和中输入员工姓名theEmployee
、工作小时数和小时工资率。变量是 a ,其他两个变量的类型是。由于 theEmployee、theHoursWorked 和 thePayRate 的值将在此函数中更改,.theHoursWorked
thePayRate
employee
string
float
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;
}