我需要为这个℃的答案++的问题,我已经在它的工作,但很明显,我在想念的东西,我会后我的答案迄今太....功能具有不同的返回类型和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