Question: Modify this by replacing all arrays by one array of structures. You will use nested structures. Array should be passed to functions through Parameters/arguments. #include
Modify this by replacing all arrays by one array of structures. You will use nested structures. Array should be passed to functions through Parameters/arguments.
#include #include #include #include
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; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
