I've been working on this little project for a while now. Everytime I get close to completing it, something goes wrong. Can someone please tell me what this error means:
error C2228: left of '.calculatePay' must have class/struct/union
Here is the code. Thanks
Code:#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
const double _payRate = 3.75;
class Employee
{
private:
int _empId; // Employee Id.
// double _hoursWorked; // Hours Worked.
public:
Employee( ); // Constructor.
Employee( int empId ); // Overloaded Constructor.
double calculatePay( /*int*/ double hoursWorked ); // Calculates the Employees pay.
double salary;
void setEmpId( int empId ); // Mutator Method - allows you to set the employee id.
int getEmpId( ); // Accessor Method - allows you to get the employee id.
void setSalaried(); //
bool getSalaried(); //
};
// Constructor.
Employee::Employee()
{
this->_empId = 1;
//this->_payRate = 5.33;
// this->_hoursWorked = 10.0;
}
Employee::Employee( int empId )
{
this->_empId = empId;
//this->_payRate = payRate;
}
// Calculates the Employee's pay based upon the _payRate and _hoursWorked.
double Employee::calculatePay( /*int*/ double hoursWorked )
{
return _payRate * hoursWorked;
}
// Sets the Employee Id
void Employee::setEmpId( int empId )
{
this->_empId = empId;
}
// Gets the employee id.
int Employee::getEmpId( )
{
return this->_empId;
}
// Main C++ function.
int _tmain(int argc, _TCHAR* argv[])
{
double emp1Pay = 0.0;
double emp2Pay = 0.0;
double emp3Pay = 0.0;
double totalPay = 0.0;
Employee emp1( 1);
Employee emp2( 2 );
Employee emp3( 3 );
double emp1Hours, emp2Hours, emp3Hours;
cout << "Please type number of hours for first employee\t: ";
cin >> emp1Hours;
cout<< _payRate * emp1Hours<<endl;
cout<< "Please type number of hours for second employee\t: ";
cin>> emp2Hours;
cout<< _payRate * emp2Hours<<endl;
cout<<"Please type number of hours for third employee\t: ";
cin>>emp3Hours;
cout<<_payRate * emp3Hours<<endl;
//cout << "Employee " << emp.getEmpId( ) << "'s salary is : " << emp.calculatePay( 40 );
emp1Pay = emp.calculatePay( emp1Hours );
totalPay += emp1Pay;
emp2Pay = emp.calculatePay( emp2Hours );
totalPay += emp2Pay;
emp3Pay = emp.calculatePay( emp3Hours );
totalPay += emp3Pay;
cout << endl << "Employee ID" << setw(15) << "Pay" << endl;
cout << "----------------------------" << endl;
cout << emp1.getEmpId( ) << setw(27) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << emp1Pay << setiosflags( ios::left ) << endl;
cout << emp2.getEmpId( ) << setw(27) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << emp2Pay << setiosflags( ios::left ) << endl;
cout << emp3.getEmpId( ) << setw(27) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << emp3Pay << setiosflags( ios::left ) << endl;
cout << "----------------------------" << endl;
cout << "Total" << setw(23) << setiosflags( ios::right ) << fixed << setprecision( 2 ) << totalPay << setiosflags( ios::left ) << endl;
cout << endl << endl << "Please press a key and then press enter to quit." << endl;
char a;
cin >> a;
return 0;
}