Exceptions continued

I am trying to teach myself exceptions; and not doing a great job. I have a section of code here in the driver that I am trying to make "bullet proof". I am getting an error message that I don't understand. It says cannot access private member declared in class. I am just playing with it so that the user cannot enter and number other that 1 or 2. Any suggestions would be much appreciated.

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
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
127
#include "employee.h"

//Declaring constants
const int WEEK_MAX = 40;
const double FED_TAX = 0.20;
const double STATE_TAX = 0.075;
const double OVER_TIME = 1.5;
const char delim = '\t';
const char space = ' ';

//Declaring variables 
double netPay;
double fedTotal;
double stateTotal;
float payCheck;
double overHours;
double overPay;
double regularPay;

//Setting initial values for the default constructor
Employee::Employee()
{
	employeeNumber = 0;
	employeeName = "";
	employeeAddress = "";
	phoneNumber = "";
	hourlyWage = 0.00;
	weeklyHours = 0.00;
}

//Setting condensed names for parameterized constructor
Employee::Employee(int eNumber, string eName, string eAddress, string pNumber, double hWage, double wHours)
{
	employeeNumber = eNumber;
	employeeName = eName;
	employeeAddress = eAddress;
	phoneNumber = pNumber;
	hourlyWage = hWage;
	weeklyHours = wHours;
}

//Reading information into formatted statements
bool Employee::readEmployee(ifstream& input)
{
	if (input >> employeeNumber && getline(input, employeeName, delim) && getline(input, employeeAddress, delim) && getline(input, phoneNumber, delim) && input >> hourlyWage && input >> weeklyHours)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//Writing information and delimiting output
void Employee::writeEmployee(ofstream& output)
{
	//No error checking when writing a file
	output << employeeNumber	<< space
		   << employeeName		<< delim
		   << employeeAddress	<< delim 
		   << phoneNumber		<< delim 
		   << hourlyWage		<< space
		   << weeklyHours		<< '\n';
}

//EmployeeNumber setter
int Employee::getEmployeeNumber( ) const
{
	return employeeNumber;
}

//EmployeeName setter
string Employee::getEmployeeName( ) const
{
	return employeeName;
}

//EmployeeAddress setter
string Employee::getEmployeeAddress( ) const
{
	return employeeAddress;
}

//PhoneNumber setter
string Employee::getPhoneNumber( ) const
{
	return phoneNumber;
}

//HourlyWage setter
double Employee::getHourlyWage( ) const
{
	return hourlyWage;
}

//WeeklyHours setter
double Employee::getWeeklyHours( ) const
{
	return weeklyHours;
}

//CalcPay method
//Purpose: To calculate pay for an employee
//Parameters: None
//Returns: payCheck as a float
double Employee::getCalcPay( ) const
{
	if (weeklyHours <= WEEK_MAX)
	{
		netPay = hourlyWage * weeklyHours;
		fedTotal = netPay * FED_TAX;
		stateTotal = netPay * STATE_TAX;
		payCheck = ((netPay - fedTotal) - stateTotal);
	}
	else if (weeklyHours > WEEK_MAX)
	{
		overHours = weeklyHours - WEEK_MAX;
		regularPay = WEEK_MAX * hourlyWage;
		overPay = overHours * (hourlyWage * OVER_TIME);
		netPay = regularPay + overPay;
		fedTotal = netPay * FED_TAX;
		stateTotal = netPay * STATE_TAX;
		payCheck = ((netPay - fedTotal) - stateTotal);
	}
	return payCheck;
}


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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <stdexcept>

using namespace std;

//Provides start point for employee information
class Employee
{
private:
	//Setting initial values
	int employeeNumber;
	string employeeName;
	string employeeAddress;
	string phoneNumber;
	double hourlyWage;
	double weeklyHours;
	double calcPay;

public:
	Employee( );

	Employee(int, string, string, string, double, double);

	bool readEmployee(ifstream&);

	void writeEmployee(ofstream&);

	int getEmployeeNumber( ) const;

	string getEmployeeName( ) const;

	string getEmployeeAddress( ) const;

	string getPhoneNumber( ) const;

	double getHourlyWage( ) const;

	double getWeeklyHours( ) const;

	double getCalcPay( ) const;
};

class greaterThanTwoException
{
public:
	greaterThanTwoException() : message("Error: Only options '1' and '2' are available for this program")
	{ }
	string what() const { return message; }

private:
	string message;
};

class lessThanOneException
{
	lessThanOneException() : message("Error: Only options '1' and '2' are available for this program")
	{ }
	string what() const { return message; }

private:
	string message;
};

class stringException
{
	stringException() : message("Error: Only options '1' and '2' are available for this program")
	{ }
	string what() const { return message; }

private:
	string message;
};


driver.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
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
#include "employee.h"

using namespace std;

void printCheck(const Employee&);

//Setting variables
int userSelection;
string fileName;

int main()
{
	//Getting information from the user
	cout << "This program has two options:" << endl;
	cout << "1 - Create a data file, or " << endl;
	cout << "2 - Read data from a file and print paychecks." << endl;
	cout << "Please enter <1> to create a file or <2> to print checks: ";
	cin >> userSelection;
	cout << "Please enter file name: ";
	cin >> fileName;

	if (userSelection < 1)
	{
		throw lessThanOneException();
	}
	if (userSelection > 2)
	{
		throw greaterThanTwoException();
	}
	
	//Creating employees
	Employee b1(1234, "Bruce Banner", "436 E 900 S", "801-465-2291", 10.00, 45);
	Employee b2(1569, "Tony Stark", "7000 E 9680 S", "801-941-0745", 12.50, 30);
	Employee b3(1967, "Charles Xavier", "500 W 780 N", "801-754-3687", 15.00, 40);

	//If statement that handles the writeEmployee information
	if (userSelection == 1)
	{
		ofstream odataFile(fileName);
		if (odataFile.good())
		{
			//Write the data
			b1.writeEmployee(odataFile);
			b2.writeEmployee(odataFile);
			b3.writeEmployee(odataFile);
			odataFile.close();
			cout << "Data file created ... you can now run option 2." << endl;
			system("PAUSE");
		}
	}
	//If statment that handles the readEmployee information
	if (userSelection == 2)
	{
		ifstream idataFile(fileName);
		if (idataFile.good())
		{
			// Read the file
			if (b1.readEmployee(idataFile))
			{
				// If read was successful, print b1
				printCheck(b1);
			}
			if (b2.readEmployee(idataFile))
			{
				//If read was successful, print b2
				printCheck(b2);
			}
			if (b3.readEmployee(idataFile))
			{
				//If read was successful, print b3
				printCheck(b3);
			}
			else // the read operation failed ... display a message
				cout << "\nRead failed";
		}
	}
}
void printCheck(const Employee& b)
{
	cout << "\n--------------------Marvel Comics--------------------" << endl;
	cout << "\n\nPay to the order of " << b.getEmployeeName() << ".............$" << setprecision(2) << fixed << b.getCalcPay() << endl;
	cout << "\n\nS.H.I.E.L.D Bank" << endl;
	cout << "-----------------------------------------------------" << endl;
	cout << "Hours worked: " << b.getWeeklyHours() << endl;
	cout << "Hourly Wage: " << b.getHourlyWage() << endl;
	cout << "\n" << endl;
	system("PAUSE");
	system("CLS");
}
It helps if you tell us what line the error is on.
I do apologize for that. The line is on, 24 of the driver.cpp.
The constructors for lessThanOneException() and stringException() are private.
I see my error! thanks helios!
Topic archived. No new replies allowed.