很难我的代码
Having a hard time my code
我正在上C++课,我必须建立一个工资单系统。 我很难弄清楚我的代码出了什么问题。 我可以让员工生产几个小时,但现在我的代码有一个新的问题。我认为这是正确的,但猜不对。现在新的问题是,我可以让员工生产小时数,但是当我做代码时,我的代码想要将我的加班时间乘以 3 并产生两次加班时间的人的输出。
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//
//CLASS DECLARATION SECTION
//
class EmployeeClass {
public:
void ImplementCalculations(string EmployeeName, int hours, float 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 Data Max Inc. Employee Pay Centernn" ;
EmployeeClass Emp1;
EmployeeClass Emp2;
EmployeeClass Emp3;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "nnEnter the first employee's first name = ";
cin >> Emp1.EmployeeName;
cout << "nnEnter the hours worked = ";
cin >> Emp1.hours;
cout << "nnEnter employee's hourly wage = ";
cin >> Emp1.wage;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "nnEnter the second employee's first name = ";
cin >> Emp2.EmployeeName;
cout << "nnEnter the hours worked = ";
cin >> Emp2.hours;
cout << "nnEnter employee's hourly wage = ";
cin >> Emp2.wage;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "nnEnter the third employee's first name = ";
cin >> Emp3.EmployeeName;
cout << "nnEnter the hours worked = ";
cin >> Emp3.hours;
cout << "nnEnter employee's hourly wage = ";
cin >> Emp3.wage;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
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);
cin.get();
return 0;
} //End of Main Function
void EmployeeClass::ImplementCalculations (string employeeFirstName, int hours, float 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;
DisplayEmployInformation();
} // if (hours > 40)
else
{
basepay = hours * wage;
iIndividualSalary = basepay;
} // End of the else
DisplayEmployInformation();
} //End of Primary Function
void EmployeeClass::DisplayEmployInformation () {
// This function displays all the employee output information.
cout << "nn";
cout << "Employee First Name ............. = " << EmployeeName << endl;
cout << "Base Pay ........................ = " << basepay << endl;
cout << "Hours in Overtime ............... = " << overtime_hours << endl;
cout << "Overtime Pay Amout............... = " << 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;
iTotal_hours = Emp1.hours + Emp2.hours + Emp3.hours;
iTotal_salaries = iIndividualSalary + iIndividualSalary + iIndividualSalary;
iTotal_OvertimeHours = overtime_hours + overtime_hours + overtime_hours;
cout << "nn";
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;
} // End of function
你没有在任何地方打电话给Addsomethingup
。您可能还希望这是一种static
方法。如果您还没有了解这些是什么,请不要担心。
在main
函数结束时,但在cin.get()
之前,请尝试添加:
Emp1.Addsomethingup(Emp1, Emp2, Emp3);
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 0-1背包代码中的错误.我的代码中有什么错误
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 在我的代码中,获得最大的Pair Wise产品C++和输出并不总是正确的
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 为什么我需要C++中不同的排序格式来对这个USACO代码上的数组和优先级队列进行排序
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 是否值得降低我的代码的可读性,以便在出现内存不足错误时提供异常安全性?
- 为什么我的C++程序的程序集输出充满了 .ascii,没有汇编代码?
- 无法在我的堆排序代码中找到错误.无法正确执行.C++
- 如何重写全局方法名称以在调用原始方法之前将我的代码推到前面
- 为什么我的 BaseClass:Method 代码编译(带有单冒号)?
- 我的代码运行良好,但在游戏循环中中断
- 8谜题代码.我的队列没有填充,我找不到错误的位置