Weekly Salary Computation

VSBrown 0 Tallied Votes 2K Views Share

A program used to calculate each employee's pay based on that employee's paycode.

/******************************************************

** Name: 

** Filename: weeklysalary.cpp

** Project #: 

** Project Description: A company pays its employees as managers
   (who receive a fixed weekly salary), hourly workers (who recieve a
   fixed hourly wage for up to the first 40 hours they work and "time-
   and-a-half," i.e., 1.5 times their hourly wage, for overtime hours
   worked), commission workers (who receive $250 plus 5.7% of their
   gross weekly sales), or pieceworkers (who receive a fixed amount of 
   money per item for each of the items they produce--each pieceworker
   in this company works on only one type of item). Write a program to
   compute the weekly pay for each employee. You do not know the number
   of employees in advance. Each type of employee has its own pay code:
   Managers have paycode 1, hourly workers have code 2, commission 
   workers have code 3 and pieceworkers have code 4. Use a switch to 
   compute each employee's pay based on that employee's paycode. Within
   the switch, prompt the user (i.e., the payroll clerk) to enter the 
   appropriate facts your program needs to calculate each employee's
   pay based on that employee's paycode.

** Output:The number of total employees paid.
          The number of Managers paid.
		  The number of Hourly workers paid.
		  The number of Commission workers paid.
		  The number of Piece Workers paid.

** Input: Paycode of employee.
          Code 1:(Manager Info)
		   - Weekly Salary
		  Code 2:(Hourly Worker Info)
		   - Hourly Salary
		   - Hours Worked
		  Code 3:(Commission Worker Info)
		   - Gross Weekly Sales
		  Code 4:(Piece Worker Info)
		   - Number of Pieces
		   - Wages per Piece

** Algorithm: Instruct user of programs purpose.
              List paycodes and instruct user to enter a paycode
			  or press -1 to end program.
			  When paycode is entered go to the case in the switch
			  which will compute the pay for that worker.
			  Each time a paycode is used count the number of times.
			  When -1 is pressed instead of paycode then print out 
			  the total number of employees to be paid.
			   -List# of:
			    -Managers
				-Hourly Workers
				-Commission Workers
				-Piece Workers
              End Program

******************************************************/

// Include files
#include <iostream>  // used for cin, cout
#include <conio.h>
#include <iomanip>
using namespace std;

// Global Type Declarations

// Function Prototypes
void instruct (void);
void pause ();

//Global Variables - should not be used without good reason.

