Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* put your name here!; CSCI 112; say online or TTh section */
- #include <stdio.h>
- #include <stdlib.h>
- /* your #defines go here */
- double hourlyRate = 20.00
- double tax = .07
- double comissionBasePay = 600.00
- /* function prototypes */
- void initialize(double *totalNet);
- void printHeader(void);
- void hourly(int id, double hours, double *totalNet);
- void commission(int id, double sales, double *totalNet);
- void piecework(int id, double sales, double *totalNet);
- void calcTaxNet(double grossPay, double penalty, double *tax, double *netPay);
- void printSummary(double totalNet);
- /* Payroll.c: Produce weekly payroll. Lab 3 */
- void main(void)
- {
- char type; // employee type
- int id; // employee ID
- double num, // employee productivity info
- totalNet; // total of all net pays, for summary info
- FILE *fp;
- initialize(&totalNet); // sets totalNet to 0.0
- fp = fopen("Payroll.dat", "r"); // open the data file
- if (fp == NULL) {
- printf("Payroll.dat file not found.\n");
- exit(1);
- }
- printHeader(); // prints column headers
- while (!feof(fp)) { // loop until every employee processed
- // reads info for next employee
- fscanf(fp, "%d %c %lf\n", &id, &type, &num);
- if (type == 'H')
- hourly(id, num, &totalNet); // prints line for hourly
- else if (type == 'P')
- piecework(id, num, &totalNet); // prints line for piecework
- else
- commission(id, num, &totalNet); // prints line for commission
- }
- fclose(fp);
- printSummary(totalNet); // prints summary info at foot of table
- }
- void initialize(double *totalNet)
- {
- totalNet = 0.0;
- }
- void printHeader(void)
- {
- printf("%5s %10s %10s %10s %5s %5s \n", "ID", "Gross", "Penalty", "Tax", "Net", "Comment");
- printf("%5s %10s %10s %10s %5s %5s \n", "____", "_______", "________", "_______", "____", "____");
- }
- void hourly(int id, double hours, double *totalNet)
- {
- *totalNet = hourlyRate * hours;
- printf("%5s %10s %10s", id , totalNet , "0.00",);
- calcTaxNet(*totalNet, 0.00, *tax, *totalNet);
- printf("%6s", *totalNet);
- if(hours > 40.0)
- {
- printf("%10s", "Overtime")
- }
- printf("\n");
- }
- void commission(int id, double sales, double *totalNet)
- {
- dobule comissionPercentage;
- double penalty;
- if(sales >= 5000)
- comissionPercentage = .05;
- if(sales >= 3000 && sales < 5000)
- comissionPercentage = .03;
- if(sales > 2000 && sales < 3000)
- comissionPercentage = .02;
- else
- comissionPercentage = .00;
- if(sales < 1000)
- penalty = 50.00;
- else penalty = 0.00
- *totalNet = comissionBasePay + ( sales * comissionPercentage) - penalty;
- printf("%5s %10s %10s", id , totalNet , penalty);
- calcTaxNet;
- printf("%6s", *totalNet);
- if(sales < 1000)
- printf("%10s", "Low sales");
- printf("\n");
- }
- void piecework(int id, double sales, double *totalNet)
- {
- calcTaxNet;
- }
- void calcTaxNet(double grossPay, double penalty, double *tax, double *netPay)
- {
- double taxWithheld;
- taxWithHeld = grossPay - (penalty - *tax);
- printf("%5s", taxWithheld);
- *totalNet = totAlNet - taxWithheld;
- }
- void printSummary(double totalNet)
- {
- printf("%5s %10s %10s %10s %5s %5s \n", "____", "_______", "________", "_______", "____", "____");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement