Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-05-2004, 03:08 PM   #1 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Overtime project

This question is for Valmont. Would the pacheck.cpp help that you gave me; would it help with this one? Cause the output almost seems similiar I think we are just adding on the calculation of overtime?

CSIS 121 Introduction to Computer Science

Project OVERTIME




Write a program that does a payroll calculation for employees that get time and one/half for any work over 40 hours per week and double time for any work over 48 hours per week.



Interactive input:

Enter employee number: _

Enter hours worked : _



File input:
The employee’s employee number, name and pay rate are in a file called “MasterFile.dat”

Format of the data in the file:



employeeNumber ‘\t’ employeeName ‘\t’ payRate



employeeNumber is a 7 digit integer.

employeeName is a string with embedded blanks

payRate is a floating point value



Output format:

Employee Hours Pay Regular Premium Gross Net Federal State

Number Name Worked Rate Pay Pay Pay Pay Tax Tax

1234567 Joe Smith ##.# ##.## ###.## ###.## ###.## ###.## ###.## ###.##



Calculations
Federal tax is 33% of the gross pay

State tax is 6% of the gross pay



Exceptions:

If the file “MasterFile.dat” is not found or opened, display an error message and quit.



Validate the data read from the MasterFile. i.e. Make sure the employee number in the file matches the number entered interactively. If the employee numbers do not match, display an error message and quit.



Notes:

To declare a storage location for a persons’ name write this declaration:

char name[64];

:p
verdell32 is offline   Reply With Quote
Old 12-06-2004, 05:05 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
I can't remember that file. What project was it?
__________________
Valmont is offline   Reply With Quote
Old 12-06-2004, 12:37 PM   #3 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
paycheck no has to be overtime

it was called pacheck.cpp, but I think this time we have to add the if and else statments in the code.

// Program Documentation //////////////////////////////////////////////////////
//
// Project Name : PAYCHECK
//
// Source File : paycheck.cpp
//
// Programmed By :
//
// Last Revision : 10/12/2004
//
// Version Number: 0.1
//
// Program Description ////////////////////////////////////////////////////////
//
// This program calculates employees pay rate, hours worked, gross pay, net pay
// federal tax, state tax and will output to screen.
///////////////////////////////////////////////////////////////////////////////

// Include Files //////////////////////////////////////////////////////////////
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

// Function Prototypes ////////////////////////////////////////////////////////

// Program Mainline ///////////////////////////////////////////////////////////

int main( )
{
const double FEDERAL_TAX_RATE = .33;
const double STATE_TAX_RATE = 0.06;

char employeeName[64];
double federalTax;
double grossPay;
double hoursWorked;
double netPay;
double payRate; //stores employee's pay rate as a real number
double stateTax;

//input data
cout << "Enter employee name:";
cin.getline( employeeName, sizeof( employeeName ));
cout << "Enter pay rate:";
cin >> payRate;
cout << "Enter hours worked:";
cin >> hoursWorked;

//calculations
grossPay = hoursWorked * payRate;
federalTax = grossPay * FEDERAL_TAX_RATE;
stateTax = grossPay * STATE_TAX_RATE;
netPay = grossPay - federalTax + stateTax;


//output results
cout.setf(ios::fixed,ios::floatfield);
cout.precision( 2 ); //output 2 decimal places
const int fw = 10;

cout << "================================================= ==============================" << endl;
cout << "Employee Hours Federal State" << endl;
cout << "Name Worked Pay Rate Gross Pay Net Pay Tax Tax" << endl;
cout.setf(ios::left,ios::adjustfield);
cout << setw(fw + 9) << employeeName;
cout.setf(ios::right,ios::adjustfield);
cout << setw(fw)<< hoursWorked;
cout << setw(fw)<< payRate;
cout << setw(fw)<< grossPay;
cout << setw(fw)<< netPay;
cout << setw(fw)<< federalTax;
cout << setw(fw)<< stateTax;
cout << "" << endl;

cout << "================================================= ===============================" << endl;

getch();
return 0;
}//endmn
verdell32 is offline   Reply With Quote
Old 12-07-2004, 12:10 PM   #4 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
This is code I have so far