int main ()
{
	 // Declaration section
	int paycode, 
	    Manager    = 0,     //Manager
	    HourWorker = 0,     //Hourly Worker
        ComWorker  = 0,     //Commission Worker
	    PiWorker   = 0;     //Piece Worker
 double salary;
	 
	 // Executable section
	instruct ();

    cout << "-----------------------------------------------------"
         << "---------------\n"
		 << "Paycodes (1=Manager,2=HourlyWorker,3=CommissionWorker"
		 << ",4=PieceWorker)\n"
	     << "                  ( -1 To End Program )              "
		 << "\n-----------------------------------------------------"
		 << "---------------\n"
		 << "\nEnter paycode : "
         << setiosflags( ios::fixed | ios::showpoint );
     cin >> paycode;
   
         while( paycode != -1 ) {
         
			 switch( paycode ) {
        
         case 1: //Manager
         Manager++;
         cout << "Manager Selected." << endl;
         cout << "Enter Weekly Salary: ";
          cin >> salary;
         cout << "Manager's pay is " << setprecision( 2 ) 
              << salary << "\n" << endl;
         break;
         
         case 2: //Hourly Worker
         double wage;
         int hours;
         HourWorker++;
         cout << "Hourly worker Selected." << endl;
         cout << "Enter the hourly salary: ";
          cin >> wage;
         cout << "Enter the total hours worked: ";
          cin >> hours;
         if ( hours <= 40 )
            salary = hours * wage;
         else
            salary = 40.0 * wage + ( hours - 40 ) * wage * 1.5;
            
         cout << "Hourly worker's pay is " << setprecision( 2 ) 
              << salary << "\n" << endl;
         break;
         
         case 3: //Commission Worker
         int sales;
         ComWorker++;
         cout << "Commission Worker Selected." << endl;
         cout << "Enter gross weekly sales: ";
          cin >> sales;
         salary = sales * .057 + 250;
         cout << "Commission worker's pay is " << setprecision( 2 ) 
              << salary << "\n" << endl;
         break;
         
         case 4: //PieceWorker
         int pieces, wagePerPiece;
         PiWorker++;
         cout << "Piece worker Selected." << endl;
         cout << "Enter number of pieces: ";
          cin >> pieces;
         cout << "Enter wage per piece: ";
          cin >> wagePerPiece;
         salary = pieces * wagePerPiece;
         cout << "Piece worker's pay is " << setprecision( 2 ) 
              << salary << "\n" << endl;
         break;
      }
      
    cout<< "-----------------------------------------------------"
        << "---------------\n"
	    << "Paycodes (1=Manager,2=HourlyWorker,3=CommissionWorker"
	    << ",4=PieceWorker)\n"
        << "                  ( -1 To End Program )              "
	    << "\n-----------------------------------------------------"
	    << "---------------\n"
	    << "\nEnter paycode : ";
    cin >> paycode;
   }
   
    cout << "\t-------------------------------------------------"
	     << "\n\t| Number of Employees paid         : "
	     << Manager + HourWorker + ComWorker + PiWorker 
	     << "\t\t|\n\t| Number of Managers paid          : " 
         << Manager 
         << "\t\t|\n\t| Number of Hourly Workers paid    : "
         << HourWorker 
         << "\t\t|\n\t| Number of Commission Workers paid: "
	     << ComWorker 
         << "\t\t|\n\t| Number of Piece Workers paid     : "
         << PiWorker 
		 << "\t\t|\n\t-------------------------------------------------"
         << endl;
   





 
	      pause ();
	      return 0;
}

void instruct (void)
{
	  // Declaration section
    cout << "\tThis program will compute the weekly pay for each     " 
		 << "      \n"
		 << "\temployee, list the total number of employees paid     "
		 << "      \n"
		 << "\tand the total number of Managers, Hourly Workers,     "
		 << "      \n"
		 << "\tCommission Workers and Piece Workers paid for the week." 
		 << "     " << endl;

	  // Executable section
}

void pause ()
{
    // Declaration section

    // Executable section
    cout << "\nPress any key to continue...";
    getch();
    cout << "\r";
    cout << "                            ";
    cout << "\r";
}


/*
Program Output

        This program will compute the weekly pay for each
        employee, list the total number of employees paid
        and the total number of Managers, Hourly Workers,
        Commission Workers and Piece Workers paid for the week.
--------------------------------------------------------------------
Paycodes (1=Manager,2=HourlyWorker,3=CommissionWorker,4=PieceWorker)
                  ( -1 To End Program )
--------------------------------------------------------------------

Enter paycode : 1
Manager Selected.
Enter Weekly Salary: 200
Manager's pay is 200.00

--------------------------------------------------------------------
Paycodes (1=Manager,2=HourlyWorker,3=CommissionWorker,4=PieceWorker)
                  ( -1 To End Program )
--------------------------------------------------------------------

Enter paycode : -1
        -------------------------------------------------
        | Number of Employees paid         : 1          |
        | Number of Managers paid          : 1          |
        | Number of Hourly Workers paid    : 0          |
        | Number of Commission Workers paid: 0          |
        | Number of Piece Workers paid     : 0          |
        -------------------------------------------------

Press any key to continue...

*/
numenor_2006 0 Newbie Poster

Very nice program.
excellent style design , liked the menus in the boxes :cheesy:

freckman1981 0 Newbie Poster

Hey it is great code, do you know how to do it in java? I am having a really hard time with the exact same assignment in java. If anyone could help me it would be greatly appreciated

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.