CODE
#include "stdafx.h"
#include <iostream> //Include the iostream class header
using namespace std; //Use the standard template library namespace
#include <iomanip>
const double payRate = 3.275;
//class declaration section
class Employee
{
private:
int empId; //declare variable
public:
Employee(); //default constructor
Employee ( int initempId ); //input parameter constructor
void setempId ( int newempId ); //mutator for employee id
int getempsId();
double calculatePay ( double hoursWorked );
};
//class implementation section
Employee::Employee() // default constructor
{
empId = 0;
}
Employee::Employee( int initempId )//input parameter constructor
{
empId = initempId;
}
void Employee::setempId( int newempId )//mutator for employee id
{
empId = newempId;
}
int Employee::getempsId() //accessor for employee id
{
return empId;
}
double Employee::calculatePay( double hoursWorked )//accessor/mutator for pay rate
{
return payRate * hoursWorked;
}
int _tmain(int argc, _TCHAR* argv[])
{
int emp1Hours, emp2Hours, emp3Hours;
cout <<"Please enter the number of hours Employee 1 worked." << endl;
cin >> emp1Hours;
cout <<"Please enter the number of hours Employee 2 worked." << endl;
cin >> emp2Hours;
cout <<"Please enter the number of hours Employee 3 worked." << endl;
cin >> emp3Hours;
cout << endl << endl;
cin.ignore( ); // This will pause the program until the user presses enter.
cout <<"Employee ID\tPay"<< endl
<<"-------------------"<< endl;
Employee EmpOne;
EmpOne.setempId( 1 );
cout << EmpOne.getempsId()<<
setw(18)<< fixed << setprecision(2) << emp1Hours * payRate << endl;
Employee EmpTwo;
EmpTwo.setempId( 2 );
cout << EmpTwo.getempsId()<<
setw(18)<< fixed << setprecision(2) << emp2Hours * payRate << endl;
Employee EmpThree;
EmpThree.setempId( 3 );
cout << EmpThree.getempsId()<<
setw(18)<< fixed << setprecision(2) << emp3Hours * payRate << endl;
cout <<"-------------------"<< endl;
cout <<"Total" <<
setw(14) << fixed << setprecision(2) <<(emp1Hours * payRate) + (emp2Hours * payRate) + (emp3Hours * payRate) << endl;
cin.ignore( ); // This will pause the program until the user presses enter.
return 0;
}
This is a program I worte to calculate pay and total pay for 3 employees. I'm trying to add salaried employees. My question concerns how I can differentiate between the two types of employees. Currently, I prompt the user to enter hours worked and then I calcualte their pay based on the payrate. I'm assuming that I have to add another variable, I think I need to now prompt the user to tell me if they are slaried or not. Maybe it will look something like this:
cout <<"Please enter the number of hours Employee 1 worked." << endl;
cin >> emp1Hours;
cout <<"Is Employee 1 salaried?" endl;
cin >> some variable
cout <<"Please enter the number of hours Employee 2 worked." << endl;
cin >> emp2Hours;
cout <<"Is Employee 2 salaried?" endl;
cin >> some variable
cout <<"Please enter the number of hours Employee 3 worked." << endl;
cin >> emp3Hours;
cout <<"Is Employee 3 salaried?" endl;
cin >> some variable
I know there is a lot more to this...baby steps. I'm trying to get this right in my head. Thanks in advance.