【发布时间】:2013-12-25 23:33:36
【问题描述】:
我一切正常,但当我在上交之前去检查它时,出了点问题,我无法让它在最后运行员工摘要。有人可以指导我了解我在这里缺少的部分吗?我还不断收到 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
【问题讨论】:
-
抱歉,警告是 C4244。
-
您真的应该将代码缩减为合理的测试用例。如果没有行号,很难确定哪一行是 99...
-
我也会删除不适用的标签。我知道 c# 已被删除,但 c 和 java 也应该删除。
-
对不起,我以为它编号了。就是代码中的 If/Else 语句。
-
PS:你的缩进是假的,这可能是让你失望的原因。考虑找一个代码编辑器或一个为你维护缩进的 IDE,这样会更容易发现这样的错误。
标签: java c++ architecture