Using a structure, and creating three structure variables; write a C++ program t
ID: 3780360 • Letter: U
Question
Using a structure, and creating three structure variables; write a C++ program that will calculate the total pay for thirty (30) employees. (Ten for each structured variable.) Sort the list of employees by the employee ID in ascending order and display their respective information.
Description - DataType - Members
Employee IDs - of INT - employees_jd
Hours Worked - of DOUBLE - hrworked_jd
Pay Rate - of DOUBLE - payrate_jd
Total Pay - of Double - total_pay
------------------------------------------------Array size
administrative - structure - variable -10
office - structure - variable -------------10
field - structure - variable ---------------10
Excluding the main function, your program should have five additional functions that will get the hours worked, and payrate, calculate the total pay, sort the data and display your output.
Base payshould be calculated by multiplying the regular hours worked by pay rate.If a person has worked over forty (40)hours, total pay is calculated by an adding10% ofbase pay for every five (5) hours over forty (40)to base pay.(ie a person working 50 hours with a total pay of $100 would have ((hours-40)/5)*(base pay*.1)+ base pay.
But this time create a file (datafile) that has your full name, Course name and Date on the first three lines. Write the program to open the output file in append mode and write your output to this file. When the execution of your C++ is complete, your output file should contain your name, course name and date followed by the 10 employee records including their total pay.
name: Bob Mcgnor
course: computer science
date 11/11/11
Explanation / Answer
Answer:
//include the needed header files
#include <iostream>
#include<fstream>
#include<string>
using namespace std;
//STRUCTURE DEFINITION
struct EMPINFO
{
int myEMPID;
double WrkdHrs;
double bsePayRt;
double talPay;
};
EMPINFO adminEMPS[10],officeEMPS[10],fieldEMPS[10];
//get HOURS WORKED
void getHrWorked(struct EMPINFO* temp,int id)
{
double myWrkHrs;
int id;
for(int aa=0;aa<10;aa++)
{
cout<<"EMTER ID";
cin>>id;
cout<<"Enter WORKED HOURS:";
cin>>myWrkHrs;
temp[aa].WrkdHrs=myWrkHrs;
temp[aa].myEMPID=id;
}
}
//GET BASE PAY RATE
void getBasePayRat(struct EMPINFO* temp)
{
double myRt;
for(int aa=0;aa<10;aa++)
{
cout<<"Enter Payrate";
cin>>myRt;
temp[aa].bsePayRt=myRt;
}
}
//Calculate total-pay
void calculatePay(struct EMPINFO* temp)
{
for(int aa=0;aa<10;aa++)
{
temp[aa].talPay=(temp[aa].bsePayRt*temp[aa].WrkdHrs);
if(temp[aa].WrkdHrs>40)
temp[aa].talPay+=((temp[aa].WrkdHrs-40)/5)*(temp[aa].talPay*0.1);
}
}
void sortEMPINFO(struct EMPINFO* temp)
{
struct EMPINFO swapEMPS;
for(int aa=0;aa<10;aa++)
{
for(int bb=aa+1;bb<10;bb++)
{
if(temp[aa].myEMPID > temp[bb].myEMPID)
{
swapEMPS=temp[aa];
temp[aa]=temp[bb];
temp[bb]=swapEMPS;
}
}
}
}
//display EMPSINFO
void displayEMPSINFO(struct EMPINFO* temp)
{
for(int aa=0;aa<10;aa++)
{
cout<<temp[aa].myEMPID<<" "<<temp[aa].WrkdHrs<<" "<<temp[aa].bsePayRt<<" "<<temp[aa].talPay<<endl;
}
}
//main
int main()
{
fstream fID;
fID.open("outfile.txt",ios::app);
//read total WORKED HOURS for all employees
cout<<"READING ADMIN EMPLOYEES WORKED HOURS: "<<endl;
getHrWorked(adminEMPS);
cout<<"READING OFFICE EMPLOYEES WORKED HOURS: "<<endl;
getHrWorked(officeEMPS);
cout<<"READING FIELD EMPLOYEES WORKED HOURS: "<<endl;
getHrWorked(fieldEMPS);
//READING BASE RATE
cout<<"READING ADMIN EMPLOYEES BASE RATE: "<<endl;
getBasePayRat(adminEMPS);
cout<<"READING OFFICE EMPLOYEES BASE RATE: "<<endl;
getBasePayRat(officeEMPS);
cout<<"READING FIELD EMPLOYEES BASE RATE: "<<endl;
getBasePayRat(fieldEMPS);
//CALCULATING TOTAL PAY
cout<<" CALCULATING TOTAL PAY for ADMIN EMPLOYEES : "<<endl;
calculatePay(adminEMPS);
cout<<" CALCULATING TOTAL PAY for OFFICE EMPLOYEES: "<<endl;
calculatePay(officeEMPS);
cout<<" CALCULATING TOTAL PAY for EMPLOYEES: "<<endl;
calculatePay(fieldEMPS);
//SORT
sortEMPINFO(adminEMPS);
sortEMPINFO(officeEMPS);
sortEMPINFO(fieldEMPS);
//display
displayEMPSINFO(adminEMPS);
displayEMPSINFO(officeEMPS);
displayEMPSINFO(fieldEMPS);
if(fID.is_open())
{
fID<<"Name:XXXX"<<endl;
fID<<"Course:Computer Science"<<endl;
fID<<"Date:12/02/2016"<<endl;
//writing to file
for(int aa=0;aa<10;aa++)
{
fID<<adminEMPS[aa].myEMPID<<" "<<adminEMPS[aa].WrkdHrs<<" "<<adminEMPS[aa].bsePayRt<<" "<<adminEMPS[aa].talPay<<endl;
}
for(int aa=0;aa<10;aa++)
{
fID<<officeEMPS[aa].myEMPID<<" "<<officeEMPS[aa].WrkdHrs<<" "<<officeEMPS[aa].bsePayRt<<" "<<officeEMPS[aa].talPay<<endl;
}
for(int aa=0;aa<10;aa++)
{
fID<<fieldEMPS[aa].myEMPID<<" "<<fieldEMPS[aa].WrkdHrs<<" "<<fieldEMPS[aa].bsePayRt<<" "<<fieldEMPS[aa].talPay<<endl;
}
fID.close();
}
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.