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

Design a C++ program that will make an employee database. There will be a maximu

ID: 3767732 • Letter: D

Question

Design a C++ program that will make an employee database. There will be a maximum of 25 employees. The program shall get input from 3 separate input files (using filestreams) and write its output to the default output source.


REQUIRED DATA STRUCTURE
Create an array of records (structs), the minimum fields in the record should be

first name and last name (string)

ID # (int)

job status (char) F=full-time P=part-time

hourly pay rate (double)

hours worked (double)

INPUT FILE
The first input file will have several lines of data representing employee information. Each line will be formatted as follows:

firstname  lastname  ID#  jobstatus   payrate

Names may need to be reformatted (first letter capitalized, remaining lower case). All other values will be present and valid in this file.

The second input file will have series of changes to be made to the employee database, one per line. Each line will start with an integer that will represent an ID#. If the ID# is valid (matches an employee), then a one letter command (that represents the field to be changed) and a new value for that field will follow. If the ID# is invalid, the remainder of the line should be discarded (ignored) (hint: use getline to read rest of line). Note: the ID#s will not be in the same order as they were in the first input file and there may be more than one change for an employee.

Commands
S = job status    P = pay rate

Sample data sets:
56 P 10.50
29 S F

Note that the name and ID# fields will not be changed.

The third data file will consist of several data sets that indicate the hours worked by employees during the current pay period. Each line will start with an integer that will represent an ID#. If the ID# is valid (matches an employee), then it will be followed by a floating point value that represents the number of hours worked by the employee. If the ID# is invalid, the remainder of the line should be discarded (ignored). Note: the ID#s will not be in the same order as they were in the first input file and there may be more than one data set for an employee.

Sample data sets:
56 8.0
29 3.5

Processing
The program must:
Interactively prompt the user for the name of the first input file, open the file, and read the data from the file, storing the employee information into your array and counting the number of employees

sort the array of employees into alphabetical order (by last name, and last names might be unique)

generate an alphabetized report that lists all of employees by name with ID#, job status, and pay rate (see sample below) BEFORE the second input file is read

interactively prompt the user for the name of the second input file, open the file

read and process the change commands, making the specified changes to the employee information in your array, for each change that is made display a message indicating the ID# and change made, if an ID# is invalid display a message that states the bad ID# and indicates that it could not be found

generate an alphabetized report that lists all of the employees by name with their ID#, job status, and pay rate (see sample below) AFTER the second input file is read

interactively prompt the user for the name of the third input file, open the file

read and process the hours worked data, determining the total number of hours worked by each employee, no output is required when processing this data, note that there may be several data sets that pertain to the same employee

generate an alphabetized report that lists all of the employees by name with their pay rate, hours worked, and total pay due; the last line of the report should display the total hours worked and total amount due to employees; do not total any other columns (see sample below)

Make sure that all output is nicely formatted (as in examples) and leave blank lines between reports to enhance readability.

Calculations Towards Pay
To calculate pay, part-time employees are paid their regular hourly rate for each hour worked (no overtime). Full-time employees earn overtime pay (1.5 times their regular hourly pay) for time worked over 40 hours.

Formatting Specifications

First and last names will be strings with a maximum length of 10 characters each.

ID#'s will be integers with a maximum length of 3 digits.

All commands will be capital letters.

Pay rate and hours worked will be double values and will be > 0. Maximum value for each is 100.00.

Display all floating point values with 2 digits to right of decimal.

Include dollar signs ($) for all dollar amounts.

Sample first input file:
max martin 123 F 20.00
Michael Malloy 56 P 7.50
maRy MiLLs 555 F 17.50
mADdy miLsAp 89 F 6.15

Sample second input file:
555 P 18.25
11 nonsense to be ignored
56 S F
555 S P

Sample third input file:
123 7.5
56 6.5
99 invalid id#
555 2.5
123 10.0
56 37.0

Sample program run:
[key]$ g++ program.cpp
[key]$ ./a.out

Enter name of first data file
employees

EMPLOYEE
NAME                        ID#    STATUS        RATE
Malloy,Michael               56         P   $    7.50
Martin,Max                  123         F   $   20.00
Mills,Mary                  555         F   $   17.50
Milsap,Maddy                 89         F   $    6.15

Enter name of second data file
changes

ID# 555 hourly pay rate changed to $18.25
ID# 11 is invalid
ID# 56 status changed to F
ID# 555 status changed to P

EMPLOYEE
NAME                        ID#    STATUS        RATE
Malloy,Michael               56         F   $    7.50
Martin,Max                  123         F   $   20.00
Mills,Mary                  555         P   $   18.25
Milsap,Maddy                 89         F   $    6.15

Enter name of third data file
hrsworked

EMPLOYEE                 
NAME                             RATE     HOURS       TOTAL PAY
Malloy,Michael              $    7.50     43.50     $    339.38
Martin,Max                  $   20.00     17.50     $    350.00
Mills,Mary                  $   18.25      2.50     $     45.62
Milsap,Maddy                $    6.15      0.00     $      0.00
TOTAL                                     63.50     $    735.00
Additional Requirements

The program must make use of functions.
The program MUST PASS PARAMETERS to communicate values. No global variables are allowed.
Program must make use of filestream variables to represent the input files and write output to the screen. Each input file can only be read once.

Program must use a static array of structs to store employee data (do not use a variable for the size of the array).

Explanation / Answer

