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: 3767812 • 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).

These header files will be used and no possible others:
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
#include <iomanip>
#include <cmath>

Explanation / Answer

write a program for employee database with following details:
1. All employee have first name,last name and salary.
2.Engineers in addition to employees have details of their trade, years of experience and whether they know c++ or not.
3.Managers in addition to employees have details of number of meetings and number of vacations
4.Researchers have details their school of Phd. and its topic.
Here is what i have done so far:


here is my main file:

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

Member functions for detecting and handling stream errors.

You can test the state of a stream using various member functions and also with a conversion operator that allows you to test the stream object itself. These are: bool good(); Returns true if none of the error bits are on and the stream is ready to use (is open). This is a good choice for asking "is everything OK?" if (stream_object) if (!stream_object) if (stream_object >> var) while (stream_object >> var) These tests of the whole stream object correspond to using good() — The stream classes have a conversion operator that converts the stream object to the same true-false value that is returned by the good() function. The first test is true if the stream is in a good state; the second if the stream is not in a good state. The third and fourth examples test the result of the input operation (remember that the result of the input operator is the stream object itself). The fourth example form is commonly used to repeatedly read the stream until an end of file condition. bool is_open(); Returns true if the stream is open. A good choice for testing for a successful opening because its name makes the purpose of the test more obvious. bool bad(); Returns true if the bad bit is on as a result of a "hard" I/O error. It is not the opposite of good(). bool fail(); Returns true if the fail bit is on due to invalid input or the bad bit is on (odd, but Standard) (see the Basic C+ + Stream I/O handout). bool eof(); Returns true if the eof bit is on due to trying to read past the end of the file. clear(); Resets all of the error bits to off. Does not change which characters will be read next from the stream.

Recovering from an input error

The action your program takes on an input error depends on the type of error encountered. If it is invalid input, your program needs to clean up the input and clear the stream, and attempt to continue. If it is an expected eof, the program simply goes to the next step in the processing. But if the eof is unexpected, something is wrong, and the user needs to be informed. Finally, if you are checking for hard I/O errors, you need to deal with it if it turns out to be the problem.

  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  
  //employee.h  #ifndef EMPLYOEE_H  #define EMPLOYEE_H  #include<iostream>  #include<fstream>  #include<string>  #include <cctype>  #include <iomanip>  #include <cmath>  using namespace std;  class Employee  {  public:          Employee(string firstName,string lastName,int salary)          {mFirstName=firstName;mLastName=lastName;mSalary=salary;}          virtual void printStats()          {                  cout<<"First name:"<<mFirstName<<endl;                  cout<<"Last name:"<<mLastName<<endl;                  cout<<"Salary:"<<mSalary<<endl;          }           virtual void save(ofstream& outFile)          {                  outFile<<"First name:"<<mFirstName<<endl;                  outFile<<"Last name:"<<mLastName<<endl;                  outFile<<"Salary:"<<mSalary<<endl;          }          string getLastName()          { return mLastName;}  protected:          string mFirstName;          string mLastName;          int mSalary;  };  class Engineer: public Employee  {  public:          Engineer(string firstName,string lastName,int salary,string knowCPP,int yearsExp,string trade):Employee(firstName,lastName,salary)          {                  mKnowCPP=knowCPP;mYearsExp=yearsExp;mtrade=trade;}          void Save(ofstream& outFile)          {                  Employee::save(outFile);                  outFile<<"know c++:"<<mKnowCPP<<endl;                  outFile<<"Years of exp:"<<mYearsExp<<endl;                  outFile<<"trade:"<<mtrade<<endl;          }          void PrintStats()          {                  Employee::printStats();                  cout<<"know c++:"<<mKnowCPP<<endl;                  cout<<"Years of exp:"<<mYearsExp<<endl;                  cout<<"trade:"<<mtrade<<endl;          }  protected:          string mFirstName;          string mLastName;          int mSalary;          string mKnowCPP;          int mYearsExp;          string mtrade;  };  class Manager: public Employee  {  public:          Manager(string firstName,string lastName,int salary,int meet,int vac):Employee(firstName,lastName,salary)          {mMeet=meet;mVac=vac;}          void Save(ofstream& outFile)          {                  Employee::save(outFile);                  outFile<<"Number of meetings:"<<mMeet<<endl;                  outFile<<"Number of holidays:"<<mVac<<endl;          }          void printStats()          {                  Employee::printStats();                  cout<<"Number of meetings:"<<mMeet<<endl;                  cout<<"Number of holidays:"<<mVac<<endl;          }  protected:          int mMeet;          int mVac;  };  class Researcher:public Employee  {  public:          Researcher(string firstName,string lastName,int salary,string schoolPhd,string PhdTopic):Employee(firstName,lastName,salary)          {mSchoolPhd=schoolPhd;mPhdTopic=PhdTopic;}          void save(ofstream& outFile)          {                  Employee::save(outFile);                  outFile<<"School of Phd.:"<<mSchoolPhd<<endl;                  outFile<<"Phd. topic:"<<mPhdTopic<<endl;          }  protected:          string mSchoolPhd;          string mPhdTopic;  };    #endif