I have no idea where to go from here.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lafayettejohnson
    New Member
    • Jul 2010
    • 7

    I have no idea where to go from here.

    I am trying to write this program, it is a payroll report. This is as far as I got, I am now completly stuck.Any help or tips would be greatly apreciated. This is what the output is suppose to look like.

    Pay Hours Gross Income FICA Net Employee
    Rate Worked Pay Tax Tax Pay Name
    ===== ====== ====== ====== ===== ====== =============== =
    10.45 38.00 397.10 26.16 30.38 340.56 Greene, Ross
    12.00 42.00 516.00 89.42 39.47 387.11 Kristner, Mary
    9.99 30.50 304.69 36.34 23.31 245.05 Nicholson, Mellisa
    11.57 40.00 462.80 63.49 35.40 363.91 Woodley, Samuel
    ====== ====== ====== ===== ======
    Totals 150.50 1680.59 215.41 128.57 1336.62
    here is the code
    Code:
    #include <fstream> 
    #include <iostream> 
    #include "weekemp.h" 
    #include "compfun.h" 
    
    int main()
    {
      weeklyEmp anEmp;
      string fName, lName, name;
      double hours, rate;
      int exempts;
      string status;
      
      ifstream inFile("employee.dat");
    
      
      if(! inFile)
      {
        cout << "**Error opening file 'employee.dat'" << endl;
      }
      else
      {
        
        decimals(cout, 2);
        cout << " Pay  Hours Gross Income FICA Net Employee" << endl;
        cout << "Rate Worked   Pay    Tax  Tax Pay Name" << endl;
        cout << "====== =====  ===== ====== ===== =======" << endl;
        
        while(inFile >> fName >> lName >> hours >> rate >> exempts >> status)
        {
          name = lName + ", " + fName;
          anEmp = weeklyEmp(name, hours, rate, exempts, status);
          
          cout.width(9);
    	  cout << rate << hours << anEmp.grossPay() << " " << anEmp.name() << endl;
        }
    	
      }
    
      return 0;
    }
    these files also go with it but they are ok
    Code:
    //--------------------------------------------------------------------
    // IMPLEMENTATION FILE: weekemp.cpp
    //
    // Implements: 1. class weeklyEmp
    //             2. cout << weeklyEmp
    //             3. cin >> weeklyEmp
    //       Note: This file is automatically included by ouremp.h
    //--------------------------------------------------------------------
    
    #include <iostream>   // for cout, cin, istream, ostream
    #include <cmath>      // for floor
    #include "string"     // for class string
    
    
    #include "compfun.h"    // for decimals(cout, 2) and round (tax, 2)
    #include "weekemp.h"
    
    // The value of WEEKLY_ALLOWANCE has changed almost every year so the
    // named constant must be checked every year for proper maintenance
    // Use IRS publication Circular E, Employer's Tax Guide each new year.
    const double WEEKLY_ALLOWANCE = 39.42;
    const int    MAX_EXEMPTIONS = 99;
    const double FICA_TAX_RATE = 0.0765;
    
    //--constructors
    
    weeklyEmp::weeklyEmp()
    { // Default constructor used to allow for arrays.
      my_name = " ?name? ";
      my_hours = 0.00;
      my_rate = 0.00;
      my_exemptions = 0;
      my_filingStatus = "?status?";
    }
    
    weeklyEmp::weeklyEmp(string initName,
                         double initHours,
                         double initRate,
                         int    initExemptions,
                         string initStatus)
    { // Five argument constructor
      my_name = initName;
      my_hours = initHours;
      my_rate = initRate;
    
      my_exemptions = initExemptions;
      if((my_exemptions < 0) || (my_exemptions > MAX_EXEMPTIONS))
      {
    	  cout << "**Error** Exemptions for "
             << initName << " == " << initExemptions << endl;
        cout << "Exemptions must be in the range of 0.." << MAX_EXEMPTIONS
             << endl;
        cout << "**Program Terminated**"
             << endl;
       
      }
      
      if(initStatus == "s" || initStatus == "S")
        my_filingStatus = "S";
      if(initStatus == "m" || initStatus == "M")
        my_filingStatus = "M";
      if ( ! (my_filingStatus == "S" || my_filingStatus == "M") )
      {
        cout << "Filing Status for " << initName << " == " << my_filingStatus
             << endl;
        cout << "Status must be one of these four strings \"s\", \"S\", \"m\", or \"M\""
             << endl;
        cout << "Terminating program"
             << endl;
       
      }
    }
    
    
    
    
    //--modifiers
    
    void weeklyEmp::set_hours(double thisWeeksHours)
    { // post: set the hours worked for a given week
      my_hours = thisWeeksHours;
    }
    
    
    void weeklyEmp::set_rate(double thisWeeksRate)
    {
      my_rate = thisWeeksRate; 
    }
    
    // -- accessors
    double weeklyEmp::grossPay()  const
    {
      double result(0.0);
    
      if(my_hours <= 40)
    	 result = my_hours * my_rate;
      else
    	 result = 40 * my_rate + 1.5 * my_rate * (my_hours - 40);
    
      // round to the nearest penny
      result = round(result, 2);
      
      return result;
    }
    
    double weeklyEmp::incomeTax()  const
    {
      double result(0.0);
      double taxableIncome(grossPay() - my_exemptions * WEEKLY_ALLOWANCE);
    
      if(my_filingStatus == "S")
      {
    	 if (taxableIncome <= 23.00)
    		result = 0.00;
        else if(taxableIncome <= 397.00)
          result = 0.15 * (taxableIncome - 23.00);
        else if(taxableIncome <= 928.00)
          result = 56.10 + 0.28 * (taxableIncome - 397.00);
        else if(taxableIncome <= 2121.00)
          result = 204.78 + 0.33 * (taxableIncome - 928.00);
        else
          result = 598.47 + 0.28 * (taxableIncome - 2121.00);
      }
    
      if(my_filingStatus == "M")
      {
        if(taxableIncome <= 65.00)
          result = 0.00;
        else if(taxableIncome <= 689.00)
          result = 0.15 * (taxableIncome - 65.00);
        else if(taxableIncome <= 1573.00)
          result = 93.60 + 0.28 * (taxableIncome - 689.00);
        else if(taxableIncome <= 3858.00)
          result = 341.12 + 0.33 * (taxableIncome - 1573.00);
        else
          result = 1095.17 + 0.28 * (taxableIncome - 3858.00);
      }
    
      // round to the nearest penny
      result = round(result, 2);
      
      return result;
    }
    
    double weeklyEmp::FICATax()  const
    {
      double result(FICA_TAX_RATE * grossPay());
    
      // round to the nearest penny
      result = round(result, 2);
      return result;
    }
    
    string weeklyEmp::name()  const
    {
      return my_name;
    }
    
    
    bool operator <  (const weeklyEmp& left, const weeklyEmp& right)
    {
       return (left.name() < right.name());  // string defines <
    }
    
    bool operator == (const weeklyEmp& left, const weeklyEmp& right)
    {
       return (left.name() == right.name()); // string defines ==
    }
    
    bool operator <= (const weeklyEmp& left, const weeklyEmp& right)
    {
       return (left.name() <= right.name()); // string defines <=
    }
    
    bool operator >= (const weeklyEmp& left, const weeklyEmp& right)
    {
       return (left.name() >= right.name()); // string defines >=
    }
    
    bool operator > (const weeklyEmp& left, const weeklyEmp& right)
    {
       return (left.name() > right.name()); // string defines >
    }
    
    bool operator != (const weeklyEmp& left, const weeklyEmp& right)
    {
       return (left.name() != right.name()); // string defines >
    }
    Code:
    #ifndef WEEKEMP_H
    #define WEEKEMP_H    // ensure the class definition is compiled only once
    #include <iostream>  // for class ostream and istream
    #include "string"    // for class string
    #include "bool"
    
    ////////////////////////////////////////////////////////////////////
    //// Define class weeklyEmp ////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////
    
    class weeklyEmp {
    public: 
    //--constructors
      weeklyEmp();
    
      weeklyEmp(string initName,  
                double initHours, 
                double initRate,
                int initExemptions, 
                string initFilingStatus );
      // post: A weeklyEmp object is initialized with 5 arguments like this:
      //         weeklyEmp anEmp("Hall, Rob", 40.0, 9.75, 3, "M");
      //       The fourth argument must be in the range of 0 to 99
      //       The last argument is either "M" for married or "S" for single
    
      weeklyEmp(const weeklyEmp & source);
      // This copy sonctructor is discussed in Chapter 10: Pointers
    
    //--modifiers
      void set_hours(double thisWeeksHours);
      // post: set the hours worked for a given week
    
      void set_rate(double thisWeeksRate);
      // post: change the employees hourly rate of pay 
    //--accessors
      double grossPay() const;
      // post: return gross pay with overtime
    
      double incomeTax() const;
      // post: return the federal income tax
    
      double FICATax() const;
      // post: return the social security tax
    
      string name() const;
      // post: return the employee's name
    
     private: 
      string my_name;
      double my_hours;
      double my_rate;
      int my_exemptions;
      string my_filingStatus;
    };
    
    //--auxilary functions 
    
    bool operator <  (const weeklyEmp& left, const weeklyEmp& right);
    // Return true if left's name alphabetically precedes right's name 
    
    bool operator == (const weeklyEmp& left, const weeklyEmp& right);
    // Return true if left's name is equal to right's name (case sensitive)
    
    // The file weekemp.cpp includes compfun so you'll also get 
    // the other four relational operators >, <=, >=, and !=
    
    #endif
    and this is the employee.dat file

    Ross Greene 38.0 10.45 4 M
    Mary Kristner 42.0 12.00 0 S
    Mellisa Nicholson 30.5 9.99 1 S
    Samuel Woodley 40.0 11.57 1 S
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I suggest you write your main() first. Then based on what you need in main() you can design your class and member functions.

    You should not have code in ytour class that is not used by anybody.

    For example:

    Code:
    int main()
    {
       Person p;
    }
    All you need is a Person class with nothing in it.

    So code it, re-compile and verify your code works.

    Code:
    int main()
    {
       Person p;
    
       p.SetSSN("123-456-7890");
    }
    Now you need a SetSSN member function that takes a string argument. So code it. Re-compile and verify the program still works.

    Keep gradually building up the main(). When you are done the code will work and Person will have the minimum number of member functions and data.

    Comment

    • lafayettejohnson
      New Member
      • Jul 2010
      • 7

      #3
      I have to bulid the main from using the other two files.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        The number of files is not relevant.

        If you want your Person class in a Person.h that you #include in the file with main() and the membr functions in a Person.cpp, then that does not alter the fact that you should be coding main() first and then adding features to your Person class as you need those features.

        Comment

        Working...