Program:

#include <string> // to deal with strings

#include <iostream> // for printf()

#include <cstdlib> // for exit(), perror()

#include <fstream> // for ifstream

#define Max 10000

using namespace std;

struct employee

{

       string firstName;

       string lastName;

       int ID;

       char jobStatus;//F=full-time P=part-time

       double hourlyPayRate;

       double hoursWorked;

      

}empDB[Max];

int main()

{

       string firstfile,secondfile,thirdfile;

       string line,command;

       int ids;

       double rates;

       char status;

       int noEmployee=0;

       bool valid=false;

       ifstream ifs;

       //Processing file 1

       cout<<"Enter the employee data base input file:";

       cin>>firstfile;

       ifs.open(firstfile+".txt");

       if (ifs.fail())

       {

              cerr << "Could not open "<<firstfile<<" file"<< endl;

              exit(2);

       }

       //make emploee data base

       do

       {

              ifs>>empDB[noEmployee].firstName;

              ifs>>empDB[noEmployee].lastName;

              ifs>>empDB[noEmployee].ID;

              ifs>>empDB[noEmployee].jobStatus;

              ifs>>empDB[noEmployee].hourlyPayRate;

              noEmployee++;

       }while(!ifs.eof());

       ifs.close();

       //print data base

       cout<<"EMPLOYEE"<<endl;

       cout<<"NAME "<<"ID# "<<"STATUS "<<"RATE "<<endl;

       for(int i=0;i<noEmployee-1;i++)

       {

              cout<<empDB[i].firstName<<","<<empDB[i].lastName<<" "<<empDB[i].ID<<" "<<empDB[i].jobStatus<<" "<<empDB[i].hourlyPayRate<<endl;

       }

       //Processing file 2

       cout<<"Enter the employee data modification input file:";

       cin>>secondfile;

       ifs.open(secondfile+".txt");

       if (ifs.fail())

       {

              cerr << "Could not open "<<secondfile<<" file"<< endl;

              exit(2);

       }

       do

       {

             

              ifs>>ids;

             

              ifs>>command;

             

              if(command.size()!=1)

              {

                     getline(ifs,command);

                     continue;

              }

             

              if(command.size()==1 && isalpha(command.at(0)))

              {

                     if(command=="S")

                     {

                           ifs>>status;

                           for(int i=0;i<noEmployee-1;i++)

                           {

                                  if(ids==empDB[i].ID)

                                  {

                                         empDB[i].jobStatus=status;

                                         break;

                                  }

                           }

                     }

                     else if(command=="P")

                     {

                           ifs>>rates;

                           for(int i=0;i<noEmployee-1;i++)

                           {

                                  if(ids==empDB[i].ID)

                                  {

                                         empDB[i].jobStatus=rates;

                                        

                                         break;

                                  }

                           }

                     }

              }

             

              command="";

       }while(!ifs.eof());

       ifs.close();

       //print data base

       cout<<"EMPLOYEE"<<endl;

       cout<<"NAME "<<"ID# "<<"STATUS "<<"RATE "<<endl;

       for(int i=0;i<noEmployee-1;i++)

       {

              cout<<empDB[i].firstName<<","<<empDB[i].lastName<<" "<<empDB[i].ID<<" "<<empDB[i].jobStatus<<" "<<empDB[i].hourlyPayRate<<endl;

       }

       double totalpay;

       //Processing file 3

       cout<<"Enter the employee working hours input file:";

       cin>>thirdfile;

       ifs.open(thirdfile+".txt");

       if (ifs.fail())

       {

              cerr << "Could not open "<<thirdfile<<" file"<< endl;

              exit(2);

       }

       do

       {

              ifs>>ids;

             

              for(int i=0;i<noEmployee-1;i++)

              {     

                     if(ids==empDB[i].ID)

                     {

                           ifs>>line;

                            empDB[i].hoursWorked=stof(line);

                     }

              }

             

             

       }while(!ifs.eof());

       ifs.close();

       //print data base

       cout<<"EMPLOYEE"<<endl;

       cout<<"NAME "<<"ID# "<<"STATUS "<<"RATE "<<"TOTAL PAY "<<endl;

       for(int i=0;i<noEmployee-1;i++)

       {

              if(empDB[i].jobStatus='P')

                     cout<<empDB[i].firstName<<","<<empDB[i].lastName<<" "<<empDB[i].ID<<" "<<empDB[i].jobStatus<<" "<<empDB[i].hourlyPayRate<<(empDB[i].hoursWorked*empDB[i].hourlyPayRate)<<endl;

              else

              {

                     double whr=empDB[i].hoursWorked;

                     if(whr>40)

                     cout<<empDB[i].firstName<<","<<empDB[i].lastName<<" "<<empDB[i].ID<<" "<<empDB[i].jobStatus<<" "<<empDB[i].hourlyPayRate<<(empDB[i].hoursWorked*empDB[i].hourlyPayRate)+(empDB[i].hoursWorked-40)*empDB[i].hourlyPayRate<<endl;

                     else

                            cout<<empDB[i].firstName<<","<<empDB[i].lastName<<" "<<empDB[i].ID<<" "<<empDB[i].jobStatus<<" "<<empDB[i].hourlyPayRate<<(empDB[i].hoursWorked*empDB[i].hourlyPayRate)<<endl;

              }

       }

       system("pause");

       return 0;

}

Sample output: