Dec 23, 2011 at 2:40am UTC
I have been working on this code, but I am having trouble writing the function for net pay. I had some help with this, but I don't really get how to do this.
any help would be appreciated. I have to have it turned in by tomorrow.I am reading up on functions, and re-reading other posts. We are supposed to calculate how much the net pay is. she said the tax is hard coded to 25%. I think I have the equation for that already, it is just making sure I set the function up correctly. It all has to fall under the Employee class.
Thanks!
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
#include <iostream>
#include <string>
using namespace std;
class Employee {
private :
const int tax = 0.25;
int hours;
int wages;
string employeeName;
public :
Employee() {
setHours(1);
setWages(1);
setTax();
}
Employee(int hours, int wages) {
setHours(hours);
setWages(wages);
setTax(tax);
}
void setWages(int wages) {
if (wages >= 1){
this ->wages = wages;
} else {
cout << "Invalid amount of wages entered." << endl;
}
}
void setHours(int hours) {
if (hours >= 1) {
this ->hours = hours;
} else {
cout << "Invalid number of hours entered." << endl;
}
}
int getWages() {
return wages;
}
int getHours() {
return hours;
}
int getPay() {
return hours * wages;
}
void retrieve() {
int temp;
cout << "Enter Hours: " ;
cin >> temp;
setHours(temp);
cout << "Enter Wages: " ;
cin >> temp;
setWages(temp);
}
};
int main() {
cout << "Enter your name: " ;// this is not showing up
cin >> employeeName;
cout <<" " << employeeName << ", I will calculate your pay for the number of hours you worked.\n\n" ;
cout << "Enter your information, " << employeeName << ".\n\n" ;
Employee empl;
empl.retrieve();
cout << "Hours: " << empl.getHours() << endl;
cout << "Wages: " << empl.getWages() << endl;
cout << "Gross Pay: " << empl.getPay() << endl;
cout << "Net Pay: "
return 0;
}
Last edited on Dec 23, 2011 at 2:49am UTC
Dec 23, 2011 at 2:55am UTC
first private is useless because in a class it is public by default
edit:
first private is useless because in a class all is private by default
Last edited on Dec 23, 2011 at 2:57am UTC
Dec 23, 2011 at 3:26am UTC
This is how the teacher wanted it set up for the assignment.
Dec 23, 2011 at 3:38am UTC
ok just for future reference
Dec 23, 2011 at 6:53am UTC
Thank you....I clearly do not understand C++ as well as some people.