I think I have this one figured out but now I can't figure out how to line up the output correctly since I have added the 2 new entries(Regular pay and Premium pay)?

Code:
// Program Documentation //////////////////////////////////////////////////////
//
// Project Name  : OVERTIME
//
// Source File   : overtime.cpp
//
// Programmed By : Shang Fields
//
// Last Revision : 12/6/2004
//
// Version Number: 0.1
//
// Program Description ////////////////////////////////////////////////////////
//
// This program
//
///////////////////////////////////////////////////////////////////////////////

// Include Files //////////////////////////////////////////////////////////////
   #include <iostream.h>
   #include <conio.h>
   #include <iomanip.h>
// Function Prototypes ////////////////////////////////////////////////////////

// Program Mainline ///////////////////////////////////////////////////////////

int main( )
{
   const double FEDERAL_TAX_RATE = .33;
   const double STATE_TAX_RATE = 0.06;
   const double MAX_HOURS = 1.5;
   const double OVERTIME = 40.0;

   char employeeNumber[64];
   char employeeName[64];
   double federalTax;
   double grossPay;
   double hoursWorked;
   double regularPay;
   double premiumPay;
   double netPay;
   double payRate;  //stores employee's pay rate as a real number
   double stateTax;


   //input data
   cout << "Enter employee number:";
   cin.getline( employeeNumber, sizeof( employeeNumber ));
   cout << "Enter employee name:";
   cin.getline( employeeName, sizeof( employeeName ));
   cout << "Enter pay rate:";
   cin >> payRate;
   cout << "Enter hours worked:";
   cin >> hoursWorked;

   //calculations
   grossPay = hoursWorked * payRate;
   federalTax = grossPay * FEDERAL_TAX_RATE;
   stateTax = grossPay * STATE_TAX_RATE;
   netPay = grossPay - federalTax + stateTax;

   // CalcPay computes wages from the employee's pay rate
// and the hours worked, taking overtime into account

   if ( hoursWorked > MAX_HOURS ) {
      grossPay = (MAX_HOURS * payRate) +        // Yes
                (hoursWorked - MAX_HOURS) * payRate * OVERTIME;
               }else{
                  grossPay = hoursWorked * payRate;               // No
   }//endif

   //output results
   cout.setf(ios::fixed,ios::floatfield);
   cout.precision( 2 ); //output 2 decimal places
   const int fw = 10;
   
   cout << "===============================================================================" << endl;
   cout << "Employee        Hours                                                          Federal  State" << endl;
   cout << "Number  Name   Worked   Pay Rate Regular pay Premium Pay Gross Pay  Net Pay      Tax    Tax" << endl;
   cout.setf(ios::left,ios::adjustfield);
   cout << setw(fw + 9) << employeeNumber;
   cout << setw(fw + 9) << employeeName;
   cout.setf(ios::right,ios::adjustfield);
   cout << setw(fw)<< hoursWorked;
   cout << setw(fw)<< payRate;
   cout << setw(fw)<< regularPay;
   cout << setw(fw)<< premiumPay;
   cout << setw(fw)<< grossPay;
   cout << setw(fw)<< netPay;
   cout << setw(fw)<< federalTax;
   cout << setw(fw)<< stateTax;
   cout << "" << endl;

   cout << "================================================================================" << endl;
   getch();
   return 0;
}//endmn

Last edited by Valmont; 12-08-2004 at 12:44 AM.
verdell32 is offline   Reply With Quote
Old 12-08-2004, 01:04 AM   #5 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Quote:
Output format:

Employee Hours Pay Regular Premium Gross Net Federal State

Number Name Worked Rate Pay Pay Pay Pay Tax Tax

1234567 Joe Smith ##.# ##.## ###.## ###.## ###.## ###.## ###.## ###.##
The output doesn't fit in a bash or console. I don't understand what your teachers wants. No matter how I fiddle, it always will look ugly.
And why is he learning an outdated style by the way?
__________________
Valmont is offline   Reply With Quote
Old 12-08-2004, 03:45 AM   #6 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Good question Valmont

Like I said before in the paycheck project I finally figured it out and everything was even in the output; but with these new entries everything is off. If you know of a better way to make it all come out even; then please help me. I will use your method to make the out put even. At least this first class is over this week and then I move onto "Object-oriented programming".

