具有不同返回类型和参数C++; 我需要一个答案来回答这个C++问题,我已经研究过了,但显然我缺少了一些东西,我也会把答案公布在……
编写一个计算和打印工资单的程序 用户输入的内容包括员工姓名、工作小时数和小时工资率 您必须声明三个函数: 1) 一个用于输入 2) 一是计算员工工资;及 3) 一个人来打印工资单 用户必须将员工姓名、工作小时数和小时工资率输入变量具有不同返回类型和参数C++; 我需要一个答案来回答这个C++问题,我已经研究过了,但显然我缺少了一些东西,我也会把答案公布在……,c++,function,types,parameters,return,C++,Function,Types,Parameters,Return,编写一个计算和打印工资单的程序 用户输入的内容包括员工姓名、工作小时数和小时工资率 您必须声明三个函数: 1) 一个用于输入 2) 一是计算员工工资;及 3) 一个人来打印工资单 用户必须将员工姓名、工作小时数和小时工资率输入变量员工、工作小时数和工资率。变量employee是一个字符串,另外两个变量的类型为float。由于员工的值、工作时间和工资率将在此函数中更改,因此需要使用参考参数 计算功能将接收表示工作小时数和小时工资率的两个参数,进行计算并返回员工的工资。工作时间超过40小时的员工每加
员工
、工作小时数
和工资率
。变量employee
是一个字符串
,另外两个变量的类型为float
。由于员工的值、工作时间和工资率将在此函数中更改,因此需要使用参考参数
计算功能将接收表示工作小时数和小时工资率的两个参数,进行计算并返回员工的工资。工作时间超过40小时的员工每加班一小时的工资为小时工资的1.5倍。由于参数在函数中没有更改,因此它们应该是值参数。该函数应返回一个表示薪资的浮动值
输出功能必须显示员工姓名、工作小时数、加班小时数和用户输入的小时工资率以及员工的工资。为了
例如:
粉红豹的工资单
工作时间:43.5小时
加班时间:3.5小时
小时工资率:125.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;
}
intmain()
{
用绳子拴住雇员;
工作时间的浮动;
浮动工资;
填妥该页;
对于(int i=0;i<5;i++)
{
获取数据(员工、工作时间、工资率);
工资=计算工资(员工、工作时间、工资率);
打印工资单(员工、工作时间、工资率、工资);
}
返回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;
}
#包括
#包括
使用名称空间std;
int getData(字符串和员工、浮动和工时、浮动和工资率)
{
cout不需要在getData函数中返回。这应该可以工作
void 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;
}
void getData(字符串和员工、浮动和工时、浮动和工资率)
{
cout
。有关说明,请参阅。首先,getData
和printPaySlip
函数不应返回任何内容-返回类型应从int
更改为void
第二,行>代码>返回雇员,HelsWork,PayRe>/Cuff>是一个错误,应该被删除——C++不允许多个返回值,而使用引用参数代替。这意味着该函数允许修改其参数。您已经正确读取了它,因此只需删除<代码>返回< /代码>行。< /P>
第三,
calculatePay
和printPaySlip
函数不需要引用,因为它们不修改参数。甚至问题陈述也说它们应该取值,所以只需删除和
第四,您的calculatePay
函数计算加班时间的费率不正确-它只是将加班时间的金额添加到总工资中,而没有将其乘以工资*1.5此外,您没有正确计算加班时间的工资率-您应该将加班时间的乘以工资率正如问题所述,乘以1.5,而不是简单地将其添加到支付中。另外,函数printPaySlip
应返回void。您好,非常感谢您提供的信息反馈,但它仍然不允许我输入第二轮名称和内容,如果您编译并运行它,您将看到!我不明白。之后,您将执行第一轮值(正如我在回答中所说的@user2257336,这是因为你将getline与>>混合在一起。这个问题在这里被问了数百次。我无法回答比所有已经给出的答案更好的问题。看看我上面发布的链接。