(Solved) : Include Cout Include Files Include Using Namespace Std Struct Employee String Fname Employ Q37561380 . . .
#include //for cout
#include //for files
#include
using namespace std;
struct employee
{
string fname; //employee first name
string lname; //employee last name
char gender; //employee gender
double hourly; //hourly pay rate
int ID; //employee ID number
int age; //employee age
};
const int SIZE = 100; //declare constant SIZE
//prototypes
void readData(employee mAr[], employee fAr[], int& mi, int&fi);
void printEmployee(const employee& size);
void printAllEmp(const employee ar[], int size);
void outfileArray(const employee ar[], int size);
employee findOldest(const employee ar[], int size);
void giveRaise(employee ar[], int size, double raise);
void giveRaiseOneEmployee(employee& size, double raise);
int main()
{
employee mAr[SIZE]; //declare an array for male employees(the instructions refer to these arrays)
employee fAr[SIZE]; //declare an array for female employees
int male; //male employees
int female; //female employees
employee oldest; // oldest employee
cout << fixed << setprecision(2); //setting decimalplaces to two for all outputs
cout << endl <<“———————-readData()————————–“<< endl;
readData(mAr, fAr, male, female); //call readData in main todisplay the number of males and females
cout << “There are ” << male << ” male and “<< female << ” female employees.” << endl;//display number of males and females
cout << endl <<“———————-printEmployee()———————“<< endl;
printEmployee(fAr[0]); //call printEmployee to show first femaleemployee in the female array
cout << endl <<“———————-printEmployee()———————“<< endl;
printEmployee(mAr[0]); //call printEmployee to show first maleemployee in the male array
cout << endl <<“———————-printAllEmp()———————–“<< endl;
printAllEmp(mAr, male); //call printAllEmp function to print allthe employees in the male array to the screen
cout << endl <<“———————-printAllEmp()———————–“<< endl;
printAllEmp(fAr, female); //call printAllEmp function to printall the employees in the female array to the screen
cout << endl <<“———————-outfileArray()———————-“<< endl;
outfileArray(mAr, male); //call outfileArray to output the lastand first names of all the employees from the male array to theoutput file the user specifies
cout << endl <<“———————-outfileArray()———————-“<< endl;
outfileArray(fAr, female); //call outfileArray to output thelast and first names of all the employees from the female array tothe output file the user specifies
cout << endl <<“———————-findOldest()————————“<< endl;
oldest = findOldest(mAr, male); //finds the oldest male employeein the list
cout << oldest.fname << endl; //displays the name ofthe oldest employee in the male array
cout << endl <<“———————-giveRaise()————————-“<< endl;
giveRaise(mAr, male, 5.0); //raise percentage is passed to thisfunction as one of the parameters and give the raise to everybodyin the male array
printAllEmp(mAr, male); //call printAllEmp function to print allthe employees in the male array to the screen
cout << endl <<“———————-giveRaise()————————-“<< endl;
giveRaise(fAr, female, 5.5); //raise percentage is passed tothis function as one of the parameters and give the raise toeverybody in the female array
printAllEmp(fAr, female); //call printAllEmp function to print allthe employees in the male array to the screen
cout << endl <<“———————-giveRaiseOneEmployee()————–“<< endl;
giveRaiseOneEmployee(fAr[1], 2.0); //raise percentage passed tothe second employee in the female array
printEmployee(fAr[1]); //call printAllEmp function to print theemployee receiving a raise in the female array to the screen
cout << endl <<“———————-giveRaiseOneEmployee()————–“<< endl;
giveRaiseOneEmployee(mAr[0], 50.0); //raise percentage passed tothe second employee in the male array
printEmployee(mAr[0]); //call printAllEmp function to print theemployee receiving a raise in the female array to the screen
cout << endl;
return 0;
}
/*********************************************************************
readData
*********************************************************************/
void readData(employee mAr[], employee fAr[], int& mi,int& fi)
{
mi = 0; //index to the male array
fi = 0; //index to the female array
//create names for the input and output files:
ifstream fin; //make name for the input file
ofstream fout; //creating a name for the output file
fin.open(“employees.dat”); //open the input file
//if the inout file does not exist…
if (!fin) //if(fin == NULL)
{
cout << “Cannot open the input file” << endl;
}
else //the input file exists
{
employee temp;
fin >> temp.fname;
fin >> temp.lname;
fin >> temp.gender;
fin >> temp.hourly;
fin >> temp.ID;
fin >> temp.age;
while (fin && mi < SIZE && fi < SIZE)//while male index and female index are below the value of SIZE
{
if (temp.gender == ‘F’) //if female
fAr[fi++] = temp; //copy all the fields from tempto the female array
else if (temp.gender == ‘M’) //if gender
mAr[mi++] = temp; //copy all the fields from tempto the male array
fin >> temp.fname;
fin >> temp.lname;
fin >> temp.gender;
fin >> temp.hourly;
fin >> temp.ID;
fin >> temp.age;
}
}
}
/*********************************************************************
printEmployee
*********************************************************************/
void printEmployee(const employee& size)
{
//output display neatly
cout << left << setw(10) << size.fname << “” << setw(10) << size.lname << ” ” <<setw(10) << size.gender << ” ” << setw(10)<< size.hourly << ” ” << setw(10) <<size.ID << ” ” << setw(10) << size.age <<endl;
}
/*********************************************************************
printAllEmp (the instructions refer to thisfunction)
*********************************************************************/
void printAllEmp(const employee ar[], int size)
{
for (int i = 0; i < size; i++)
{
printEmployee(ar[i]); //prints all employees
}
}
/*********************************************************************
outfileArray
*********************************************************************/
void outfileArray(const employee ar[], int size)
{
string fname; //first name of the employee
cout << “Enter the output file name: “; //prompts user forouput file name
cin >> fname;
ofstream fout;
fout.open(fname.c_str()); //a new file will be created
for (int i = 0; i < size; i++) //loop displays array of lastamd first names
{
fout << ar[i].lname << “, ” << ar[i].fname<< endl;
}
fout.close();
}
/*********************************************************************
findOldest
*********************************************************************/
employee findOldest(const employee ar[], int size)
{
int largest = 0; //largest value in the array set to zero
for (int i = 1; i < size; i++) //for loop finds largestvalue
{
if (ar[largest].age < ar[i].age)
largest = i;
}
return ar[largest]; //return the largest value
}
/*********************************************************************
giveRaise
*********************************************************************/
void giveRaise(employee ar[], int size, double raise)
{
for (int i = 0; i < size; i++) //for loop calculating theraise for each employee based on hourly rate
ar[i].hourly = ar[i].hourly + (ar[i].hourly * (raise /100.00));
}
/*********************************************************************
giveRaiseToOneEmployee
*********************************************************************/
void giveRaiseOneEmployee(employee& size, double raise)
{
//calculates the raise for one employee based on hourly rate
size.hourly = size.hourly + (size.hourly * (raise /100.00));
}
Ada Agusta F 10.00 19569 28
Issac Asimov M 18.25 63948 58
Humphry Bogart M 20.00 48482 56
Albert Einstein M 11.10 47474 67
Emmylou Harris F 33.50 72647 38
James Kirk M 18.85 82828 46
Ted Kopple M 22.25 37376 48
David Letterman M 15.50 19338 47
Stevis Nicks F 18.85 23459 38
Monty Python M 33.35 80939 44
Roger Rabbit M 15.00 91343 24
Sally Ride F 25.50 91123 30
Rod Serling M 55.50 93939 56
Luke Skywalker M 19.95 12343 35
Kit Ross F 11.00 20000 21
Mike Smith M 23.35 10000 30
We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageHere is the content of employees.dat: C) C) Thank you in advance for any help! Show transcribed image text
Expert Answer
Answer to Include Cout Include Files Include Using Namespace Std Struct Employee String Fname Employ Q37561380 . . .
OR