Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,937 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,685 people online right now. Registration is fast and FREE... Join Now!




Adding salaried employees to a program

 
Reply to this topicStart new topic

Adding salaried employees to a program

danijlew1977
2 Oct, 2007 - 08:32 AM
Post #1

New D.I.C Head
*

Joined: 2 Oct, 2007
Posts: 1


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Pontus
RE: Adding Salaried Employees To A Program
2 Oct, 2007 - 10:34 AM
Post #2

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 529



Thanked: 2 times
Dream Kudos: 275
My Contributions
A simple bool salaried or an int that if 0 non salaried and if 1 its salaried.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:36AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month