Please Assist me most urgently

Ok, im having trouble creating a simple class called "Wage" that will determine the pay for each of several employees. The company pays time x1 for the first 40 hours worked by each employee and pays time x1.5 the rest of hours over 40.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>  // Wage.h file
#include <string>
using namespace std;
\
class Wage
{
public:
    Wage(int, int, int);

    void setHoursWorked(int);
    int  getHoursWorked();

    void setHourlyRate(int);
    int  getHourlyRate();

    void setSalaryOT(int);
    int  getSalaryOT();

    void displayMessage();

private:
    int hoursWorked;
    int hourlyRate;
    int salaryOT;
};
.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>  //Main.cpp file
using namespace std;
#include "Wage.h"
#include<string>

int main()
{
    Wage work;
            int hoursWorked;
            cout<<"Enter hours worked by Employee: ";
            cin>> hoursWorked;


return 0;
}
.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>  //Wage.cpp file
using namespace std;
#include "Wage.h"
#include<string>

Wage::Wage(int hours, int rate, int gross)
{
    setHoursWorked(hours);
    setHourlyRate(rate);
    setSalaryOT(gross);
}


void Wage::setHoursWorked(int hours)
{
    hoursWorked = hours;
}
int Wage::getHoursWorked()
{
    return hours;
}


void Wage::setHourlyRate(int rate)
{
    hourlyRate = rate;
}
int Wage::getHourlyRate()
{
    return hourlyRate;
}


void Wage::setSalaryOT(int gross)
{
    salaryOT = gross;
}
int Wage::getSalaryOT()
{
    return gross
}

Any help is greatly appreciated guys... I'm a real newbie btw..
Your first issue that I can point out is you are using int vs double. Also I noticed you have a lot of code, but none of it is really being used so far.

I'd personally recommend combining everything into your main CPP file and making it work and then once you get it working, slowly start splitting it into separate files. But that's just the way I've always done things.
I'm lost.. i thought i was doing great... :( imma give up on this c++ thing.. there goes 1.5 semesters down the drain...
This may help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//Employee.h
//##

#include <string>
using std::string;

class Employee{

public:
	Employee();
	void setHoursWorked(double HoursWorked);   
	double getHoursWorked();

	void setSalary(double Salary);
	double getSalary();

	void setWage(double Wage);
	double getWage();
	
	void setName(string Name);
	string getName();

	void inputData();
	void calcSalary();
	void displayInfo();

	static const int MAX_HOURS_PER_WEEK=40;	


private:
	double hoursWorked;
	double salary;
	double wage;
	string name;
	
};//end class Employee 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//Employee.cpp
//##

#include "Employee.h"

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <string>
using std::string;
using std::getline;

Employee::Employee(){

}//end constructor class Employee

void Employee::setHoursWorked(double HoursWorked){
	hoursWorked=HoursWorked;
}//end function setHoursWorked

double Employee::getHoursWorked(){
	return hoursWorked;
}//end function getHoursWorked

void Employee::setSalary(double Salary){
	salary=Salary;
}//end function setSalary

double Employee::getSalary(){
	return salary;
}//end function getSalary

void Employee::setWage(double Wage){
	wage=Wage;
}//end function setWage

double Employee::getWage(){
	return wage;
}//end function getWage

void Employee::setName(string Name){
	name=Name;
}//end function setName

string Employee::getName(){
	return name;
}//end function getName


void Employee::inputData(){
	
	double hoursWorked;
	string name;
	
	cout<<"Enter employee's name: ";
 	getline(cin,name);
	
	cout<<"Enter hours worked: ";
	cin>>hoursWorked;
	cin.ignore(1000,'\n');
	cin.clear();

	setHoursWorked(hoursWorked);
	setName(name);

	calcSalary();

	
}//end function inputData

void Employee::calcSalary(){
	if(getHoursWorked()>MAX_HOURS_PER_WEEK){
		salary=MAX_HOURS_PER_WEEK*getWage();
		salary+=(getHoursWorked()-40)*(getWage()+(getWage()*0.5));
	}else{
		salary=getHoursWorked()*getWage();
	}//end if..else
	
}//end function calcSalary

void Employee::displayInfo(){
	cout<<getName()
		<<"\nHours worked: "<<getHoursWorked()
		<<"\nSalary: "<<getSalary()
		<<endl;
}//end function displayInfo 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//PayDay.cpp
//##

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "Employee.h"

void inputWage(Employee workers[],const int NUMBER_OF_WORKERS); //function prototypes
void inputData(Employee workers[],const int NUMBER_OF_WORKERS);
void displayInformation(Employee workers[],const int NUMBER_OF_WORKERS);

int main(){

const int NUMBER_OF_WORKERS=3;
Employee workers[NUMBER_OF_WORKERS];

inputWage(workers,NUMBER_OF_WORKERS);
cout<<'\n';

inputData(workers,NUMBER_OF_WORKERS);

cout<<'\n'<<endl;

displayInformation(workers,NUMBER_OF_WORKERS);

return 0; //indicates success
}//end of main

void inputWage(Employee workers[],const int NUMBER_OF_WORKERS){
	double wage;
	cout<<"Enter wage: ";
	cin>>wage;
	cin.ignore(1000,'\n');
	cin.clear();

	for(int i=0;i<NUMBER_OF_WORKERS;i++){
		workers[i].setWage(wage);
	}//end for
}//end function inputWage

void inputData(Employee workers[],const int NUMBER_OF_WORKERS){
	for(int i=0;i<NUMBER_OF_WORKERS;i++){
		workers[i].inputData();
	}//end for
}//end function inputData

void displayInformation(Employee workers[],const int NUMBER_OF_WORKERS){
	for(int i=0;i<NUMBER_OF_WORKERS;i++){
		workers[i].displayInfo();
	}//end for
}//end function displayInformation 



Eyenrique-MacBook-Pro:Employee Eyenrique$ ./PayDay 
Enter wage: 100

Enter employee's name: Enrique
Enter hours worked: 41
Enter employee's name: Erick
Enter hours worked: 40
Enter employee's name: Sussy
Enter hours worked: 39


Enrique
Hours worked: 41
Salary: 4150
Erick
Hours worked: 40
Salary: 4000
Sussy
Hours worked: 39
Salary: 3900
Eyenrique-MacBook-Pro:Employee Eyenrique$ ./PayDay 
Enter wage: 100

Enter employee's name: Enrique
Enter hours worked: 42
Enter employee's name: Erick
Enter hours worked: 40
Enter employee's name: Sussy
Enter hours worked: 39


Enrique
Hours worked: 42
Salary: 4300
Erick
Hours worked: 40
Salary: 4000
Sussy
Hours worked: 39
Salary: 3900
Oi, oi, oi, eyenrique. I know you want to help, but giving out huge blocks of code is generally against what we do here.

-Albatross
Sometimes i can't figure out the best way to explain a problem
-I have to improve my 'teaching' skills
But this is a forum, we can help together!
Topic archived. No new replies allowed.