Keep getting bad output

Hello all. I am writing a program and I keep getting the same values that I have in my default constructor even though I am using set functions to set the values of the object and am using get functions to return the value. Can anyone point out my error?

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  
#include <string>
#include <iostream>
using namespace std;

class Employee
{
private: string empName;
		 int empNum;
		 string hireDate;
public:
	Employee():empName(""),empNum(0), hireDate("") //default ctor
	{}

	Employee(string name, int num, string date)
	{
		empName = name;
		empNum = num;
		hireDate = date;
	}

	void setempName(string n);
	void setempNum(int nm);
	void setHiredate(string d);
	string getName();
	int getNum();
	string getDate();
	void print();
};

void Employee::setempName(string n)
{ n = empName;}

void Employee::setempNum(int nm)
{ nm = empNum;}

void Employee::setHiredate(string d)
{d = hireDate;}

string Employee::getName()
{return empName;}

int Employee::getNum()
{return empNum;}

string Employee::getDate()
{return hireDate;}



//derived class production worker

class ProductionWorker : public Employee
{
private:
	int shift;
	double hrlyPay;
public:
	ProductionWorker():shift(0) , hrlyPay(0.0)
	{}

	ProductionWorker(int sh , double pay)
	{
		shift = sh;
		hrlyPay = pay;
	}

	void setshift(int s);
	void setPay(double p);
	int getshift();
	double getPay();
	void print();
};

void ProductionWorker::print()
{
	cout << "Employee Name: " << getName() << endl;
	cout << "Employee Number: " << getNum() << endl;
    cout << "Hire Date: " << getDate() << endl;
    cout << "Shift: " << getshift();
	
	if(shift == 1)
	{
		cout << "(Day Shift)" << endl;}
	else
		cout << "(Night Shift)" << endl;

    cout << "Pay Rate: $" << getPay()<< endl;
}

void ProductionWorker::setshift(int sh)
{sh = shift;}

void ProductionWorker::setPay(double p)
{p = hrlyPay;}

int ProductionWorker::getshift()
{return shift;}

double ProductionWorker::getPay()
{return hrlyPay;}



int main()
{
	
	int Shift;
	double pay;
	cout << "Enter 1 for Day Shift or 2 for Night Shift: ";
	cin >> Shift;
	cout << "Enter hourly pay: $";
	cin >> pay;
    ProductionWorker emp1(Shift, pay);
	emp1.setempName("John Jenkins");
	emp1.setempNum(123);
	emp1.setHiredate("12-25-2013");
	emp1.print();
	return 0;
}

	
	




Here is the output I keep getting
Enter 1 for Day Shift or 2 for Night Shift: 2
Enter hourly pay: $8.50
Employee Name:
Employee Number: 0
Hire Date:
Shift: 2(Night Shift)
Pay Rate: $8.50
Press any key to continue . . .
Last edited on
Look more closely at your setter methods, e.g.

1
2
void Employee::setempNum(int nm)
{ nm = empNum;}


What exactly are you changing the value of here?
Last edited on
I am setting nm to get the value of enum. Sorry if that doesn't make sense I am fairly new to OOP.
I am setting nm to get the value of enum.


Yes, you are. Was that really what you wanted that function to do?
Last edited on
I figured it out my mutators were backwards empNum = nm was how it should've been. However I think that may be what you were trying to point out to me LOL Thanks
Yep - that's what I was hinting at! Glad you managed to find it, and I hope the code's working now :)
Topic archived. No new replies allowed.