Question

In: Computer Science

Write a program in C to process weekly employee timecards for all employees of an organization...

Write a program in C to process weekly employee timecards for all employees of an organization (ask the user number of employees in the start of the program). Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week.A tax amount of 3.625% of gross salary will be deducted. The program output should show the identification number and net pay. Display the total payroll and the average amount paid at the end of the run.
Make a simple program without using classes.

Solutions

Expert Solution

#include <stdio.h>
#include <stdlib.h>


/* declare functions */

/* Get the employee data */
void get_employee_data(FILE* fp,int* id, float* rate, float* hours);

/* Calculate gross pay */
float calc_gross_pay(float rate, float hours);


/* Calculate net pay */
float calc_net_pay(float gross_pay);


/* Display results */
void display(FILE* fp,int id, float net_pay);


int main()
{
int id; /* employee identification */
float rate; /* hourly wage */
float hours; /* hours worked */
float gross_pay; /* gross pay */
float net_pay; /* net pay */
float total_payroll=0; /* total payroll */
float average_payroll=0; /* total payroll */
int nums=0; /* number employees */

FILE *fpin; /* read file pointer */
FILE *fpout; /* write file pointer */

fpin = fopen("employees.in","r"); /* open file for reading */

/* check if file open */
if(fpin == NULL)
{
printf("file 'employees.in' cannot be opened for reading\n");
exit(1); /* close all file streams and terminate */
}

fpout = fopen("employees.out","w"); /* open file for writing */

/* check if file open */
if(fpout == NULL)
{
printf("file 'employees.out' cannot be opened for writing\n");
exit(1); /* close all file streams and terminate */
}

/* read employees in loop */

/* Get the employee data */
get_employee_data(fpin,&id, &rate, &hours);

while(!feof(fpin))
{
nums++; /* count employees */

/* Calculate gross pay */
gross_pay = calc_gross_pay(rate, hours);


/* Calculate net pay */
net_pay = calc_net_pay(gross_pay);

/* sum totals */
total_payroll = total_payroll + net_pay;

/* Display results */
display(fpout,id, net_pay);

/* get next employee data */
get_employee_data(fpin,&id, &rate, &hours);

}

/* close read file */
fclose(fpin);

/* caculate average payents */
average_payroll = total_payroll / nums;

/* print total */
fprintf(fpout,"\nTotal Payroll: %.2f Average Payroll: %.2f\n",total_payroll, average_payroll);
printf("\nTotal Payroll: %.2f Average Payroll: %.2f\n",total_payroll, average_payroll);

/* close write file */
fclose(fpout);

return 0;
}


/* Get the employee data */
void get_employee_data(FILE* fp,int* id, float* rate, float* hours)
{

/* get employee id */
fscanf(fp,"%d",id);

/* get employee id */
fscanf(fp,"%f",rate);

/* get employee id */
fscanf(fp,"%f",hours);

}


/* Calculate gross pay */
float calc_gross_pay(float rate, float hours)
{
float gross_pay = 0;

if(hours <= 40)
gross_pay = rate * hours;
else
gross_pay = rate * 40 + (hours - 40) * rate * 1.5f;

return gross_pay;
}

/* Calculate net pay */
float calc_net_pay(float gross_pay)
{

float tax = 3.625* gross_pay;

float net_pay = gross_pay - tax;

return net_pay;
}

/* Display results */
void display(FILE* fp, int id, float net_pay)
{

fprintf(fp,"%d %.2f\n",id,net_pay);
printf("%d %.2f\n",id,net_pay);
}


Related Solutions

Write a program to process weekly employee time cards for all employees of an organization. Each...
Write a program to process weekly employee time cards for all employees of an organization. Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week. Each employee is to be paid time and a half for all hours worked over 40. A tax amount of 3.625% of gross salary will be deducted. The program output should show the employee’s number and net pay. Display the total...
EMPLOYEE (Inheritance) Write a program that maintains wage information for the employees of a company. The...
EMPLOYEE (Inheritance) Write a program that maintains wage information for the employees of a company. The following example shows what the user will see during a session with the program: N: New employee P: Compute paychecks R: Raise wages L: List all employees Q: Quit Enter command: n Enter name of new employee: Plumber, Phil Hourly (h) or salaried (s): h Enter hourly wage: 40.00 (Note: Do Not VALIDATE) N: New employee P: Compute paychecks R: Raise wages L: List...
An important tactic for retaining employees is a good employee recognition program within the organization. Here...
An important tactic for retaining employees is a good employee recognition program within the organization. Here we what to examine how common they are in small (and large) businesses. With that in mind, you interview 376 of each kind. You find that 278 of the small organizations said they have an employee recognition program, while 316 of the large ones said they have an employee recognition program. We are trying to prove that larger organizations are more likely to have...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
Write a program of doubly Circular linked list to maintain records of employees. Take employee ID,...
Write a program of doubly Circular linked list to maintain records of employees. Take employee ID, name and salary as data of each employee. Search a particular record on ID and display the previous and next records as well. Whichever ID it give, it should display all the records because of being circular. Code needed in Java.
It is common for an organization to have different categories of employees, such that one Employee...
It is common for an organization to have different categories of employees, such that one Employee class can not easily describe all types of Employees.In this project, you will code a basic Employee class, and then a number of classes which derive from the Employee class (inherit), adding Employee specifics. An application program which stores info for one company will have use objects of different types to model the all employees. Part I:   The Employee Class First create the Employee...
Write a C++ program that uses all the relational operators.
Write a C++ program that uses all the relational operators.
You will write a C program to fork a child process. The child process will print...
You will write a C program to fork a child process. The child process will print the current time/date. The parent will wait for the child to complete. Here is how you can programmatically call the Linux date command from a C program. execlp("/bin/date","date",NULL); Your C file should be named myfork.c The binary will be named myfork.
About the organization: This fictional organization has a small, but growing, employee base, with 50 employees...
About the organization: This fictional organization has a small, but growing, employee base, with 50 employees in one small office. The company is an online retailer of the world's finest artisanal, hand-crafted widgets. They've hired you on as a security consultant to help bring their operations into better shape. Organization requirements: As the security consultant, the company needs you to add security measures to the following systems: An external website permitting users to browse and purchase widgets An internal intranet...
Write a C++ program that uses array to store the salaries of 10 employees working in...
Write a C++ program that uses array to store the salaries of 10 employees working in a small firm. The program should take average of the salaries and the max and min salaries being paid to the employees
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT