Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

payroll class Hello, I\'m having trouble doing a project for C++ and need some h

ID: 3766081 • Letter: P

Question

payroll class

Hello, I'm having trouble doing a project for C++ and need some help!!!

Here's the assignment :

Project 2 will require output to a text file similar to Project 1, but will require you to use the concepts of classes and objects (Chapter 7), dynamic arrays (Chapter 10), static data members and functions (Chapter 11) that have been reviewed in last several week in the course.

This program will simulate the calculation of payroll. The program will store a set of Payroll objects in a dynamic array and output the values of each object to a data file.

The overview of the project is as follows:

You will be required to create a text data file that will contain payroll information.

You will use a payroll class similar to what was used in Programming Assignment #5 to store and calculate payroll information in the program.

The program will accept payroll data that is input by the user and store the data in a payroll object.

The program should accept from the user the number of employees to calculate payroll information for and use a dynamic array of payroll objects to store the payroll data.

When the user has completed entering payroll data, the program should then output the data from the objects into the text file.

Project Requirements

The following is the requirements for the project. Your approach does not necessarily have to follow the order of the items listed here, but it must contain all of these requirements.

The data in the output file should be structured as follows:

Field Position

Field Description

Requirement

1

Employee Number

6 digit employee number

2

First Name

Text

3

Last Name

Text

4

Pay Rate

Accept decimals

5

Hours worked

Accept decimals

6

Pay Amount

Include decimal

Use the comma (“,”) character to separate the fields as you write them to the file.

Each record of payroll information should start on a new line in the text file.

Add a Trailer record at the end of the file which displays the following:

The text Total Records in brackets:

A space after

A number specifying the number of records contained in the text file

Name the text file cop2224_proj2.txt

Create a Payroll class for the project. The class should contain the following: (10 pts)

5 private data members. Each data member should correspond to the first 5 fields in the output file description above

A constructor that will create an instance of the class and initialize each of the 5 data members of the object

Get member functions for each of the data members

Set member functions if you choose to use these to update the data members of the class

A static data member that will track the total number of Payroll records created

Appropriate static member functions that will access and increment the static data member

A method to calculate the total pay amount for the employee. This should be calculated by multiplying the hours worked by the pay rate.

Your program will prompt the user for Payroll information.

Provide a descriptive introduction to the program to inform the user of the purpose of the program. (2 pts)

Provide the user the option to quit the program before entering any payroll data (2 pts)

You will ask the user how many Payroll records they will enter into the program. You will collect Payroll data until one of the following: (5 pts)

the user chooses to stop entering data into the program.

the number of payroll records the user specified to enter has been reached

You will need to use a loop structure to accomplish this.

The user should be prompted in your program to enter the Payroll information. You should design the program so that the user will be prompted to enter each data item on a separate line on the screen (4 pts)

Provide a clear option for the user at the completion of the payroll data entry. They should be prompted to either add another payroll record or quit the program. (2 pts)

Notify the user when they have reached their number of payroll records – no more payroll records need to be accepted once they reach the limit they specified at the beginning of the program (3 pts)

Validate that the Employee Number is exactly 6 characters long (3 pts)

The program should create a dynamic array which will store Payroll objects. The array should be dynamic so that the user of the program can enter the number of Payroll records as specified in (3) above. (5 pts)

The Payroll information entered by the user for each employee should be stored in a separate Payroll object. Each object should be included as an element of the dynamic array that was created in (4) above. (4 pts)

The static data member of the class will keep track of the number of Payroll records added by the user. (4 pts)

As the user completes entering payroll for an employee, the static data member of the class should be incremented by 1.

You need to use the static data member to track the number of Payroll records input by the user, as there is no guarantee that the user will enter the number of records they specify at the beginning of the program.

Be sure to use a static member function to access and update the static data member

When the user has completed entering Payroll records, the payroll information will be written to the output text file. The program should read through the Payroll object elements of the dynamic array and write a record to the output file for each object in the array. The trailer record - which includes the number of payroll records in the text file - should be written at the end of the text file.

the code that I had in the previous assignment was:

//Jason Dodson
//Project 1
//Class - C++

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


int main()
{
       ofstream outputFile;
       string FirstName, LastName ,JobTitle, OfficeLocation;
       int EmpNumber, OfficeChoice;
       double PayRate, HoursWorked;
       char overtime, exit, NewRecord, CorrectInfo;
       // This is the introduction line for the user
       cout << "Would you like to enter a new employee record?"<< endl;
       cin >> NewRecord;
       if ((NewRecord=='y')||(NewRecord =='Y'))
           { outputFile.open("cop2224_proj.txt");

// This is the line Where I started the loop
      do{
             cout << "Please enter your 6 digit employee number " << endl;
           
              cin >>EmpNumber;
              // This is the range validation for employee number
           while((EmpNumber<1)||(EmpNumber>999999))
              
           {cout<<"The number that you have entered is not valid!!"<< endl;
           cout << "Please enter your 6 digit number" << endl;
          
           cin >> EmpNumber;
      
           }
           
             cout<< "Please Enter your first name "<<endl;
          // This line allows for me to press [Enter] for a null value from the user
           cin.ignore();
           getline(cin, FirstName);

             cout << "Please enter your last name "<<endl;          
           getline(cin, LastName);
          
           // Menu driven choice for the Office location
             cout << "Please select the number listed of your current office location: " << endl;
             cout << "1 - Tampa"<< endl;
             cout << "2 - Sarasota " << endl;
             cout << "3 - Orlando " << endl;
             cout << "4 - Miami " << endl;
             cin >> OfficeChoice;
           // Office location choice validation
           // and loop for the menu choices
           while ((OfficeChoice<1)||(OfficeChoice>4))
           { cout <<"You did not enter a valid choice. Please enter a number 1 thru 5 to choose your office location"<< endl;
           cin >> OfficeChoice;}

             if (OfficeChoice == 1)
               OfficeLocation = "Tampa";
             else if (OfficeChoice == 2)
               OfficeLocation = "Sarasota";
             else if (OfficeChoice == 3)
             OfficeLocation = "Orlando";
           else if (OfficeChoice == 4)
               OfficeLocation = "Miami";

           // payrate and payrate validation
              cout << "Please enter the PayRate: " << endl;
              cin >> PayRate;
              while (PayRate<.01)
              {cout <<"Error!! Please enter a value greater than 0!!"<< endl;
              cin >> PayRate;}

           //Hours worked and hours worked validation
              cout << "Please enter the hours that were worked: " << endl;
              cin >> HoursWorked;
              while (HoursWorked<.01)
              {cout <<"Error!! Please enter a value greater than 0!!"<< endl;
              cin >> HoursWorked;}

          // Job title with or without whitespace
              cout<< "Please enter your Job Title"<<endl;
              cin.ignore();
              getline(cin, JobTitle);

          // overtime with validation for yes or no
              cout<< "Are you eligable for overtime? Enter 'Y' for Yes or 'N' for No"<< endl;
              cin >>overtime;
              while (((overtime!='y')&&(overtime!='Y'))&&((overtime!='n')&&(overtime!='N')))
                  {cout<<"error: Please answer 'Y' for Yes or 'N' for No." << endl;
              cin >> overtime;}


       //Clear screen and verify all data entered from the user
              system("cls");
              cout << "The new employee information that you entered is: "<< endl;
              cout<<""<<endl;
              cout << "Employee Number: "<< EmpNumber<<endl;
              cout <<"First Name: "<< FirstName <<endl;
              cout << "Last Name: " << LastName << endl;
              cout << "Office Location: " << OfficeLocation<< endl;
              cout << "Pay Rate: " << PayRate<< endl;
              cout << "Hours Worked: " << HoursWorked << endl;
              cout <<"Job Title"<< JobTitle<< endl;
              cout <<"Eligable for Job title: " << overtime << endl;
              cout << "Is all the information correct?" << endl;
              cin >>CorrectInfo;
              if ((CorrectInfo=='Y')||(CorrectInfo=='y'))

       // Loop if the data entered is false or contine to output the data and save to file
          
              {
           outputFile <<EmpNumber<< ", " ;
           outputFile <<FirstName << ", ";
           outputFile <<LastName << ", ";
           outputFile << OfficeLocation<< ", " ;
           outputFile<< fixed << setprecision(2)<<"Payrate - $" << PayRate<< ", " ;
           outputFile<< fixed << setprecision(2)<<"Hours Worked-"<< HoursWorked<< ", ";
           outputFile << JobTitle << ", ";
           outputFile<< overtime<< endl;
              }
              else if ((CorrectInfo=='n')||(CorrectInfo =='N'))
       // loop if the data displayed if incorrect
              { cout<< "Restarting Program" << endl;}
          
        // loop for if the user wants to enter another record here
           cout << "Would you like to enter another Employee Record?"<< endl;
              cin >> exit;
          }  
       while ((exit!='n')&&(exit!= 'N'));
       cout << "The file has sucessfully been saved." << endl;
     
       }
       else
        outputFile.close();
       system ("pause");
       return 0;
       }

Field Position

Field Description

Requirement

1

Employee Number

6 digit employee number

2

First Name

Text

3

Last Name

Text

4

Pay Rate

Accept decimals

5

Hours worked

Accept decimals

6

Pay Amount

Include decimal

Explanation / Answer

Program: