1. Write a program that calculates gross wages for employees. The program should ask the user to enter an employee’s ID, hours worked and hourly pay rate. It should then calculate the gross wage for that employee and store it with this employee’s information into another file. The program should allow the user to calculate wages as many times as they want. It should use the following functions:
a. void getEmployeeInfor() should ask the user for an employee’s ID, pay rate and the hours worked.
b. double calcWage() should calculate one employee’s gross wage.
c. void printWages should print an employee’s ID, pay rate, hours worked and wage into another file

Input Validation: Do not accept negative values for pay rate and hours worked.

2.Modify Project 4 (Payroll System) so that employees’ information can be sorted by ID, hourly rate, hours worked or wage. You are asked to use a menu to provide these services for the users. The menu might look like this:

Menu
1. Calculate gross wages for employees
2. Display employees’ information to screen
3. Display employee's information to screen according the order of ID
4. Display employee's information to screen according the order of hourly rate
5. Display employee's information to screen according the order of hours worked
6. Display employee's information to screen according the order of wage
7. Quit the system

The requirements for option 1 are same as those for the project 4.

Recommended Answers

All 5 Replies

I eventually want a co-worker who knows how to solve his own problems. Seems we are at an impasse.

If you would like help with a particular problem you are having, please post your code and a question. However, no one here is going to do your homework for you.

I have the solution for the first question and is as follows.

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;



//Function prototype

void getEmployeeInfor(int ,double &, double &);
double calcWage(double, double);
void printWages(int, double, double, double)


main ()

{
     int ID;
     double payrate, hours, wage;

     /* Testing getEmployeeInfor() */
     /* getEmployeeInfor(ID, payrate, hours);
     cout << "ID: " << ID << ", Payrate: " << payrate << ", Hours: " << hours << endl;
     */

     /* Testing calcWage() */
     /*cout << calcWage(3,10) << endl;
     cout << calcWage(6.5,7.5) << endl; */

     /* Testing printWages() */
     /* printWages(1,3,10,30.00);
     printWages(2,6.5,7.5,48.75); */
while(1)

 {
     getEmployeeInfor(ID,payrate,hours);
     wage = calcWage(payrate,hours);
     printWages(ID, payrate, hours,wage);


    char choice;

    cout << "Do you want to calculate another employee's gross wage? ";

    cin >> choice;

           if (choice == 'n')

               break;

}
   cout << "The result is reported to the file \"employeeWages.dat\"." << endl;

   return 0;

}


//*****************************************************
// This function ask the user to input his ID,        *
// payrate, and the hours worked.                     *
//*****************************************************


void getEmployeeInfor (int &ID,double &payrate,double &hours)
{

    while (1) {

    cout << " Enter an employee's information by order of ID "
         << "number,rate,hours: " << endl;

    cin >> ID >> payrate >> hours;

    if(ID < 0 || payrate < 0 || hours < 0)

     {
      cout <<" You must enter a non negative valve. Try again!" << endl;
      continue;
     }
    else
     break;
    }

}

//*****************************************************
// This function calculates one employee's            *
// gross wage                                         *
//*****************************************************

double calcWage( double rate, double hours)


     {
        double wage;

        wage = rate * hours;

        return wage;

     }

//*****************************************************
// This function prints an employee ID,               *
// payrate,hours worked and                           *
// wages                                              *
//*****************************************************


void printWages (int ID, double rate, double hours, double wage)

     {
          static ofstream out ("employeeWages.dat");
               static int i = 0;

          if(i == 0)
            {
             out.setf(ios::right);

             out << setw (10) << "ID" << setw (20) << "Hourly Rate"
                  << setw (15) << "Hours" << setw (20)<< "Wage" << endl;

             out << "------------------------------------"
                 << "-----------------------------" << endl;

              i = 1;
            }

              out << fixed << setprecision(2);
              out << setw (10) << ID << setw (20) << rate
                   << setw (15) << hours << setw (20)<< wage << endl;

     }

Please use code tags when posting code to the forum.
At this point, you are going to have to store the data you are reading in to a structure that can be sorted instead of just printing immediately to file. Consider using a struct or class

struct Employee {
   int id;
   double rate, hours;
   Employee (int i, double r, double h) : id(i), rate(r), hours(h) {}
};

Now, when you get valid information from a user, you can create an Employee

Employee e(id,rate,hours);

Using that, create a container that will store as many of these employees as you would like. Maybe a std::vector< Employee > . These structures can be sorted according to criteria you provide.

That may seem like a lot. Start slow and implement the pieces. If you have problems along the way, post back and we will help you along.

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.