home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / BROWSER / PAYROLL.CPP < prev   
C/C++ Source or Header  |  1993-04-30  |  4KB  |  141 lines

  1. /* @(#)25    1.3  src/samples/payroll.cpp, samples, brs110, 930429 92/11/20 22:04:12 */
  2.  
  3. /*******************************************************
  4. *** payroll.cpp main source file for example program ***
  5. *******************************************************/
  6. #include <iostream.h>    // Include file for C++ input and
  7.                          //output operations.
  8. #include "payclass.h"     // Include file for class definitions.
  9. #include "payfunc.h"      // Include file for function definitions.
  10.  
  11. void payout(double);           // Declaration of function
  12.                                // prototype.
  13. void payout(double, double);   // Declaration of overloaded
  14.                    // function prototype.
  15. void payout(double, double, double);   // Declaration of another
  16.                                        // overloaded
  17.                        // function prototype.
  18.  
  19. inline void title()          // Example of defining
  20.                              // an inline function.
  21. {
  22.   cout << "Monthly Employee Pay Report\n\n";
  23. };
  24.  
  25. void main()                 // Start of main function.
  26. {
  27.  
  28. // Assigning values to variables, use const so
  29. // a program could not inadvertantly change a value.
  30.   const double managers_pay = 1510.35;
  31.   const double reg_emp_pay = 25.75;
  32.   const double reg_emp_hrs = 40.00;
  33.   const double sales_mgr_pay = 880.75;
  34.   const double sales_mgr_commission = 1.15;
  35.   const double sales_mgr_units = 200;
  36.   const double monthly_salary = 800.00;
  37.   const double commission = 1.00;
  38.   const double units = 150;
  39.  
  40. // Use the functions in cout to set the decimal places
  41. // in the output.
  42.    cout.setf(ios::fixed);
  43.    cout.precision(2);
  44.  
  45. // Use the inline function title.
  46.   title();
  47.  
  48. // Use the payout function.
  49.   payout(managers_pay);
  50.  
  51. // Use the overloaded payout function.
  52.   payout(reg_emp_pay, reg_emp_hrs);
  53.  
  54. //Use another overloaded payout function.
  55.   payout(monthly_salary, commission, units);
  56.  
  57. //A place to put in a security feature
  58.   char val;
  59.   cout << "To view data on employees, "
  60.        << "type your password and press Enter: ";
  61.   cin >> val ;
  62.  
  63. // Define an instance, smith, of class manager.
  64.   manager smith("Jack Smith", 123, 28020);
  65.  
  66. // Do position and print functions for this instance.
  67.   smith.position();
  68.   smith.print();
  69.  
  70. // Define an instance, james, of class regular_emp.
  71.   regular_emp james("Everett James", 456, 12,160) ;
  72.  
  73. // Do position and print functions for this instance.
  74.   james.position();
  75.   james.print();
  76.  
  77. // Define an instance, doe, of class sales_person.
  78.   sales_person doe("Jackson Doe", 101, 31,65);
  79.  
  80. // Do position and print functions for this instance.
  81.   doe.position();
  82.   doe.print() ;
  83.  
  84. // Define an instance, stevens, of class sales_mgr.
  85.   sales_mgr stevens("Jennifer Stevens", 789, 28000, 4, 105) ;
  86.  
  87. // Do position and print functions for this instance.
  88.   stevens.position();
  89.   stevens.print();
  90.  
  91. // Declaring variables where they are to be used.
  92.   double sal1, sal2, sal3, sal4;
  93.  
  94.   sal1 = smith.pay();
  95.   sal2 = james.pay();
  96.   sal3 = doe.pay();
  97.   sal4 = stevens.pay();
  98.  
  99. // Use the values returned from the pay functions.
  100.  
  101.   cout << "Total wages paid this month were: "
  102.        << (sal1+sal2+sal3+sal4)
  103.        << " dollars\n\n";
  104. };
  105. // End of main function
  106.  
  107. // Definition of payout functions (declared
  108. // as prototypes before main). 
  109.  
  110. // Example of an overloaded function. 
  111.  
  112. // One argument
  113.   void payout(double managers_pay)
  114. {
  115.   cout << "The basic salary for a manager is: "
  116.        << managers_pay << " dollars per month.\n\n";
  117. };
  118.  
  119. // Two arguments:
  120.   void payout(double reg_emp_pay, double reg_emp_hrs)
  121. {
  122.   double  reg_monthly_pay;
  123.   reg_monthly_pay = reg_emp_pay * reg_emp_hrs;
  124.  
  125.   cout << "The basic pay for a regular employee is "
  126.        << reg_monthly_pay  << " dollars per month.\n\n ";
  127. };
  128.  
  129. // Three arguments:
  130.   void payout(double monthly_salary, 
  131.           double commission, double units)
  132. {
  133.   double reg_monthly_pay;
  134.   reg_monthly_pay = (monthly_salary + (commission*units));
  135.  
  136.   cout << "The basic pay for a sales manager is "
  137.        << reg_monthly_pay  << " dollars per month.\n\n ";
  138. };
  139.  
  140. /**************** End of payroll.cpp ****************************/
  141.