Note: If you can help me with your style of output; then I still have to keep the "box" around the output. Sometime I think I should have started with a "Visual Basic Class" before I jumped into C++?

Last edited by verdell32; 12-08-2004 at 03:48 AM. Reason: update
verdell32 is offline   Reply With Quote
Old 12-08-2004, 07:56 AM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Do it with tabs then:


Code:
#include <iostream>
#include <string>
#include <climits>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;
using std::numeric_limits;
using std::streamsize;
using std::string;
using std::ios;

//Optional function: depends on IDE. Remove if not needed.
void wait_for_enter();

//Additional helper. Remove if not needed.
void reset_istream();

//--
const double FEDERAL_TAX_RATE = .33;
const double STATE_TAX_RATE = 0.06;
const double MAX_HOURS = 1.5;
const double OVERTIME = 40.0;

int main(int argc, char *argv[])
{
  char employeeNumber[64];
  char employeeName[64];
  double federalTax;
  double grossPay;
  double hoursWorked;
  double regularPay;
  double premiumPay;
  double netPay;
  double payRate;  //stores employee's pay rate as a real number
  double stateTax;

  //input data
  cout << "Enter employee number:";
  cin.getline( employeeNumber, sizeof( employeeNumber ));
  cout << "Enter employee name:";
  cin.getline( employeeName, sizeof( employeeName ));
  cout << "Enter pay rate:";
  cin >> payRate;
  cout << "Enter hours worked:";
  cin >> hoursWorked;

  //calculations
  grossPay = hoursWorked * payRate;
  federalTax = grossPay * FEDERAL_TAX_RATE;
  stateTax = grossPay * STATE_TAX_RATE;
  netPay = grossPay - federalTax + stateTax;

  // CalcPay computes wages from the employee's pay rate
  // and the hours worked, taking overtime into account
  if ( hoursWorked > MAX_HOURS )
  {
    grossPay = (MAX_HOURS * payRate) + (hoursWorked - MAX_HOURS) * payRate * OVERTIME;
  }
  else
  {
    grossPay = hoursWorked * payRate;
  }

  //output results
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision( 2 ); //output 2 decimal places

  cout << "================================================================================" << endl;
  cout << "Employee\tHours\tPay\tRegular\tPremium\tGross\tNet\tFederal\tState"<<endl;
  cout << "number\tname\tworked\tRate\tpay\tpay\tpay\tpay\ttax\ttax"<<endl;
  
  cout << employeeNumber;
  cout << '\t' << employeeName;
  cout << '\t' << hoursWorked;
  cout << '\t' << payRate;
  cout << '\t' << regularPay;
  cout << '\t' << premiumPay;
  cout << '\t' << grossPay;
  cout << '\t' << netPay;
  cout << '\t' << federalTax;
  cout << '\t' << stateTax;
  
  cout << endl;
  cout << "================================================================================" << endl;
  
  reset_istream();
  wait_for_enter();
  return 0;
}


//---------------------------------------------------

void reset_istream()
{
   if(cin.eof())
   {
      cin.clear();
   }
   else
   {
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(), '\n');
   }
}

//---------------------------------------------------

void wait_for_enter()
{
  cout << "press <enter> to continue...";
  // Reset failstate, just in case.
  cin.clear();
  string line;
  getline( cin, line);
}
__________________
Valmont is offline   Reply With Quote
Old 12-08-2004, 07:51 PM   #8 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Talking I apologize(Valmont)

First of all I would like to apologize but, my teacher sprung on us today that he wants the program to do something a little bit different. I really like the way that you got the stuff even. I say truly that I appreciate all the help you are giving me (Valmont) you help me through my first class. I only have two more projects (timeDiff and phonebill) thank God and then I will be moving on to Object oriented programming


1. User enter the employee number; then that will find the employee name and the employee pay rate

so in this program we are supposed to use the "while Loop" and the if/else statements.

This is the example that he gave us:

#include <iostream>
#include <fstream>

int main
int accountNum, searchItem;
char name[30]

cout << "Enter account number:";
cin >> searchItem;

ifstream accountFile("account.lst", iso::in);
accountFile>>accountNum; //primary input

while(!accountFile.eof() searchItem! =
accountNum){
accountFile.ignore(80; '\n' );
accountFile >> accountNum; //continuing input

}//endwh

if(searchItem == accountNum){
accountFile.getline(name, sizeof(name)-1);
cout << accountNum << " " << name << endl;

{else}
cout << "Account" << searchItem <<
"not found!" << endl;

}//endif
return 0
}//endmn

Thank you very much,
D.O.C.

This is not due to Monday(12-13-04). If you have anytime I would appreciate the help.
verdell32 is offline   Reply With Quote
Old 12-09-2004, 03:13 AM   #9 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
So how is the *.lst file organized? His code does not convince me.
__________________
Valmont is offline   Reply With Quote
Old 12-09-2004, 05:15 AM   #10 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Master.dat file

I think he "*.lst" has something to do with a master.dat" file because when he showed us yesterday; he opened it up in Notepad and it had a "list of employee's numbers, payrate, etc.
verdell32 is offline   Reply With Quote
Old 12-09-2004, 07:20 AM   #11 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Oh, I see, the one like in your first post.
__________________
Valmont is offline   Reply With Quote
Old 12-09-2004, 11:17 AM   #12 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Thumbs up This is true

Correct Now I have to figure out what to change/how to approach this?
verdell32 is offline   Reply With Quote
Old 12-09-2004, 12:15 PM   #13 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
There are so many approaches. Here something that works. Perhaps you could fine more ways.
Code:
#include <iostream>
#include <string>
#include <climits>
#include <fstream>

using std::cin;
using std::cout;
using std::endl;
using std::numeric_limits;
using std::streamsize;
using std::string;
using std::ifstream;

//Optional function: depends on IDE. Remove if not needed.
void wait_for_enter();

//Additional helper. Remove if not needed.
void reset_istream();

int main(int argc, char *argv[])
{
  ifstream theAccount("account.lst");
  if(!theAccount)
  {
    cout<<"ERROR! Reason: could not open or find file."<<endl;
    wait_for_enter();
    return -1;
  }
  
  cout<<"employee number: ";
  unsigned employeeNumber;
  cin>>employeeNumber;
  
  unsigned empNum;
  string employeeName;
  double payRate;
  bool b_found(false);
  // Assuming *.lst has this format (note \t): unsigned\tstring\tdouble
  while(theAccount>>empNum)
  {
    if(empNum == employeeNumber)
    {
      b_found = true;
      theAccount >> employeeName >> payRate;
      cout<<empNum<<endl;
      cout<<employeeName<<endl;
      cout<<payRate<<endl;
      break;
    }
    else
    {
      theAccount.ignore( numeric_limits<streamsize>::max(), '\n' );
    }
  }
  
  //Eof not reached but item not found either. So something must have gone wrong.
  if( !theAccount.eof() && b_found == false)
  {
    cout<<"ERROR! Reason: could not process the file properly."<<endl;
    cout<<"Terminating program..."<<endl;
    theAccount.close();
    wait_for_enter();
    return -1;
  }
  else if( b_found == false ) //All went O.K. but item has not been found.
  {
    cout<<"This employee number does not exist."<<endl;
  }
  
  theAccount.close();
  
  reset_istream();
  wait_for_enter();
  return 0;
}


//---------------------------------------------------

void reset_istream()
{
   if(cin.eof())
   {
      cin.clear();
   }
   else
   {
      cin.clear();
      cin.ignore(numeric_limits<streamsize>::max(), '\n');
   }
}

//---------------------------------------------------

void wait_for_enter()
{
  cout << "press <enter> to continue...";
  // Reset failstate, just in case.
  cin.clear();
  string line;
  getline( cin, line);
}
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quad project suggestion verdell32 Standard C, C++ 7 12-06-2004 04:17 PM
Project help verdell32 Standard C, C++ 2 11-16-2004 03:13 PM
Project Management Project DavH27 All Other Coding Languages 14 08-18-2004 05:58 AM
Suggestion: Project Thread DavH27 Lounge 2 08-17-2004 10:23 AM


All times are GMT -8. The time now is 03:50 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting