Code Errors

"Employee and ProductionWorker Classes

Design a class named Employee. The class should keep the following information in member variables:

Employee name
Employee number
Hire Date

Write one or more constructors and the appropriate accessor and mutator functions for the class.

Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information:

Shift (an integer)
Hourly pay rate (a double)

The workday is divided into two shifts: day and night. The shift variable will hold an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator functions for the class. Demonstrate the classes by writing a program that uses a ProductionWorker object."

Here is my code I have two errors:Hopefully someone can run my code and help me out!
1. Severity Code Description Project File Line Suppression State
Error C2008 '.': unexpected in macro definition EmployeeProductionWorker f:\computer science 2\employeeproductionworker\productionworker.h 2

2. Severity Code Description Project File Line Suppression State
Error C2008 '.': unexpected in macro definition EmployeeProductionWorker f:\computer science 2\employeeproductionworker\employee.h 2



Employee.H

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
#ifndef EMPLOYEE.H
#define EMPLOYEE.H
#include <string>
using namespace std;

class Employee
{
private:
	string name;		// Employee name
	string number;		// Employee number
	string hireDate;	// Hire date

public:
	// Default constructor
	Employee()
	{
		name = ""; number = ""; hireDate = "";
	}

	// Constructor
	Employee(string aName, string aNumber, string aDate)
	{
		name = aName; number = aNumber; hireDate = aDate;
	}

	// Mutators
	void setName(string n)
	{
		name = n;
	}

	void setNumber(string num)
	{
		number = num;
	}

	void setHireDate(string date)
	{
		hireDate = date;
	}

	// Accessors
	string getName() const
	{
		return name;
	}

	string getNumber() const
	{
		return number;
	}

	string getHireDate() const
	{
		return hireDate;
	}
};

#endif  

Productionworker.h

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
#ifndef PRODUCTIONWORKER.H
#define PRODUCTIONWORKER.H
#include "Employee.h"
#include <string>
using namespace std;

class ProductionWorker : public Employee
{
private:
	int shift;		// The worker's shift
	double payRate;	// The worker's hourly pay rate

public:
	class InvalidShift
	{};

	// Default constructor
	ProductionWorker() : Employee()
	{
		shift = 0; payRate = 0.0;
	}

	// Constructor
	ProductionWorker(string aName, string aNumber, string aDate,
		int aShift, double aPayRate) : Employee(aName, aNumber, aDate)
	{
		shift = aShift; payRate = aPayRate;
	}

	// Mutators
	void setShift(int s)
	{
		shift = s;
	}

	void setPayRate(double r)
	{
		payRate = r;
	}

	// Accessors
	int getShiftNumber() const
	{
		return shift;
	}

	string getShiftName() const
	{
		if (shift == 1)
			return "Day";
		else if (shift == 2)
			return "Night";
		else
			throw InvalidShift();
	}
	double getPayRate() const
	{
		return payRate;
	}
};

#endif

Employee.CPP

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
#include <iostream>
#include <iomanip>
#include "ProductionWorker.h"
using namespace std;

// Function prototype
void displayInfo(ProductionWorker);

int main()
{

	try
	{
		ProductionWorker pw("John Jones", "123", "1/1/2006", 3, 18.00);
		displayInfo(pw);
	}
	catch (const ProductionWorker::InvalidShift &invalid)
	{
		cout << "Invalid shift";
	}

	cin.get();
	return 0;
}


//******************************************************
// The displayInfo function displays a production      *
// worker's employment information.                    *
//******************************************************
void displayInfo(ProductionWorker e)

{
	cout << setprecision(2) << fixed << showpoint;
	cout << "Name: "
		<< e.getName() << endl;
	cout << "Employee number: "
		<< e.getNumber() << endl;
	cout << "Hire date: "
		<< e.getHireDate() << endl;
	cout << "Shift: "
		<< e.getShiftName() << endl;
	cout << "Shift number: "
		<< e.getShiftNumber() << endl;
	cout << "Pay rate: "
		<< e.getPayRate() << endl;
};


Last edited on
closed account (48T7M4Gy)
#ifndef PRODUCTIONWORKER_H
#define PRODUCTIONWORKER_H


Underscore?
Hello guys I got the program to compile! I'm having trouble getting the shift, shirt number, pay rate to show up at. If someone can run my code and help me I would great help!

Employee.h

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
ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;

class Employee
{
private:
	string name;		// Employee name
	string number;		// Employee number
	string hireDate;	// Hire date

public:
	// Default constructor
	Employee()
	{
		name = ""; number = ""; hireDate = "";
	}

	// Constructor
	Employee(string aName, string aNumber, string aDate)
	{
		name = aName; number = aNumber; hireDate = aDate;
	}

	// Mutators
	void setName(string n)
	{
		name = n;
	}

	void setNumber(string num)
	{
		number = num;
	}

	void setHireDate(string date)
	{
		hireDate = date;
	}

	// Accessors
	string getName() const
	{
		return name;
	}

	string getNumber() const
	{
		return number;
	}

	string getHireDate() const
	{
		return hireDate;
	}
};


#endif

ProductionWorker.h

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
#ifndef PRODUCTIONWORKER_H
#define PRODUCTIONWORKER_H
#include "Employee.h"
#include <string>
using namespace std;

class ProductionWorker : public Employee
{
private:
	int shift;		// The worker's shift
	double payRate;	// The worker's hourly pay rate

public:
	class InvalidShift
	{};

	// Default constructor
	ProductionWorker() : Employee()
		{ shift = 0; payRate = 0.0; }

	// Constructor
	ProductionWorker(string aName, string aNumber, string aDate,
		int aShift, double aPayRate) : Employee(aName, aNumber, aDate)
		{ shift = aShift; payRate = aPayRate; }

	// Mutators
	void setShift(int s)
		{ shift = s; }

	void setPayRate(double r)
		{ payRate = r; }

	// Accessors
	int getShiftNumber() const
		{ return shift; }

	string getShiftName() const
		{ if (shift == 1)
			 return "Day";
		  else if (shift == 2)
			 return "Night";
		  else
			throw InvalidShift();
		}
	double getPayRate() const
		{ return payRate; }
};

#endif  

Employee.CPP

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
#include <iomanip>
#include "ProductionWorker.h"
#include "Employee.h"
using namespace std;

// Function prototype
void displayInfo(ProductionWorker);

int main()
{

	try
	{
		ProductionWorker pw("John Jones", "123", "1/1/2006", 3, 18.00);
		displayInfo(pw);
	}
	catch (const ProductionWorker::InvalidShift &invalid)
	{
		cout << "Invalid shift";
	}

	cin.get();
	return 0;
}


//******************************************************
// The displayInfo function displays a production      *
// worker's employment information.                    *
//******************************************************
void displayInfo(ProductionWorker e)

{
	cout << setprecision(2) << fixed << showpoint;
	cout << "Name: "
		<< e.getName() << endl;
	cout << "Employee number: "
		<< e.getNumber() << endl;
	cout << "Hire date: "
		<< e.getHireDate() << endl;
	cout << "Shift: "
		<< e.getShiftName() << endl;
	cout << "Shift number: "
		<< e.getShiftNumber() << endl;
	cout << "Pay rate: "
		<< e.getPayRate() << endl;
}; 
closed account (48T7M4Gy)
You will need to be more specific than that.

Since you wrote this code you will have a clear idea of how you have tested your program and details of what you attempted, what you expected as output and what you actually got as output, perhaps error messages, even line numbers.

Better still, go back to the step where you got to in writing your code and it was running properly and isolate what new change caused the problem. If you tell us that it would help a lot :)
I have everything working except the Shift Number and What Shift the person works on! I'm assuming the problem is with my ProductionWork. h because it keeps putting #3 for both the shift and shift number!

