员工摘要问题最终没有显示

时间:2013-12-08 23:49:44

标签: java c++ architecture

我把所有东西都搞定了,当我在把它打开之前去检查它时,有些东西搞砸了,我不能让它在最后运行员工摘要。有人可以指导我到这里我缺少的部分吗?我还一直得到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

2 个答案:

答案 0 :(得分:2)

您永远不会致电Addsomethingup,因此不会打印摘要。将double转换为float当然会失去精度。对所有变量使用浮点数或双精度值(即不要混用它们,除非你有充分的理由不这样做,你可能不在这里)。

答案 1 :(得分:1)

(1)我在MSVC 2010下编译/运行了这个并没有得到类型警告。但是,警告问题很可能是因为你正在混合类型 - 工资,basepay和overtime_pay都是float类型,你正在进行使用int类型变量的计算(文字40和小时)     a - 使用40f而不是40(使用浮点常量而不是int)和     b - 在这些语句中使用static_cast(hours)而不是几小时     c - 考虑使用double类型而不是float类型 - 无论如何,你都可以获得比double类型更好的精度。

正如Mornfall所说,你永远不会调用AddSomethingUp成员函数。

对该函数的唯一引用是类描述中的原型头和实际代码本身 - 您不会在任何地方调用它。

你可以建立功能代码,直到奶牛回家,但除非你实际告诉程序,在某个地方运行它,它不会被执行。您需要在处理完员工数据之后以及从main执行'return'语句之前调用它。

这是使用某些版本的Visual Studio编写的,其中包括以下几行:

// ConsoleApplication29.cpp : Defines the entry point for the console application.`
//
#include "stdafx.h"

您是否尝试在调试器下运行它以查看调用的代码?