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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int n;
const double FALL = 0.39,
SPRING = 0.37,
SUMMER = 0.24;
const int SIZE = 9;
const int SIZE2 = 9;
void inputdata(ifstream &, string[][SIZE], double[][3][3], double[][SIZE2], int, int);
void validatedata(string[][SIZE], int, int);
void validatedata(double[][3][3], int, int);
void fwe(double[][3][3], double[][SIZE2], int, int);
void tafwe(double [][SIZE2], int , int);
void srinpercent(double [][SIZE2], string [][SIZE], int , int );
void salary(double [][SIZE2], int , int );
void letter(string [][SIZE], double [][SIZE2], int , int );
void report(ofstream &, string [][SIZE], double [][3][3], double [][SIZE2], int , int );
int main()
{
cout << "How many Employees? ";
cin >> n;
string mystring[n][SIZE];
double grades[n][3][3];
double totalval[n][SIZE2];
while(n < 1 || n > 3)
{
cout << "Invalid! emp must range from 1 - 3" << endl;
cout << "How many Employees? ";
cin >> n;
}
ifstream fin;
fin.open("project1.txt");
if(!fin)
{
cout << "error" << endl;
return 1;
}
ofstream fout;
fout.open("project2.txt");
for(int emp = 0;emp < n; emp++)
{
inputdata(fin, mystring, grades, totalval, n, emp);
validatedata(mystring, n, emp);
validatedata(grades, n, emp);
fwe(grades, totalval, n, emp);
tafwe(totalval, n, emp);
srinpercent(totalval, mystring, n, emp);
salary(totalval, n, emp);
letter(mystring, totalval, n, emp);
report(fout, mystring, grades, totalval, n, emp);
}
fin.close();
fout.close();
return 0;
}
void inputData(ifstream &fin, string mystring[][SIZE], double grades[][3][3], double totalval[][SIZE2], int n, int emp)
{
for(int i = 0;i < SIZE;i++)
{
getline(fin, mystring[emp][i]);
}
for(int year =0; year < 3; year++)
{
for(int j = 0;j < 3;j++)
{
fin >> grades[emp][year][j];
}
}
fin >> totalval[emp][5];
fin.ignore();
}
void validateData(string mystring[][SIZE], int n, int emp)
{
//sending the information from the input file to the cout file with the loop
for(int i = 0;i < SIZE;i++)
{
//inner loop for non numeric strings
if(mystring[emp][i].length() < 1 || mystring[emp][i].length() > 100)
{
cout << "error" << endl;
continue;
}
}
}
void validateData(double grades[][3][3], int n, int emp)
{
//reads the numeric values from the input file
for(int year = 0; year < 3; year++)
{
for(int j = 0;j < 3;j++)
{
for(int k = 0;k < 3;k++)
{
if(grades[emp][year][j] < 1 || grades[emp][year][j] > 1000)
{
cout << "error";
break;
}
}
}
}
}
void fwe(double grades[][3][3], double totalval[][SIZE2], int n, int emp)
{
totalval[emp][0] = (grades[emp][0][0] * SPRING) + (grades[emp][0][1] * SUMMER) + (grades[emp][0][1] * FALL);
totalval[emp][1] = (grades[emp][1][2] * SPRING) + (grades[emp][1][1] * SUMMER) + (grades[emp][1][2] * FALL);
totalval[emp][2] = (grades[emp][2][0] * SPRING) + (grades[emp][2][1] * SUMMER) + (grades[emp][2][2] * FALL);
totalval[emp][3] = totalval[emp][0] + totalval[emp][1] + totalval[emp][2];
}
void tafwe(double totalval[][SIZE2], int n, int emp)
{
totalval[emp][3] = totalval[emp][0] + totalval[emp][1] +totalval[emp][2];
totalval[emp][4] = totalval[emp][3]/3;
}
void srinpercent(double totalval[][SIZE2], string mystring[][SIZE], int n, int emp)
{
if(totalval[emp][4] < 75.)
{
totalval[emp][6] = 0;
}
else if(totalval[emp][4] > 75 && totalval[emp][4] <= 80)
{
totalval[emp][6] = 1;
}
else if(totalval[emp][4] > 80 && totalval[emp][4] <= 90)
{
totalval[emp][6] = 3;
}
else if(totalval[emp][4] > 90 && totalval[emp][4] <= 100)
{
totalval[emp][6] = 5;
}
else if(totalval[emp][4] > 100)
{
totalval[emp][6] = 10;
}
}
void salary(double totalval[][SIZE2], int n, int emp)
{
totalval[emp][7] = (totalval[emp][6]/100) * totalval[emp][5];
totalval[emp][8] = totalval[emp][5] + totalval[emp][7];
}
void letter(string mystring[][SIZE], double totalval[][SIZE2], int n, int emp)
{
if(totalval[emp][4] < 70)
{
mystring[emp][7] = "Warning!";
}
else if(totalval[emp][4] >= 95)
{
mystring[emp][8] = "Congrats!";
}
}
void report(ofstream &fout, string mystring[][SIZE], double grades[][3][3], double totalval[][SIZE2], int n, int emp)
{
fout << mystring[emp][0] << endl;
fout << "\t" << mystring[emp][1] << endl;
fout << "Name: " << mystring[emp][2] << endl;
fout << "Supervisor:" << mystring[emp][3] << endl;
fout << "ID: " << mystring[emp][4] << endl;
fout << "num: " << mystring[emp][5] << endl;
fout << "addy: " << mystring[emp][6] << endl;
for(int year = 0;year < 3;year++)
{
for(int j = 0;j < 3;j++)
{
switch(j)
{
case 0: //case for 2013
fout << " Spring Semester Evaluation, " << fixed << setprecision(2) << 2015 + year << ": " << grades[emp][year][j] << endl;
break;
case 1: //case for 2014
fout << " Summer Semester Evaluation, " << fixed << setprecision(2) << 2015 + year << ": " << grades[emp][year][j] << endl;
break;
case 2: //case for 2015
fout << " Fall Semester Evaluation, " << fixed << setprecision(2) << 2015 + year << ": " << grades[emp][year][j] << endl;
break;
}
}
fout << "final, 2015: " << totalval[emp][0] << endl;
fout << "final, 2016: " << totalval[emp][1] << endl;
fout << "final, 2017: " << totalval[emp][2] << endl;
fout << "total: " << totalval[emp][3] << endl;
fout << "Average: " << totalval[emp][4] << endl;
fout << "salary: " << totalval[emp][5] << endl;
fout << "in percent: " << totalval[emp][6] << endl;
fout << "in dollar: " << totalval[emp][7] << endl;
fout << "both: " << totalval[emp][8] << endl;
if(totalval[emp][4] < 70)
{
fout << mystring [emp][7] << endl;
fout << endl;
}
else if(totalval[emp][4] >= 95)
{
fout << mystring[emp][8] << endl;
}
}
}
|