pay c++

teacher program notes:

Create a UML diagram for the following class and then create the following class and demo program. Submit the UML diagram, the class file(s), and the demo program in the drop box area.

Create a class called Pay. The class needs to have the following fields: hours, rate, and tax, where hours is the number of hours that the employee worked, rate is the hourly pay rate, and tax is the tax amount withheld. The class needs to have the following methods:
1.) A default constructor that is used if an object is created without any arguments.
2.) An overloaded constructor that accepts the hours and rate.
3.) A set function for each of the three fields: hours, rate, and tax.
4.) A get function for each of the three fields: hours, rate, and tax.
5.) A get function that calculates and returns the employee’s pay.
NOTE: The pay is to be calculated as follows:
Multiply the hours by the rate.
Take that result and subtract the tax which will give you the pay.

Now write a demo program that will demonstrate that the class is working properly. Create an object using the default constructor. Now ask the user for the number of hours worked, the rate per hour, and the amount of tax withheld. Using the set functions, pass these values to the class. Have the class calculate and return the pay to the main program. The main program needs to display the pay. Now ask the user for the hours worked, the rate of pay, and the amount of taxes withheld for a second employee. Then create a second object that passes the hours and the rate to the constructor. Use the set function to set the tax. Have the class calculate and return the pay for the second employee and have the main program display this result. No data validation is needed.

p.s. dont worry got uml done

what i need:
i need help finishing this program kinda lost. any help would be greatly appreciated.

what i got so far:

header file:

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
// header file

#ifndef PAY_H
#define PAY_H

// Pay class declation
class Pay
{

private:

	// The variables are declared private
	// to protect them from being
	// changed by mistake.
	double hours;
	double rate;
	double tax;

public:

	// Default constructor - Used when an object is created
	// without any values.
	Pay();

	// Overloaded constructor - Used when an object is created 
	// with a hours, rate, and tax.
	Pay(double, double, double);

	// The 2 set functions are used whenever an outside program
	// needs to set (ie. pass) the hours, rate, and tax to the objecet.
	void setHours(double);
	void setRate(double);
	void setTax(double);

	// The 2 get functions are used whenever an outside program wants to
	// retireve the hours, rate, and tax of the Pay object.
	double getHours();
	double getRate();
	double getTax();

	// The following functions are called whenever an outide program wants
	// to know the person's gross and net pay.
	double getGrossPay();
	double getNetPay(double);


};
#endif 



pay.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// file is Pay.cpp

#include "pay.h"

/*****************************************************************
 * Here is the default constructor. It is used when the main     *
 * program creates an object without any values. The constructor *
 * will assign a value of 0 to the hours, rate, and tax.         *
 *****************************************************************/

Pay::Pay()
{

	hours = 0;
	rate = 0;
	tax = 0;

}

/*****************************************************************
 * Here is the overloaded constructor. It is is used whenever an *
 * object is created with the hours, rate, and tax.              *
 *****************************************************************/

Pay::Pay(double h, double r, double t)
{

	hours = h;
	rate = r;
	tax = t;

}

/*******************************************************************
 *                         Pay::setHours                           *
 * If the argument passed to the setHours function is zero or      *
 * greater, it is copied into the member variable hours, and true  *
 * is returned. If the argument is negative, the user is told to   *
 * to re-enter the number as a positive number.                    *
 *******************************************************************/

void Pay::setHours(double hou)
{

	if (hou > 0)
		hours = hou;
	else
		hours = 0;
	
}

/******************************************************************
 *                         Pay::setRate                           *
 * If the argument passed to the setRate function is zero or      *
 * greater, it is copied into the member variable rate, and true  *
 * is returned. If the argument is negative, the value of rate    *
 * is assigned the value of 0.                                    *
 ******************************************************************/
void Pay::setRate(double ra)
{

	if (ra >= 0)                 // If r is valid
		rate = ra;              // copy it to width
	else
		rate = 0;

}

/******************************************************************
 *                         Pay::setTax                            *
 * If the argument passed to the setTax function is zero or       *
 * greater, it is copied into the member variable tax, and true   *
 * is returned. If the argument is negative, the value of tax     *
 * is assigned the value of 0.                                    *
 ******************************************************************/
void Pay::setTax(double ta)
{

	if (ta >= 0)                 // If ta is valid
		tax = ta;               // copy it to width
	else
		tax = 0;

}

/**************************************************************
 *                         Pay::getHours                      *
 * This function returns the value in member variable hours.  *
 **************************************************************/
double Pay::getHours()
{
	
	return hours;

}

/**************************************************************
 *                         Pay::getRate                       *
 * This function returns the value in member variable rate.   *
 **************************************************************/
double Pay::getRate()
{
	
	return rate;

}

/*************************************************************
 *                          Pay::getTax                      *
 * This function returns the value in member variable tax.  *
 *************************************************************/
double Pay::getTax()
{

	return tax;

}

/*************************************************************
 *                       Pay::getGrossPay                      *
 * This function calculates and returns the users gross pay. *
 *************************************************************/
double Pay::getGrossPay()
{
	
	return hours * rate;

}

/***********************************************************
*                       Pay::getNetPay                    *
* This function calculates and returns the users net pay. *
***********************************************************/
double Pay::getNetPay(double g)
{
	double netPay;
	double grossPay;
	g = grossPay;
	
	return netPay = g - tax;

}


revised.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
/*********************************************************
 * This program that uses the Pay class.                 *
 * The Pay class declaration is in file pay.h.           *
 * The Pay member function definitions are in pay.cpp    *
 * These files should all be combined into this project. *
 *********************************************************/
#include <iostream>
#include "pay.h"         // Contains Pay class declaration

using namespace std;

int maim()
{

	double hours, rate, tax, grossPay, netPay;

	cout << " Please enter employee ones hours worked: ";
	cin >> hours;

	cout << " Please enter pay rate for employee one: ";
	cin >> rate;

	cout << " Please enter taxes being taking out of employee ones pay check: ";
	cin >> tax;

	cout << "__________________________________________________________________________" << endl;
	
	
	
	
	Pay payA(netPay);
	netPay = payA.getNetPay();
	cout << fixed << showpoint << setprecision(2);
	cout << " Gross pay is: $" << grossPay << endl;
	cout << " Net pay is: $" << netPay << endl;

}
I noticed I wasn't exactly going how my teacher wanted.

header file:

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
// header file

#ifndef PAY_H
#define PAY_H

// Pay class declation
class Pay
{

private:

	// The variables are declared private
	// to protect them from being
	// changed by mistake.
	double hours;
	double rate;
	double tax;

public:

	// Default constructor - Used when an object is created
	// without any values.
	Pay();

	// Overloaded constructor - Used when an object is created 
	// with a hours, rate, and tax.
	Pay(double, double, double);

	// The 2 set functions are used whenever an outside program
	// needs to set (ie. pass) the hours, rate, and tax to the objecet.
	void setHours(double);
	void setRate(double);
	void setTax(double);

	// The 2 get functions are used whenever an outside program wants to
	// retireve the hours, rate, and tax of the Pay object.
	double getHours();
	double getRate();
	double getTax();

	// The following functions are called whenever an outide program wants
	// to know the person's gross and net pay.
	double getPay(double);
	


};
#endif 



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
128
129
130
131
// file is Pay.cpp

#include "pay.h"

/*****************************************************************
 * Here is the default constructor. It is used when the main     *
 * program creates an object without any values. The constructor *
 * will assign a value of 0 to the hours, rate, and tax.         *
 *****************************************************************/

Pay::Pay()
{

	hours = 0;
	rate = 0;
	tax = 0;

}

/*****************************************************************
 * Here is the overloaded constructor. It is is used whenever an *
 * object is created with the hours, rate, and tax.              *
 *****************************************************************/

Pay::Pay(double h, double r, double t)
{

	hours = h;
	rate = r;
	tax = t;

}

/*******************************************************************
 *                         Pay::setHours                           *
 * If the argument passed to the setHours function is zero or      *
 * greater, it is copied into the member variable hours, and true  *
 * is returned. If the argument is negative, the user is told to   *
 * to re-enter the number as a positive number.                    *
 *******************************************************************/

void Pay::setHours(double hou)
{

	if (hou > 0)
		hours = hou;
	else
		hours = 0;
	
}

/******************************************************************
 *                         Pay::setRate                           *
 * If the argument passed to the setRate function is zero or      *
 * greater, it is copied into the member variable rate, and true  *
 * is returned. If the argument is negative, the value of rate    *
 * is assigned the value of 0.                                    *
 ******************************************************************/
void Pay::setRate(double ra)
{

	if (ra >= 0)                 // If r is valid
		rate = ra;              // copy it to width
	else
		rate = 0;

}

/******************************************************************
 *                         Pay::setTax                            *
 * If the argument passed to the setTax function is zero or       *
 * greater, it is copied into the member variable tax, and true   *
 * is returned. If the argument is negative, the value of tax     *
 * is assigned the value of 0.                                    *
 ******************************************************************/
void Pay::setTax(double ta)
{

	if (ta >= 0)                 // If ta is valid
		tax = ta;               // copy it to width
	else
		tax = 0;

}

/**************************************************************
 *                         Pay::getHours                      *
 * This function returns the value in member variable hours.  *
 **************************************************************/
double Pay::getHours()
{
	
	return hours;

}

/**************************************************************
 *                         Pay::getRate                       *
 * This function returns the value in member variable rate.   *
 **************************************************************/
double Pay::getRate()
{
	
	return rate;

}

/*************************************************************
 *                          Pay::getTax                      *
 * This function returns the value in member variable tax.  *
 *************************************************************/
double Pay::getTax()
{

	return tax;

}

/*************************************************************
 *                       Pay::getGrossPay                      *
 * This function calculates and returns the users gross pay. *
 *************************************************************/
double Pay::getPay(double p)
{

	double pay;
	p =  pay;
	return hours * rate;

}



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
/*********************************************************
 * This program that uses the Pay class.                 *
 * The Pay class declaration is in file pay.h.           *
 * The Pay member function definitions are in pay.cpp    *
 * These files should all be combined into this project. *
 *********************************************************/
#include <iostream>
#include <iomanip>
#include "pay.h"         // Contains Pay class declaration

using namespace std;

int maim()
{

	double hours, rate, tax, pay, finalPay;

	cout << " Please enter employee ones hours worked: ";
	cin >> hours;

	cout << " Please enter pay rate for employee one: ";
	cin >> rate;

	cout << " Please enter taxes being taking out of employee ones pay check: ";
	cin >> tax;

	cout << "__________________________________________________________________________" << endl;
	
	finalPay = pay - tax;

	cout << fixed << showpoint << setprecision(2);
	cout << " Pay before taxes is: $" << pay << endl;
	cout << " Tax deduction is: $" << tax << endl;
	cout << " Take home pay is: $" << finalPay << endl;


}



Topic archived. No new replies allowed.