I tried to write the function myself for a switch statement that would take a char and multiply it by a certain amount and then return the total. I'm a little confused on how the object gets passed to the case function. But here's what I got.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int MAX_FACULTY = 500;
ifstream inFile;
struct Employee
{
string name;
char rank;
int hours;
double rankPay;
};
int readData(Employee faculty[]);
double calcOverload(Employee faculty[], int numFaculty);
void print(Employee faculty[], int numFaculty);
int main()
{
Employee faculty[MAX_FACULTY];
int numFaculty;
double rankPay;
numFaculty = readData(faculty);
rankPay = calcOverload(faculty, numFaculty);
print(faculty, numFaculty);
}
int readData(Employee faculty[])
{
inFile.open("overload.txt");
int count = 0;
while(inFile.peek() !=EOF)
{
inFile >> faculty[count].name >> faculty[count].rank >> faculty[count].hours;
count++;
inFile.ignore(1);
}
inFile.close();
return count;
}
double calcOverload(Employee faculty[], int numFaculty)
{
char rank;
for (int i=0; i<numFaculty; i++)
switch(rank)
{
case 'F':
case 'f':
faculty.rankPay = faculty[i].hours * 990;
break;
case 'S':
case 's':
faculty.rankPay = faculty[i].hours * 895;
break;
case 'A':
case 'a':
faculty.rankPay = faculty[i].hours * 780;
break;
default:
faculty.rankPay = faculty[i].hours * 655;
}
return rankPay;
}
void print(Employee faculty[], int numFaculty, double rankPay)
{
for (int i=0; i<numFaculty; i++)
cout << faculty[i].name << faculty[i].rank << faculty[i].hours << rankPay[i].hours << endl;
}