Using a structure, and creating three structure variables; write a C++ program t
ID: 3571885 • 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. with screenshot plz
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.
datafile.txt
name: Bob Mcgnor
course: computer science
date 11/11/11
Explanation / Answer
#include <iostream>
using namespace std;
struct emp
{
int employees_jd;
double hrworked_jd;
double payrate_jd;
double total_pay;
};
struct emp administrative[10];
struct emp office[10];
struct emp field[10],temp;
void hours_worked(struct emp hr[])
{
for(int i=0;i<2;i++)
{
cout <<i+1 <<". Enter hours worked: ";
cin>>hr[i].hrworked_jd;
}
}
void payrate(struct emp rate[])
{
for(int i=0;i<2;i++)
{
cout <<i+1 <<". Enter payrate: ";
cin>>rate[i].payrate_jd;
}
}
double total(double pay,struct emp hr[])
{
for(int i=0;i<2;i++)
if(hr[i].hrworked_jd>40)
return (((hr[i].hrworked_jd-40)/5)*(pay*0.1)+pay);
else
return pay;
}
void print(struct emp ad[])
{
int i;
cout <<"Employee ID Hour Worked Pay Rate Total Pay"<<endl;
for(i=0;i<2;i++)
cout <<ad[i].employees_jd<<" "<<ad[i].hrworked_jd<<" "<<ad[i].payrate_jd<<" "<<ad[i].total_pay<<endl;
}
void sort(struct emp ad[])
{
for (int i = 1; i < 2; i++)
{
for (int j =0; j < 2-i; j++)
{
if (ad[j].employees_jd>ad[j+1].employees_jd)
{
temp = ad[j];
ad[j] = ad[j+1];
ad[j+1] = temp;
}
}
}
}
int main()
{
cout<<"Admistrative"<<endl;
for(int i=0;i<2;i++)
{
cout << i+1<<".Enter employee id: ";
cin>>administrative[i].employees_jd;
}
hours_worked(administrative);
payrate(administrative);
for(int i=0;i<2;i++)
{
basepay[i]=administrative[i].hrworked_jd*administrative[i].payrate_jd;
administrative[i].total_pay=total(basepay[i],administrative);
}
sort(administrative);
cout <<"Adminstrative"<<endl;
print(administrative);
return 0;
}
rest part i will post you in comments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.