Here is the output I keep getting
Name: John Jones
Employee Number: 123
Hire Date: 1/1/2006
Shift: (depending on the #1 or #2 should be Day for #1 and Night for #2)
Shift Number: (this parts needs be either 1 or 2)
closed account (48T7M4Gy)
It keeps putting 3 because that’s what you specify when you declare pw in main(). There’s nothing in the constructor that will throw an exception for an invalid shift.
Well can you please help me with that then?
closed account (48T7M4Gy)
You first need to locate where you wrote your code for the check which forms the basis for the try.
Can I please get someone to run my code and help me get this last two issues corrected please:
This is what I'm trying to accomplish! I have everything working correcting except the Shift and Shift Number: I have provided my code:

Here is the output I Need:
Name: John Jones
Employee Number: 123
Hire Date: 1/1/2006
Shift: (depending on the #1 or #2 should be Day for #1 and Night for #2)
Shift Number: (this parts needs be either 1 or 2)


Employee.h
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
/s/ 
#define EMPLOYEE_H
#include <string>
using namespace std;

class Employee
{
private:
	string name;		// Employee name
	string number;		// Employee number
	string hireDate;	// Hire date

public:
	// Default constructor
	Employee()
	{
		name = ""; number = ""; hireDate = "";
	}

	// Constructor
	Employee(string aName, string aNumber, string aDate)
	{
		name = aName; number = aNumber; hireDate = aDate;
	}

	// Mutators
	void setName(string n)
	{
		name = n;
	}

	void setNumber(string num)
	{
		number = num;
	}

	void setHireDate(string date)
	{
		hireDate = date;
	}

	// Accessors
	string getName() const
	{
		return name;
	}

	string getNumber() const
	{
		return number;
	}

	string getHireDate() const
	{
		return hireDate;
	}
};

#endif  


ProductionWorker.h

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
#ifndef PRODUCTIONWORKER_H
#define PRODUCTIONWORKER_H
#include "Employee.h"
#include <string>
using namespace std;

class ProductionWorker : public Employee
{
private:
	int shift;		// The worker's shift
	double payRate;	// The worker's hourly pay rate

public:
	class InvalidShift
	{};

	// Default constructor
	ProductionWorker() : Employee()
		{ shift = 0; payRate = 0.0; }

	// Constructor
	ProductionWorker(string aName, string aNumber, string aDate,
		int aShift, double aPayRate) : Employee(aName, aNumber, aDate)
		{ shift = aShift; payRate = aPayRate; }

	// Mutators
	void setShift(int s)
		{ shift = s; }

	void setPayRate(double r)
		{ payRate = r; }

	// Accessors
	int getaShift() const
		{ return shift; }

	string getShift() const
		{ if (shift == 1)
			 return "Day";
		   if (shift == 2)
			 return "Night";
		  else
			throw InvalidShift();
		}
	double getaPayRate() const
		{ return payRate; }
};

#endif  


Employee.Cpp

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
#include <iostream>
#include <iomanip>
#include "ProductionWorker.h"
#include "Employee.h"
using namespace std;

// Function prototype
void displayInfo(ProductionWorker);

int main()
{

	try
	{
		ProductionWorker pw("John Jones", "123", "1/1/2006", 2, 18.00);
		displayInfo(pw);
		
	}
	catch (const ProductionWorker::InvalidShift &invalid)
	{
		cout << "Invalid shift";
	}

	cin.get();
	return 0;
}


//******************************************************
// The displayInfo function displays a production      *
// worker's employment information.                    *
//******************************************************
void displayInfo(ProductionWorker e)

{
	cout << setprecision(2) << fixed << showpoint;
	cout << "Name: "
		<< e.getName() << endl;
	cout << "Employee number: "
		<< e.getNumber() << endl;
	cout << "Hire date: "
		<< e.getHireDate() << endl;
	cout << "Shift: " 
		<< e.getaShift() << endl;
	cout << "Shift number: "
		<< e.getaShift() << endl;
	cout << "Pay rate: "
		<< e.getaPayRate() << endl;
}; 

closed account (48T7M4Gy)
Are you really, really sure this is your own work?

Because if you wrote this code and not copied it, you would know and understand exactly what I have been saying and know exactly where you wrote the relevant code. But regrettably you haven’t given any indication you know.

Maybe I’m wrong. Maybe you were in a trance when you wrote it. Maybe you simply forgot where you put it. Only you know for sure.

And maybe someone will come along and answer your question. Good luck to you, and them :)
Listen Kemort just because I can't read between whatever your hinting at doesn't mean I'm stupid. If you aren't willing to help or show me what I'm missing then stop posting on my post! I have it working only issues is I can't figure out two parts and I've been looking and changing things constantly only to be getting more lost. I'm just learning this kind of stuff so I'm no pro the way you seem to be with your post.
closed account (48T7M4Gy)
Take it easy, I understand. I would say cunning and deceptive rather than stupid. But rest assured, you’re beautiful when you’re angry. Like I said someone might come along so good luck and stand by.
Look carefully at line 44 in Employee.cpp. Compare it to line 46.
Thank you for your help doug! I was able to get it figured out! Thank you so much!
I wanted to ask if there was a way to remove these two things without crashing the problem? I've tried removing them but then program doesn't work!

else
throw InvalidShift();

catch (const ProductionWorker::InvalidShift &invalid)
{
cout << "Invalid shift";
}
If you want to delete the exception-related catch block, you also need to remove the try block.

Try to see if this works:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 	string getShift() const
		{ if (shift == 1)
			 return "Day";
		   if (shift == 2)
			 return "Night";
		}

 ...

int main()
{

	ProductionWorker pw("John Jones", "123", "1/1/2006", 2, 18.00);
	displayInfo(pw);

	cin.get();
	return 0;
}


And please, for next time, be more descriptive than saying "the problem doesn't work".
Is it compiling? If not, what's the error?
If it is running, is it crashing or just with unexpected output?
Last edited on
closed account (48T7M4Gy)
https://gist.github.com/shade34321/4974779
http://www.cplusplus.com/forum/beginner/123749/
Last edited on
Topic archived. No new replies allowed.