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
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>
#include <stdexcept>
using namespace std;
//Declaration
const char FileName[] = "EmployeeRecords.txt";
//Class
class Employee
{
private:
string lname;
string fname;
char gender;
int dependents;
double anSal, wkSal;
//for divider:
int title, i;
public:
// Constructors
Employee()
{
fname = "Not Given";
lname = "Not Given";
gender = 'U';
dependents = 0;
anSal = 20000;
}
Employee(string f, string l, char g, int d, double s)
{
}
double Employee::calcPay();
void Employee::display();
string Employee::getFirst();
string Employee::setFirst(string fname);
string Employee::getLast();
string Employee::setLast(string lname);
char Employee::getGen();
char Employee::setGen(string gen, char gender);
int Employee::getDep();
int Employee::setDep(int dependent, string dep);
double Employee::getSal();
double Employee::setSal(string an, double anSal);
void displayDivider(int &title, int &i);
};
void displayDivider(int &title, int &i)
{
if (title == 1)
{
cout << "\n--------------------- Employee " << i << " ---------------------\n";
i++;
return;
}
else if (title == 0)
{
cout << "------------------------------------------------------\n";
}//end ifs
}//end dividers
//get information:
string Employee::getFirst()
{
title = 1;
displayDivider(title, i);
//input
cout << "\nEnter First Name:\t";
cin >> fname;
return fname;
}
string Employee::getLast()
{
cout << "\nEnter Last Name:\t";
cin >> lname;
Employee::setLast(lname);
return lname;
}
char Employee::getGen()
{
string gen;
cout << "\nEnter Gender:\t\t";
cin >> gen;
//check for errors:
while ((gen != ("female")) && (gen != ("male")) && (gen != ("Female")) && (gen != ("Male")))
{
cout << "Error: Gender must be Male or Female.\n";
cout << "Enter Gender:\t\t";
cin >> gen;
}
Employee::setGen(gen, gender);
return gender;
}
int Employee::getDep()
{
string dep;
cout << "\nEnter Dependents:\t";
cin >> dep;
Employee::setDep(dependents, dep);
return dependents;
}
double Employee::getSal()
{
string an;
cout << "\nEnter Last Name:\t";
cin >> an;
Employee::setSal(an, anSal);
return anSal;
title = 0;
displayDivider(title, i);
}
//set values
string Employee::setFirst(string fname)
{
fname = fname;
return fname;
}
string Employee::setLast(string lname)
{
lname = lname;
return lname;
}
char Employee::setGen(string gen, char gender)
{
if (gen[0] == 'F' || gen[0] == 'f')
{
gender = 'F';
return gender;
}
else
{
gender = 'M';
return gender;
}
}
int Employee::setDep(int dependents, string dep)
{
int value = 0;
for (int i = 0; i < dep.length(); i++)
{
value *= 10;
// we multiply value by 10 to move the digits one base 10 position
value += dep[i] % 48;
//converts from ascii to integer value
value = (round(value));//rounds value to nearest integer
}
dependents = value;
return dependents;
}
double Employee::setSal(string an, double anSal)
{
double value = 0.0;
for (int i = 0; i < an.length(); i++)
{
value = atof(an.c_str());
}
anSal = value;
return anSal;
}
//ouput
double Employee::calcPay()
{
wkSal = anSal / 52;
return wkSal;
}
void Employee::display()
{
cout << "\n\nEmployee Information:\n";
title = 0;
displayDivider(title, i);
cout << "Name:\t" << fname << " " << lname << endl;
cout << "Gender:\t" << gender << endl;
cout << "Dependents:\t" << dependents << endl;
cout << "Annual Salary:\t" << anSal << endl;
Employee::calcPay();
cout << "Weekly Salary:\t" << wkSal << endl;
displayDivider(title, i);
}
//main
int main(string fname, string lname, char gender, int dependents, double anSal, string dep)
{
cout << "Assignment:\tLAB2\nDeveloper:\tSierra McGivney\nDate Written:\t05/16/2014\nPurpose:\tInput and output employee information.\n\n";
Employee one("", "", 'U', 0, 20000);
Employee two("Sierra", "McGivney", 'F', 0, 65000);
one.getFirst();
one.getLast();
one.getGen();
one.getDep();
one.getSal();
one.display();
two.display();
return 0;
} //end main
| |