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
|
#include <iostream>
#include <iomanip>
#include <ctype.h>
#include <string>
#include <sstream>
#include <stdexcept>
using namespace std;
void displayDivider(int &title);
stringstream ss;
//Class
class Employee
{
private:
string lname, fname, stemp, name;
char gender;
int dependents;
double wkSal;
double anSal;
//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)
{
title = 1;
displayDivider(title);
setFirst(fname);
getFirst();
setLast(lname);
getLast();
setGen(gender);
getGen();
setDep(dependents);
getDep();
setSal(anSal);
getSal();
name = (fname + " " + lname);
display();
}
Employee(string f, string l, char g, int d, double s, int n)
{
n = 2;
title = n;
displayDivider(title);
fname = "Tom";
lname = "Sawyer";
gender = 'M';
dependents = 0;
anSal = 9872.21;//all that from painting fences.
name = (fname + " " + lname);
display();
}
double Employee::calcPay();
void Employee::display();
//Get
string Employee::getFirst();
string Employee::getLast();
char Employee::getGen();
int Employee::getDep();
double Employee::getSal();
//Set
string Employee::setFirst(string fname);
string Employee::setLast(string lname);
string Employee::setGen(char gender);
string Employee::setDep(int dependents);
string Employee::setSal(double anSal);
};
//Divider
void displayDivider(int &title)
{
if (title == 2)
{
int i = 2;
cout << "\n--------------------- Employee " << i << " ---------------------\n";
return;
}
if (title == 1)
{
int i = 1;
cout << "\n--------------------- Employee " << i << " ---------------------\n";
return;
}
else if (title == 0)
{
cout << "------------------------------------------------------\n";
}//end ifs
}//end dividers
//set information
string Employee::setFirst(string fname)
{
cout << "\nEnter First Name:\t";
cin >> fname;
return fname;
}
string Employee::setLast(string lname)
{
cout << "\nEnter Last Name:\t";
cin >> lname;
return lname;
}
string Employee::setGen(char gender)
{
cout << "\nEnter Gender:\t\t";
cin >> stemp;
while ((stemp != "Female") && (stemp != "Male") && (stemp != "female") && (stemp != "male"))
{
cout << "Error: Gender must be Male or Female.\n";
cout << "Enter Gender:\t\t";
cin >> stemp;
}//end while
return stemp;
}
string Employee::setDep(int dependents)
{
cout << "\nEnter Dependents:\t";
cin >> stemp;
return stemp;
}
string Employee::setSal(double anSal)
{
cout << "\nEnter Annual Salary:\t";
cin >> stemp;
title = 0;
displayDivider(title);
return stemp;
}
//get values
string Employee::getFirst()
{
return fname;
}
string Employee::getLast()
{
return lname;
}
char Employee::getGen()
{
char c = stemp[0];
c = toupper(c);
gender = c;
return gender;
}
int Employee::getDep()
{
int value = 0;
for (int i = 0; i < stemp.length(); i++)
{
value *= 10;
// we multiply value by 10 to move the digits one base 10 position
value += stemp[i] % 48;
// the value of any ASCII number character ( 0 - 9)
// can be converted from ASCII format to an integer value
// with % 48
}
dependents = value;
return dependents;
}
double Employee::getSal()
{
anSal = stod(stemp);
return anSal;
}
//ouput
double Employee::calcPay()
{
wkSal = anSal / 52.00;
return wkSal;
}
void Employee::display()
{
title = 0;
displayDivider(title);
cout << "Name:\t" << name << endl;
cout << "Gender:\t" << gender << endl;
cout << "Dependents:\t" << dependents << endl;
cout << setprecision(2) << showpoint << fixed << "Annual Salary:\t" << anSal << endl;
calcPay();
cout << setprecision(2) << showpoint << fixed << "Weekly Salary:\t" << wkSal << endl;
displayDivider(title);
return;
}
//main
int main(int &title)
{
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, 2);//this should be what is displayed for two
return 0;
} //end main
| |