Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program which will retrive and maipulate data from a company\'s payrol

ID: 663154 • Letter: W

Question

Write a C program which will retrive and maipulate data from a company's payroll database file named "payfile.txt" The data for each employee should be read into a struct containing the following field identifiers:

first, 7 character max. initial, 1 character max. last, 9 characters max. street, 16 characters max. city, 11 characters max. state, 2 characters max. zip, 5 characters max. age, integer. sex, 1 character max. tenure, integer. salary, double.

Each section should be designed within its own fucntion, passing parameters as necessary. The program should perform each of the following operations:

a) Read data for employees into an array of structures

b) output the contents of each structure into an easily read format, similar to the format of the input file.

c) output the first and last name of all men on the payroll.

d) output the first and last name of the highest paid woman on the payroll.

e) output the first and last name of the lowest paid man on the payroll.

f) output the average salary of all employess.

g) output the first and last name of all women earning less than the average.

h) output the ratio of the number of men above the average salary to the number of men below the average salary.

i) output the first and last name of all employess who make more than $35,000 per year, have been with the company for at least 5 years, and who are over 30 years old.

j) give a 10% raise to all employees who make less than $350.00 per week and output the first and last name and new salary for each employee who received the raise.

k) sort the structures according to zip codes and output the first and last name and zipcode for each employee.

Assume the following declaration:

#define MAX 100

Use the following function that grabs a substring.

void strsub(char buf[], char sub[], int start, int end){

     int i,j;

     for (j=0, i=start; i<=end; i++, j++){

          sub[j] = buf[i];

     }

     sub[j] = '';

}

The contents of payfile.txt:

Please submit a sample screen output from your submission.

Explanation / Answer

#include <stdio.h>

struct Employee{
char first[10],last[9],street[16],city[11],state[2],zip[5];
char initial[1],sex[1];
int age,tenure;
double salary;
};

void readData(FILE *fp,struct Employee emp[]){
int i=0;
char buildingNo[30];
char street1[10],street2[10];
while (!feof(fp)) {
fscanf(fp,"%s",emp[i].first);
printf(" %s",emp[i].first);
fscanf(fp,"%s",emp[i].initial);
fscanf(fp,"%s",emp[i].last);
fscanf(fp,"%s",&buildingNo);
fscanf(fp,"%s",&street1);
fscanf(fp,"%s",&street2);
strcat(buildingNo,street1);
strcat(buildingNo,street2);
strcpy(emp[i].street,buildingNo);
fscanf(fp,"%s",emp[i].city);
fscanf(fp,"%s",emp[i].state);
fscanf(fp,"%s",emp[i].zip);
fscanf(fp,"%d",&emp[i].age);
fscanf(fp,"%s",emp[i].sex);
fscanf(fp,"%d",&emp[i].tenure);
fscanf(fp,"%f",&emp[i].salary);
i+=1;
}
}

void displayData(struct Employee emp[]){
int i;
for(i=0;i<14;i++){
printf("%s %s %s %s %s %s %s %d %s %d %f ",emp[i].first,emp[i].initial,emp[i].last,emp[i].street,emp[i].city,emp[i].state,emp[i].zip,emp[i].age,emp[i].sex,emp[i].tenure,emp[i].salary);
}
}

void outputFirstAndLastName(struct Employee emp[]){
int i;
for(i=0;i<14;i++){
printf("%s %s ",emp[i].first,emp[i].last);
}
}

void highestPaidWoman(struct Employee emp[]){
int i,pos;
double highest=0.0;
for(i=0;i<14;i++){
if(strcmp(emp[i].sex,"F")==0){
if(emp[i].salary>highest){
highest=emp[i].salary;
pos=i;
}
}
}
printf("Name of highest paid woman %s %s",emp[pos].first,emp[pos].last);
}

void lowestPaidMan(struct Employee emp[]){
int i,pos;
double lowest=emp[0].salary;
for(i=0;i<14;i++){
if(strcmp(emp[i].sex,"M")==0){
if(emp[i].salary<lowest){
lowest=emp[i].salary;
pos=i;
}
}
}
printf("Name of lowest paid man %s %s",emp[pos].first,emp[pos].last);
}

void averageSalary(struct Employee emp[]){
int i;
double avg,sum=0.0;
for(i=0;i<14;i++){
sum+=emp[i].salary;
}
avg=sum/14;
printf("Average salary of all employees %f ",avg);
}

void womanEarningLessThanAvg(struct Employee emp[]){
int i;
double avg,sum=0.0;
for(i=0;i<14;i++){
sum+=emp[i].salary;
}
avg=sum/14;
for(i=0;i<14;i++){
if(strcmp(emp[i].sex,"F")==0){
if(emp[i].salary<avg){
printf("Name of woman earning less than average %s %s",emp[i].first,emp[i].last);
}
}
}
}

int main(){
struct Employee emp[14];
FILE *fp;
fp = fopen("d:\payfile.txt", "r");

if (fp == NULL) {
fprintf(stderr, "Can't open input file ");
exit(1);
}
readData(fp,emp);
displayData(emp);
outputFirstAndLastName(emp);
highestPaidWoman(emp);
lowestPaidMan(emp);
averageSalary(emp);
womanEarningLessThanAvg(emp);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote