gpt4 book ai didi

java - 最后没有显示员工摘要的问题

转载 作者:行者123 更新时间:2023-11-30 02:50:26 25 4
gpt4 key购买 nike

我一切正常,当我在上交之前去检查它时,有些东西搞砸了,最后我无法让它运行员工摘要。有人可以指导我到这里缺少的部分吗?我还不断收到 3 条警告 C$@$$ "="从 double 到 float 的转换可能会丢失数据?第 99、101 和 109 行?:

    // ConsoleApplication29.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

//
//CLASS DECLARATION SECTION
//
class EmployeeClass
{
public:
void ImplementCalculations(string EmployeeName, int hours, double wage);
void DisplayEmployInformation(void);
void Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2, EmployeeClass Emp3);
string EmployeeName ;
int hours ;
float wage ;
float basepay ;
int overtime_hours ;
float overtime_pay ;
float overtime_extra ;
float iTotal_salaries ;
float iIndividualSalary ;
int iTotal_hours ;
int iTotal_OvertimeHours ;
};

int main()
{ system("cls");

cout << "\nWelcome to the Employee Pay Center\n\n" ;

EmployeeClass Emp1;
EmployeeClass Emp2;
EmployeeClass Emp3;


cout << "Enter the first employee's name = ";
cin >> Emp1.EmployeeName;
cout << "\nEnter the hours worked = ";
cin >> Emp1.hours;
cout << "\nEnter their hourly wage = ";
cin >> Emp1.wage;
cout << endl;

cout << "Enter the second employee's name = ";
cin >> Emp2.EmployeeName;
cout << "\nEnter the hours worked = ";
cin >> Emp2.hours;
cout << "\nEnter their hourly wage = ";
cin >> Emp2.wage;
cout << endl;

cout << "Enter the third employee's name = ";
cin >> Emp3.EmployeeName;
cout << "\nEnter the hours worked = ";
cin >> Emp3.hours;
cout << "\nEnter their hourly wage = ";
cin >> Emp3.wage;


cout << endl;
Emp1.ImplementCalculations(Emp1.EmployeeName, Emp1.hours, Emp1.wage);
Emp2.ImplementCalculations(Emp2.EmployeeName, Emp2.hours, Emp2.wage);
Emp3.ImplementCalculations(Emp3.EmployeeName, Emp3.hours, Emp3.wage);


system ("pause");
return 0;


//This section you will send all three objects to a function that will add up the the following information:
//- Total Employee Salaries
//- Total Employee Hours
//- Total Overtime Hours

//The format for this function is the following:
//- Define a new object.
//- Implement function call [objectname.functionname(object name 1, object name 2, object name 3)]


} //End of Main Function


void EmployeeClass::ImplementCalculations (string EmployeeName, int hours, double wage) {
//Initialize overtime variables
overtime_hours=0;
overtime_pay=0;
overtime_extra=0;

if (hours > 40)
{

basepay = 40 * wage;
overtime_hours = hours - 40;
overtime_pay = wage * 1.5;
overtime_extra = overtime_hours * overtime_pay;
iIndividualSalary = overtime_extra + basepay;

} // if (hours > 40)
else
{

basepay = hours * wage;
iIndividualSalary = basepay;

}
DisplayEmployInformation ();

} //End of Primary Function

void EmployeeClass::DisplayEmployInformation ()
{
// This function displays all the employee output information.

cout << "\n\n";
cout << "Employee Name ............. = " << EmployeeName << endl;
cout << "Base Pay .................. = " << basepay << endl;
cout << "Hours in Overtime ......... = " << overtime_hours << endl;
cout << "Overtime Pay Amount......... = " << overtime_extra << endl;
cout << "Total Pay ................. = " << iIndividualSalary << endl;

} // END OF Display Employee Information

void EmployeeClass::Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2, EmployeeClass Emp3)
{

iTotal_salaries = 0;
iTotal_hours = 0;
iTotal_OvertimeHours = 0;
for (int i = 0; i < 3; ++i )
{
cout << "\n\n";
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% Total Employee Salaries ..... =" << iTotal_salaries << endl;
cout << "%%%% Total Employee Hours ........ =" << iTotal_hours << endl;
cout << "%%%% Total Overtime Hours......... =" << iTotal_OvertimeHours << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
}
system("PAUSE");
return;
} // End of function

最佳答案

您永远不会调用 Addsomethingup,因此它永远不会打印摘要。将 double 转换为 float 当然会失去精度。对所有变量始终如一地使用 float 或 double(即不要混合使用它们,除非你有充分的理由不这样做,而你在这里可能没有)。

关于java - 最后没有显示员工摘要的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20460786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com