Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.47 KB | None | 0 0
  1. /* put your name here!; CSCI 112; say online or TTh section */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /* your #defines go here */
  6.  
  7. double hourlyRate = 20.00
  8. double tax = .07
  9. double comissionBasePay = 600.00
  10.  
  11. /* function prototypes */
  12. void initialize(double *totalNet);
  13. void printHeader(void);
  14. void hourly(int id, double hours, double *totalNet);
  15. void commission(int id, double sales, double *totalNet);
  16. void piecework(int id, double sales, double *totalNet);
  17. void calcTaxNet(double grossPay, double penalty, double *tax, double *netPay);
  18. void printSummary(double totalNet);
  19.  
  20. /* Payroll.c:  Produce weekly payroll.  Lab 3 */
  21. void main(void)
  22. {
  23.     char   type;     // employee type
  24.     int    id;       // employee ID
  25.     double num,      // employee productivity info
  26.            totalNet; // total of all net pays, for summary info
  27.     FILE *fp;
  28.  
  29.     initialize(&totalNet); // sets totalNet to 0.0
  30.  
  31.     fp = fopen("Payroll.dat", "r"); // open the data file
  32.     if (fp == NULL) {
  33.         printf("Payroll.dat file not found.\n");
  34.         exit(1);
  35.     }
  36.     printHeader(); // prints column headers
  37.     while (!feof(fp)) {                // loop until every employee processed
  38.         // reads info for next employee
  39.         fscanf(fp, "%d %c %lf\n", &id, &type, &num);
  40.  
  41.         if (type == 'H')
  42.             hourly(id, num, &totalNet); // prints line for hourly
  43.         else if (type == 'P')
  44.             piecework(id, num, &totalNet); // prints line for piecework
  45.         else
  46.             commission(id, num, &totalNet); // prints line for commission
  47.     }
  48.     fclose(fp);
  49.     printSummary(totalNet); // prints summary info at foot of table
  50. }
  51.  
  52. void initialize(double *totalNet)
  53. {
  54.     totalNet = 0.0;
  55. }
  56.  
  57. void printHeader(void)
  58. {
  59.     printf("%5s %10s %10s %10s %5s %5s \n", "ID", "Gross", "Penalty", "Tax", "Net", "Comment");
  60.     printf("%5s %10s %10s %10s %5s %5s \n", "____", "_______", "________", "_______", "____", "____");
  61. }
  62.  
  63. void hourly(int id, double hours, double *totalNet)
  64. {
  65.     *totalNet = hourlyRate * hours;
  66.      printf("%5s %10s %10s", id , totalNet , "0.00",);
  67.     calcTaxNet(*totalNet, 0.00, *tax, *totalNet);
  68.     printf("%6s", *totalNet);
  69.    
  70.     if(hours > 40.0)
  71.     {
  72.         printf("%10s", "Overtime")
  73.     }
  74.    
  75.     printf("\n");
  76.    
  77. }
  78.  
  79. void commission(int id, double sales, double *totalNet)
  80. {
  81.     dobule comissionPercentage;
  82.     double penalty;
  83.    
  84.     if(sales >= 5000)
  85.         comissionPercentage = .05;
  86.     if(sales >= 3000 && sales < 5000)
  87.         comissionPercentage = .03;
  88.     if(sales > 2000 && sales < 3000)
  89.         comissionPercentage = .02;
  90.     else
  91.         comissionPercentage = .00;
  92.    
  93.     if(sales < 1000)
  94.         penalty = 50.00;
  95.     else penalty = 0.00
  96.    
  97.         *totalNet = comissionBasePay + ( sales * comissionPercentage) - penalty;
  98.     printf("%5s %10s %10s", id , totalNet , penalty);
  99.    
  100.     calcTaxNet;
  101.    
  102.     printf("%6s", *totalNet);
  103.     if(sales < 1000)
  104.         printf("%10s", "Low sales");
  105.     printf("\n");
  106.  
  107.        
  108. }
  109.  
  110. void piecework(int id, double sales, double *totalNet)
  111. {
  112.     calcTaxNet;
  113. }
  114.  
  115. void calcTaxNet(double grossPay, double penalty, double *tax, double *netPay)
  116. {
  117.     double taxWithheld;
  118.     taxWithHeld = grossPay - (penalty - *tax);
  119.     printf("%5s", taxWithheld);
  120.     *totalNet = totAlNet - taxWithheld;
  121.    
  122. }
  123.  
  124. void printSummary(double totalNet)
  125. {
  126.     printf("%5s %10s %10s %10s %5s %5s \n", "____", "_______", "________", "_______", "____", "____");
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement