473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1. #include <fstream> 
  2. #include <iostream> 
  3. #include "weekemp.h" 
  4. #include "compfun.h" 
  5.  
  6. int main()
  7. {
  8.   weeklyEmp anEmp;
  9.   string fName, lName, name;
  10.   double hours, rate;
  11.   int exempts;
  12.   string status;
  13.  
  14.   ifstream inFile("employee.dat");
  15.  
  16.  
  17.   if(! inFile)
  18.   {
  19.     cout << "**Error opening file 'employee.dat'" << endl;
  20.   }
  21.   else
  22.   {
  23.  
  24.     decimals(cout, 2);
  25.     cout << " Pay  Hours Gross Income FICA Net Employee" << endl;
  26.     cout << "Rate Worked   Pay    Tax  Tax Pay Name" << endl;
  27.     cout << "====== =====  ===== ====== ===== =======" << endl;
  28.  
  29.     while(inFile >> fName >> lName >> hours >> rate >> exempts >> status)
  30.     {
  31.       name = lName + ", " + fName;
  32.       anEmp = weeklyEmp(name, hours, rate, exempts, status);
  33.  
  34.       cout.width(9);
  35.       cout << rate << hours << anEmp.grossPay() << " " << anEmp.name() << endl;
  36.     }
  37.  
  38.   }
  39.  
  40.   return 0;
  41. }
these files also go with it but they are ok
Expand|Select|Wrap|Line Numbers
  1. //--------------------------------------------------------------------
  2. // IMPLEMENTATION FILE: weekemp.cpp
  3. //
  4. // Implements: 1. class weeklyEmp
  5. //             2. cout << weeklyEmp
  6. //             3. cin >> weeklyEmp
  7. //       Note: This file is automatically included by ouremp.h
  8. //--------------------------------------------------------------------
  9.  
  10. #include <iostream>   // for cout, cin, istream, ostream
  11. #include <cmath>      // for floor
  12. #include "string"     // for class string
  13.  
  14.  
  15. #include "compfun.h"    // for decimals(cout, 2) and round (tax, 2)
  16. #include "weekemp.h"
  17.  
  18. // The value of WEEKLY_ALLOWANCE has changed almost every year so the
  19. // named constant must be checked every year for proper maintenance
  20. // Use IRS publication Circular E, Employer's Tax Guide each new year.
  21. const double WEEKLY_ALLOWANCE = 39.42;
  22. const int    MAX_EXEMPTIONS = 99;
  23. const double FICA_TAX_RATE = 0.0765;
  24.  
  25. //--constructors
  26.  
  27. weeklyEmp::weeklyEmp()
  28. { // Default constructor used to allow for arrays.
  29.   my_name = " ?name? ";
  30.   my_hours = 0.00;
  31.   my_rate = 0.00;
  32.   my_exemptions = 0;
  33.   my_filingStatus = "?status?";
  34. }
  35.  
  36. weeklyEmp::weeklyEmp(string initName,
  37.                      double initHours,
  38.                      double initRate,
  39.                      int    initExemptions,
  40.                      string initStatus)
  41. { // Five argument constructor
  42.   my_name = initName;
  43.   my_hours = initHours;
  44.   my_rate = initRate;
  45.  
  46.   my_exemptions = initExemptions;
  47.   if((my_exemptions < 0) || (my_exemptions > MAX_EXEMPTIONS))
  48.   {
  49.       cout << "**Error** Exemptions for "
  50.          << initName << " == " << initExemptions << endl;
  51.     cout << "Exemptions must be in the range of 0.." << MAX_EXEMPTIONS
  52.          << endl;
  53.     cout << "**Program Terminated**"
  54.          << endl;
  55.  
  56.   }
  57.  
  58.   if(initStatus == "s" || initStatus == "S")
  59.     my_filingStatus = "S";
  60.   if(initStatus == "m" || initStatus == "M")
  61.     my_filingStatus = "M";
  62.   if ( ! (my_filingStatus == "S" || my_filingStatus == "M") )
  63.   {
  64.     cout << "Filing Status for " << initName << " == " << my_filingStatus
  65.          << endl;
  66.     cout << "Status must be one of these four strings \"s\", \"S\", \"m\", or \"M\""
  67.          << endl;
  68.     cout << "Terminating program"
  69.          << endl;
  70.  
  71.   }
  72. }
  73.  
  74.  
  75.  
  76.  
  77. //--modifiers
  78.  
  79. void weeklyEmp::set_hours(double thisWeeksHours)
  80. { // post: set the hours worked for a given week
  81.   my_hours = thisWeeksHours;
  82. }
  83.  
  84.  
  85. void weeklyEmp::set_rate(double thisWeeksRate)
  86. {
  87.   my_rate = thisWeeksRate; 
  88. }
  89.  
  90. // -- accessors
  91. double weeklyEmp::grossPay()  const
  92. {
  93.   double result(0.0);
  94.  
  95.   if(my_hours <= 40)
  96.      result = my_hours * my_rate;
  97.   else
  98.      result = 40 * my_rate + 1.5 * my_rate * (my_hours - 40);
  99.  
  100.   // round to the nearest penny
  101.   result = round(result, 2);
  102.  
  103.   return result;
  104. }
  105.  
  106. double weeklyEmp::incomeTax()  const
  107. {
  108.   double result(0.0);
  109.   double taxableIncome(grossPay() - my_exemptions * WEEKLY_ALLOWANCE);
  110.  
  111.   if(my_filingStatus == "S")
  112.   {
  113.      if (taxableIncome <= 23.00)
  114.         result = 0.00;
  115.     else if(taxableIncome <= 397.00)
  116.       result = 0.15 * (taxableIncome - 23.00);
  117.     else if(taxableIncome <= 928.00)
  118.       result = 56.10 + 0.28 * (taxableIncome - 397.00);
  119.     else if(taxableIncome <= 2121.00)
  120.       result = 204.78 + 0.33 * (taxableIncome - 928.00);
  121.     else
  122.       result = 598.47 + 0.28 * (taxableIncome - 2121.00);
  123.   }
  124.  
  125.   if(my_filingStatus == "M")
  126.   {
  127.     if(taxableIncome <= 65.00)
  128.       result = 0.00;
  129.     else if(taxableIncome <= 689.00)
  130.       result = 0.15 * (taxableIncome - 65.00);
  131.     else if(taxableIncome <= 1573.00)
  132.       result = 93.60 + 0.28 * (taxableIncome - 689.00);
  133.     else if(taxableIncome <= 3858.00)
  134.       result = 341.12 + 0.33 * (taxableIncome - 1573.00);
  135.     else
  136.       result = 1095.17 + 0.28 * (taxableIncome - 3858.00);
  137.   }
  138.  
  139.   // round to the nearest penny
  140.   result = round(result, 2);
  141.  
  142.   return result;
  143. }
  144.  
  145. double weeklyEmp::FICATax()  const
  146. {
  147.   double result(FICA_TAX_RATE * grossPay());
  148.  
  149.   // round to the nearest penny
  150.   result = round(result, 2);
  151.   return result;
  152. }
  153.  
  154. string weeklyEmp::name()  const
  155. {
  156.   return my_name;
  157. }
  158.  
  159.  
  160. bool operator <  (const weeklyEmp& left, const weeklyEmp& right)
  161. {
  162.    return (left.name() < right.name());  // string defines <
  163. }
  164.  
  165. bool operator == (const weeklyEmp& left, const weeklyEmp& right)
  166. {
  167.    return (left.name() == right.name()); // string defines ==
  168. }
  169.  
  170. bool operator <= (const weeklyEmp& left, const weeklyEmp& right)
  171. {
  172.    return (left.name() <= right.name()); // string defines <=
  173. }
  174.  
  175. bool operator >= (const weeklyEmp& left, const weeklyEmp& right)
  176. {
  177.    return (left.name() >= right.name()); // string defines >=
  178. }
  179.  
  180. bool operator > (const weeklyEmp& left, const weeklyEmp& right)
  181. {
  182.    return (left.name() > right.name()); // string defines >
  183. }
  184.  
  185. bool operator != (const weeklyEmp& left, const weeklyEmp& right)
  186. {
  187.    return (left.name() != right.name()); // string defines >
  188. }
  189.  
  190.  
Expand|Select|Wrap|Line Numbers
  1. #ifndef WEEKEMP_H
  2. #define WEEKEMP_H    // ensure the class definition is compiled only once
  3. #include <iostream>  // for class ostream and istream
  4. #include "string"    // for class string
  5. #include "bool"
  6.  
  7. ////////////////////////////////////////////////////////////////////
  8. //// Define class weeklyEmp ////////////////////////////////////////
  9. ////////////////////////////////////////////////////////////////////
  10.  
  11. class weeklyEmp {
  12. public: 
  13. //--constructors
  14.   weeklyEmp();
  15.  
  16.   weeklyEmp(string initName,  
  17.             double initHours, 
  18.             double initRate,
  19.             int initExemptions, 
  20.             string initFilingStatus );
  21.   // post: A weeklyEmp object is initialized with 5 arguments like this:
  22.   //         weeklyEmp anEmp("Hall, Rob", 40.0, 9.75, 3, "M");
  23.   //       The fourth argument must be in the range of 0 to 99
  24.   //       The last argument is either "M" for married or "S" for single
  25.  
  26.   weeklyEmp(const weeklyEmp & source);
  27.   // This copy sonctructor is discussed in Chapter 10: Pointers
  28.  
  29. //--modifiers
  30.   void set_hours(double thisWeeksHours);
  31.   // post: set the hours worked for a given week
  32.  
  33.   void set_rate(double thisWeeksRate);
  34.   // post: change the employees hourly rate of pay 
  35. //--accessors
  36.   double grossPay() const;
  37.   // post: return gross pay with overtime
  38.  
  39.   double incomeTax() const;
  40.   // post: return the federal income tax
  41.  
  42.   double FICATax() const;
  43.   // post: return the social security tax
  44.  
  45.   string name() const;
  46.   // post: return the employee's name
  47.  
  48.  private: 
  49.   string my_name;
  50.   double my_hours;
  51.   double my_rate;
  52.   int my_exemptions;
  53.   string my_filingStatus;
  54. };
  55.  
  56. //--auxilary functions 
  57.  
  58. bool operator <  (const weeklyEmp& left, const weeklyEmp& right);
  59. // Return true if left's name alphabetically precedes right's name 
  60.  
  61. bool operator == (const weeklyEmp& left, const weeklyEmp& right);
  62. // Return true if left's name is equal to right's name (case sensitive)
  63.  
  64. // The file weekemp.cpp includes compfun so you'll also get 
  65. // the other four relational operators >, <=, >=, and !=
  66.  
  67. #endif
  68.  
  69.  
  70.  
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
Jul 30 '10 #1
3 1773
weaknessforcats
9,208 Expert Mod 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.    Person p;
  4. }
All you need is a Person class with nothing in it.

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

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.    Person p;
  4.  
  5.    p.SetSSN("123-456-7890");
  6. }
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.
Jul 31 '10 #2
I have to bulid the main from using the other two files.
Aug 1 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
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.
Aug 2 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
8
by: sebb | last post by:
I'm kind of newbie to programming, but I thought of something and I want some opinions on that. It's about a new instruction block to do some cycles. I thought about that because it's not very...
29
by: Jim Hubbard | last post by:
Yet another hotfix alert (http://www.kbalertz.com/Feedback_823535.aspx) that states "To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix." ...
11
by: Christopher Benson-Manica | last post by:
#include <vector> class Bar; class Foo { friend class Bar; /* 1 */ protected: int myint;
5
by: Hugo Elias | last post by:
Hi all, I have an idea for a better IDE. Though I don't have the skills required to write such a thing, if anyone's looking for a killer app, maybe this is it. If I'm typing at a rate of 10...
4
by: GiladP1 | last post by:
Hi, I want to copy protect my application. I want to limit its use for a given period of time, say 30 days, after which a license key will be needed. There are various issues to consider here...
15
by: jcrouse | last post by:
Here is my code: Dim sw As StreamWriter = File.CreateText(Application.StartupPath & "\mameversion.bat") sw.WriteLine(lblMameExePath.Text & " -help >""" & Application.StartupPath &...
22
by: Rob R. Ainscough | last post by:
Sorry to hear about the job cuts and Oracle now out sourcing to India. Rob.
21
by: petermichaux | last post by:
Hi, I've been asking questions about library design over the last week and would like to get feedback on my overall idea for a JavaScript GUI library. I need a nice GUI library so there is a...
5
by: mike3 | last post by:
Hi. Is this a good idea?: <begin code> /* Addition operator: += */ const BigFix &BigFix::operator+=(const BigFix &rhs) { ErrorType err; int lhs_sign = sign, rhs_sign = rhs.sign;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.