Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,121 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,756 people online right now. Registration is fast and FREE... Join Now!




Progam to calculate Pay

 
Reply to this topicStart new topic

Progam to calculate Pay, c++ program for a company with various category of workers

adisajaja
15 Apr, 2007 - 07:18 PM
Post #1

New D.I.C Head
*

Joined: 19 Mar, 2007
Posts: 3


My Contributions
I am Evrol Bell from Kingston Jamaica I have already found this site and the forums it offers very useful give thanks I just started learning C++ like a month ago this is the assignment I got from my facilitator she said it will be graded I wrote as much as I can but I know something is wrong so I need all the input I can get its outline below with the code I wrote at the end give thanks



A program is required by a company to store employee’s number, TRN number pay rate and the number of hours worked in a week. The program is then to validate the pay rate and the hours worked fields and, if valid compute the employee’s weekly pay and print it along with the input data on to a payslip

Validation: According to the company’s rules, the maximum hours an employee can work per week is 40 hours, and the maximum hourly rate is $200.00 per hour. If the hours worked fields or the hourly rate is out of range, the input data and the appropriate message is to be printed and the employee’s weekly pay is not to be calculated

Weekly pay calculation: Weekly pay is calculated as hours worked times pay rate. If more than 30 hours are worked, payment for the overtime hours worked is calculated at time-and-a-half.

Most employees are paid according to these procedures, but two categories of workers are paid differently.

Programmers have an area of speciality and can be assigned to only one project. They do not earn overtime, but they are entitled to a $5,000 bonus for each week their project is running ahead of schedule.

Sales representatives earn a commission of $2000 if their weekly sales exceed $20,000 and $1000 if their sales are in the range $10,000 to $20,000.

As the payroll is processed, the weekly pay for each employee should be added to the wages total for that week and printed after the last employee has been processed. All the data that has been printed on the payslips should be written to file.



This implementation must be done using C++ (Bloodshed C++)


CODE
#include <iostream>     // for keyboard/screen I/O
#include <fstream>        // for file I/O


using namespace std;

void  CalcPay ( float,  float,  float& );

const  float  MAX_HOURS = 40.0;  // Maximum normal hours
const  float  OVERTIME = 1.5;    // Overtime pay factor



int  main( )
{
     float     payRate;            //  Employee’s pay rate
     float     hourswork;        //  Hours  worked
     float     wages;         //  Wages earned
     float     total;        //  Total company payroll
     int       empNum;        //  Employee  ID  number
     int          trnnum;        //  Employee TRN number
     int       category;       
    ofstream  payFile;        // Company  payroll file

     payFile.open( “payfile.dat” );    // Open file
     total = 0.0;                          // Initialize total

cout << “Enter employee number: “;  // Prompt

     cin  >> empNum;                     // Read ID number

             while ( empNum  !=  0 )             // While not done
     {
      cout << “Enter pay rate: “;        
      cin  >> payRate;                   // Read pay rate
      cout << “Enter hours worked: “;
      cin  >> hourswork;                 // and hours worked
    cout << "enter employee trn number";
    cin >> "trnnumber";
    cout << "enter category of employee";
    cin >> "category";

    

If (hoursworked > 40) && (pay rate > 200) then
    Print input data
    Print appropriate message
    Salary not calculated
Else
If( category = = “programmer”)
“Prompt user for schedule time”
If schedule time = = yes
            Bonus = 5000
            Weeklypay = bonus + (hoursworked * hourlyrate)
Else
Weeklypay = hoursworked *hourlyrate
print (payslip) weeklypay , input data
ElseIf (category = =”sales rep”)
        Prompt user to enter weekly sales
        If (weeklysales > 20000)
            Commission = 2000
            Weeklypay = commission + (hourlyrate * hoursworked)
            print (payslip) weeklypay , input data
Else
            If (weeklysales > = 10000) && (weekly sales < = 20000)
                Commission = 1000
                Weeklypay = commission + (hoursworked + hourlyrate)
                print (payslip) weeklypay , input data
Endif
Else
If (hours worked > 30) then
            Overtime = 40 – hoursworked
            Overtimepay = 40- hoursworked
            Weeklypay = (30* hourlyrate)+ overtimepay
Else
            weeklypay = hoursworked * hourlyrate
            print (payslip) weeklypay , input data
Endif
Endif

Totalwages = totalwages + weeklypay
Print totalwages
Write File with EmpNumber,TrnNumber,HoursWorked,PayRate,Totalsalary
Endif  code here


This post has been edited by adisajaja: 15 Apr, 2007 - 07:23 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Progam To Calculate Pay
16 Apr, 2007 - 04:23 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Can you specify the problem you are encountering, along with any error messages being generated?
User is offlineProfile CardPM
+Quote Post

adisajaja
RE: Progam To Calculate Pay
16 Apr, 2007 - 02:53 PM
Post #3

New D.I.C Head
*

Joined: 19 Mar, 2007
Posts: 3


My Contributions
QUOTE(Amadeus @ 16 Apr, 2007 - 05:23 AM) *

Can you specify the problem you are encountering, along with any error messages being generated?


[quote] I am facing some problems regarding system error and so on I am not realy sure how to write all C++ syntaxes or most of them I was wondering if I could get some assistance in that regard as you can see most the code is written as algorithm I need some syntax advice please thank you [/qoute]
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Progam To Calculate Pay
16 Apr, 2007 - 03:55 PM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Syntax of an if-then statement:


if (condition)
{
do something when condition is true
}


syntax of if-then-else in C

if (condition)
{
do something when condition is true
} else
{
do something else if condition is false
}


syntax of if-else-if in C


if (condition)
{
do something when condition is true
} else if (condition2)
{
do something if condition1 is false but condition2 is true
} else if (condition3)
{
do something if condition1 & condition2 are false but condition3 is true
} else
{
do something if all those conditions are false
}



The syntax for the conditions use the operators (==, <=, >=, <, >, &, |, ^, %) although it may be noted that in C/C++ a zero is false, and a nonzero is true so you can use any expresion that returns an integral type. You can also create compond conditions using && and ||.


User is offlineProfile CardPM
+Quote Post

adisajaja
RE: Progam To Calculate Pay
16 Apr, 2007 - 04:06 PM
Post #5

New D.I.C Head
*

Joined: 19 Mar, 2007
Posts: 3


My Contributions

[qoute] give thanks for that outline I am gonna work on it anyone else have an input can let me know.





QUOTE(NickDMax @ 16 Apr, 2007 - 04:55 PM) *

Syntax of an if-then statement:


if (condition)
{
do something when condition is true
}


syntax of if-then-else in C

if (condition)
{
do something when condition is true
} else
{
do something else if condition is false
}


syntax of if-else-if in C


if (condition)
{
do something when condition is true
} else if (condition2)
{
do something if condition1 is false but condition2 is true
} else if (condition3)
{
do something if condition1 & condition2 are false but condition3 is true
} else
{
do something if all those conditions are false
}



The syntax for the conditions use the operators (==, <=, >=, <, >, &, |, ^, %) although it may be noted that in C/C++ a zero is false, and a nonzero is true so you can use any expresion that returns an integral type. You can also create compond conditions using && and ||.


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:08PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month