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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
#include "MyEmployee.h"
const double FEDTAX = 0.2;
const double STATETAX = 0.075;
const double OVERPAY = 1.5;
const double ONE = 1;
const int OVERTIME = 40;
MyEmployee::MyEmployee(void)
{
_employeeNumber = 0;
_name = "John Doe";
_streetAddress = "N/A";
_phoneNumber = "N/A";
_hourlyWage = 0.0;
_hoursWorkedThisWeek = 0.0;
}
MyEmployee::MyEmployee(int en, string n, string sa, string pn, double hw, double hwtw)
{
_employeeNumber = en;
_name = n;
_streetAddress = sa;
_phoneNumber = pn;
_hourlyWage = hw;
_hoursWorkedThisWeek = hwtw;
}
MyEmployee::~MyEmployee()
{
}
void MyEmployee::SetEmployeeNumber(int x)
{
_employeeNumber = x;
}
int MyEmployee::GetEmployeeNumber(void)
{
return _employeeNumber;
}
void MyEmployee::SetName(string x)
{
_name = x;
}
string MyEmployee::GetName(void)
{
return _name;
}
void MyEmployee::SetStreetAddress(string x)
{
_streetAddress = x;
}
string MyEmployee::GetStreetAddress(void)
{
return _streetAddress;
}
void MyEmployee::SetPhoneNumber(string x)
{
_phoneNumber = x;
}
string MyEmployee::GetPhoneNumber(void)
{
return _phoneNumber;
}
void MyEmployee::SetHourlyWage(double x)
{
_hourlyWage = x;
}
double MyEmployee::GetHourlyWage(void)
{
return _hourlyWage;
}
void MyEmployee::SetHoursWorkedThisWeek(double x)
{
_hoursWorkedThisWeek = x;
}
double MyEmployee::GetHoursWorkedThisWeek(void)
{
return _hoursWorkedThisWeek;
}
double MyEmployee::CalcPay(void)
{
if(_hoursWorkedThisWeek <= OVERTIME)
{
return double((_hoursWorkedThisWeek * _hourlyWage) * (ONE-(FEDTAX + STATETAX)));
} else {
return double((((_hoursWorkedThisWeek - OVERTIME) * (_hourlyWage * OVERPAY )) + (OVERTIME * _hourlyWage)) * (ONE-(FEDTAX + STATETAX)));
}
}
void MyEmployee::ReadData(ifstream& x)
{
}
void MyEmployee::WriteData(ofstream& x)
{
}
/*
{
private:
int _employeeNumber;
string _name;
string _streetAddress;
string _phoneNumber;
double _hourlyWage;
double _hoursWorkedThisWeek;
public:
Employee(void);
Employee(int, string, string, string, double, double);
void setEmployeeNumber(int);
int getEmployeeNumber(void);
void setName(string);
string getName(void);
void setStreetAddress(string);
string getStreetAddress(void);
void setPhoneNumber(string);
string getPhoneNumber(void);
void setHourlyWage(double);
double getHourlyWage(void);
void setHoursWorkedThisWeek(double);
double getHoursWorkedThisWeek(void);
};
*/
const string WELCOME = "\n--------------------------------Dead Beats Inc.--------------------------------";
const string BUSINESS = "Truly Inconceivable Morgue of Undertown";
const string LINES = "-------------------------------------------------------------------------------";
const string EMPNAME = "Pay to ";
const string EMPPAY = ".................................................. $";
const string EMPHOURS = "Hours worked: ";
const string EMPWAGE = "Hourly Wage: ";
const string INFO = "Employee Information";
const string ADDRESS = "Employee address: ";
const string PHONE = "Employee phone number: ";
const string NUMBER = "Employee number: ";
const string END = " END OF EMPLOYEES";
const string WELCOMEMSG = "This program has 3 options:\n1 - Create a data file.\n2 - Read data from file and display paychecks.\n3 - Exit Program.\n";
const string WELCOMEMSG2 = "Please enter <1> <2> or <3>: ";
const string ERRORMSG1 = "You entered an invalid number, please enter a new value.";
const string WRITTEN = "The file has been created and written too...";
const string FILENAME = "NewTxtFile.txt";
const string PA1 = "1";
const string PA2 = "2";
const string PA3 = "3";
const int FIXED = 2;
const int EMPLOYEENUMBER = 3;
void main()
{
Menu();
}
void Menu()
{
string answer = "";
string temp = "";
bool error = false;
vector<MyEmployee> emp;
ofstream txtFile;
ifstream txtFi;
cout << WELCOMEMSG << WELCOMEMSG2;
do{
getline(cin, answer);
cin.clear();
if(answer == PA1 || answer == PA2 || answer == PA3)
{
error = false;
} else {
cout << ERRORMSG1 << endl << WELCOMEMSG2;
error = true;
}
}while(error == true);
if(answer == PA1)
{
MyEmployee joe(37, "Joe Brown", "123 Main St.", "123-6788", 45, 10.00);
MyEmployee sam(21, "Sam Jones", "45 East State", "661-9000", 30, 12.00);
MyEmployee mary(15, "Mary Smith", "12 High Street", "401-8900", 40, 15.00);
emp.push_back(joe);
emp.push_back(sam);
emp.push_back(mary);
txtFile.open(FILENAME);
for(int i = 0; i < EMPLOYEENUMBER; i++)
{
txtFile << emp.at(i).GetEmployeeNumber() << endl;
txtFile << emp.at(i).GetName() << endl;
txtFile << emp.at(i).GetStreetAddress() << endl;
txtFile << emp.at(i).GetPhoneNumber() << endl;
txtFile << emp.at(i).GetHoursWorkedThisWeek() << endl;
txtFile << emp.at(i).GetHourlyWage() << endl;
}
cout << WRITTEN << endl;
system("PAUSE");
return;
} else if (answer == PA2) {
{
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
MyEmployee joe2();
MyEmployee sam2();
MyEmployee mary2();
emp.push_back(joe2());
emp.push_back(sam2());
emp.push_back(mary2());
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
//THE ERROR HAS SOMETHING TO DO WITH THIS DECLARATION OF THE MyEmployee CLASS
txtFi.open(FILENAME);
for(int i = 0; i < EMPLOYEENUMBER; i++)
{
txtFi >> temp;
emp.at(i).SetEmployeeNumber(atoi(temp.c_str()));
txtFi >> temp;
emp.at(i).SetName(temp);
txtFi >> temp;
emp.at(i).SetStreetAddress(temp);
txtFi >> temp;
emp.at(i).SetPhoneNumber(temp);
txtFi >> temp;
emp.at(i).SetHoursWorkedThisWeek(atof(temp.c_str()));
txtFi >> temp;
emp.at(i).SetHourlyWage(atof(temp.c_str()));
system("CLS");
PrintCheck(emp.at(i));
}
cout << endl << LINES << endl << END << endl << LINES << endl << endl << endl;
system("PAUSE");
return;
}
} else {
cout << endl;
system("PAUSE");
return;
}
}
void PrintCheck(MyEmployee x)
{
cout << WELCOME << endl << endl;
cout << EMPNAME << x.GetName() << EMPPAY << setprecision(FIXED) << fixed << x.CalcPay() << endl << endl;
cout << BUSINESS << endl << LINES << endl;
cout << EMPHOURS << x.GetHoursWorkedThisWeek() << endl;
cout << EMPWAGE << x.GetHourlyWage() << endl;
cout << endl << LINES << endl;
cout << INFO << endl << LINES << endl;
cout << NUMBER << x.GetEmployeeNumber() << endl;
cout << ADDRESS << x.GetStreetAddress() << endl;
cout << PHONE << x.GetPhoneNumber() << endl;
cout << endl << endl << endl;
system("PAUSE");
system("CLS");
}
|