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

C++ Program Using Records (structs), Arrays, filestream variables, functional de

ID: 3572701 • Letter: C

Question

C++ Program Using Records (structs), Arrays, filestream variables, functional decomposition, and functions and parameter passing.

Create a C++ program with the following requirements. You will manage employee database. There will be a maximum of 25 employees. The program will get its 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
a. first name and last name (string)
b. ID # (int)
c. job status (char) F=full-time P=part-time
d. hourly pay rate (double)
e. hours worked (double)


INPUT FILE DESCRIPTIONS
a. The first input file will consist of several lines of data representing employee information. Each line will be formatted as follows:
b. firstname  lastname  ID#  jobstatus   payrate
c. Names may need to be reformatted (first letter capitalized, remaining lower case). All other values will be present and valid in this file.

d. The second input file will consist of a series of changes to be made to the employee database, one per line. Each line will start with an integer that is supposed to 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 ignored. Maximum of 80 characters on a line, use ignore function, ifstvar.ignore(80,' ') or you can write your own function to discard the remainder of the current 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.

Command Codes
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.

e. 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 is supposed to 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 ignored (maximum of 80 characters). 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
Your program should:

a. 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

b. sort the array of employees into alphabetical order (by last name, you may assume last names will be unique)

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

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

e. 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

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

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

g. 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

h. 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)

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

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

Formatting Specifications

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

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

c. All commands will be capital letters.

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

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

f. Include dollar signs ($) for all dollar amounts.


NOTES and OTHER REQUIREMENTS:

FUNCTIONS MUST BE USED TO MODULARIZE THE PROGRAM. At least 5 functions (besides main) must be implemented. The functions must be meaningful.

Assumptions about input:

the data files will exist and will not be empty

each input value will be separated by whitespace (blanks and/or linefeeds)

the last line in each data file will be terminated with a linefeed (' ')

Program must be designed to interactively prompt the user for the name of each input file in the order described above. Filestream variable(s) must be used to represent files.

All output will be written to the screen.

Include header files for all library functions used.

Each input file can only be read one time.

Sample terminal session:
[keys]$ more employees
max martin 123 F 20.00
Michael Malloy 56 P 7.50
maRy MiLLs 555 F 17.50
mAUry miLsAp 89 F 6.15
[keys]$ more changes
555 P 18.25
11 nonsense to be ignored
56 S F
555 S P
[keys]$ more hrsworked
123 7.5
56 6.0
99 invalid id#
555 2.5
56 40.0
123 10.0
[keys]$ g++ assign06.cpp
[keys]$ ./a.out
Enter name of first data file
employees

NAME                        ID#    STATUS       RATE
Malloy,Michael               56       P    $    7.50
Martin,Max                  123       F    $   20.00
Mills,Mary                  555       F    $   17.50
Milsap,Maury                 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

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

Enter name of third data file
hrsworked

NAME                    PAY RATE     HOURS       TOTAL
Malloy,Michael           $ 7.50     46.00    $    367.50
Martin,Max               $ 20.00     17.50    $    350.00
Mills,Mary               $ 18.25      2.50    $     45.62
Milsap,Maury             $ 6.15      0.00    $      0.00
TOTAL                                66.00    $    763.12

*DO NOT USE ALGORITHM, VECTORS, TIME, OR SSTREAM TO SOLVE THE PROBLEM. YOU MUST USE STRUCTS TO HELP SOLVE THE PROBLEM.
Please add comments to the program if possible.


Here is what bubblesort is if you don't know it, I might have to use it in the program:

void bubblesort(int list[ ],int count)

// Sort an array of integers into descending order.
// Parameters:

//     list: array of integers to be sorted

//     count: (integer) number of values in the array

// Value passed back: sorted list
{
   int temp;   //place holder when values are interchanged
   for (int i=0; i < count-1; i++)
       for (int j=0; j < count-(i+1); j++)
         if (list[j] < list[j+1])
         {
            temp = list[j];
            list[j] = list[j+1];
            list[j+1] = temp;
         }
}

Here's a start to the code, these are the only header files you will use:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cctype>
#include <cmath>
using namespace std;

struct employee
{

}
int main()
{

return 0;
}

Explanation / Answer

First Part and the third part has been completed. Please find the code snippet.

However the second part is still pending. Can you please apply the same logic and solve the second part.

// Employee_Database.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct employee{
   char *strFirst;
   char *strLast;
   int id;
   char cJobStatus;
   double dPayrate;
   double dHoursWorked;
};

void main()
{
   employee emp[4];
   ifstream infile;
   ifstream hrsWorkedFile;
   ifstream changes;
   infile.open("D:\Users\Rohit Bhaiya\Desktop\employee.txt");
   hrsWorkedFile.open("D:\Users\Rohit Bhaiya\Desktop\hrsworked.txt");
   changes.open("D:\Users\Rohit Bhaiya\Desktop\changes.txt");
   string word;
   int count = 1,j = 0;
   while (infile >> word)
   {
       if(count==1)
       {
           emp[j].strFirst = (char*)malloc(100);
           strcpy(emp[j].strFirst,word.c_str());
           emp[j].strFirst[0] = toupper( emp[j].strFirst[0] );

           for( std::size_t i = 1 ; i < 10; ++i )
               emp[j].strFirst[i] = tolower( emp[j].strFirst[i] );
       }
       else if(count==2)
       {
           emp[j].strLast = (char*)malloc(100);
           strcpy(emp[j].strLast,word.c_str());
           emp[j].strLast[0] = toupper( emp[j].strLast[0] );

           for( std::size_t i = 1 ; i < 10; ++i )
               emp[j].strLast[i] = tolower( emp[j].strLast[i] );
       }
       else if(count==3)
       {
           emp[j].id = atoi(word.c_str());
       }
       else if(count==4)
       {
           emp[j].cJobStatus = *word.c_str();
       }
       else if(count==5)
       {
           emp[j].dPayrate = atof(word.c_str());
           j++;
           count = 0;
       }
       count++;
   }
   int flag = 0,i;
   while (hrsWorkedFile >> word)
   {
       if(flag==1)
       {
           emp[i].dHoursWorked = atof(word.c_str());
           flag = 0;
           continue;
       }
       for(i=0;i<4;i++)
       {
           if(emp[i].id == atoi(word.c_str()))
           {
               flag = 1;
               break;
           }
       }
   }

   cout<<"NAME "<<"ID# "<<"STATUS "<<"RATE"<<" ";
   for(int i=0;i<4;i++)
   {
       cout<<emp[i].strLast<<","<<emp[i].strFirst<<" ";
       cout<<emp[i].id<<" ";
       cout<<emp[i].cJobStatus<<" ";
       cout<<emp[i].dPayrate<<" ";
       cout<<" ";
   }
   cout<<" ";

   char cflag;
   int id,k;
   flag = 0;
   count = 1;
   while (changes >> word)
   {
       if(count==1)
       {
           id = atoi(word.c_str());
           count = 0;
       }

       if(flag==1)
       {
           cflag = *word.c_str();
           flag = 0;
           continue;
       }

       if(cflag == 'P')
       {
           emp[k].dPayrate = atof(word.c_str());
           count = 1;
           cflag = ' ';
           continue;
       }

       if(cflag == 'S')
       {
           emp[k].cJobStatus = *word.c_str();
           count = 1;
           cflag = ' ';
           continue;
       }

       for(k=0;k<4;k++)
       {
           if(emp[k].id == id)
           {
               flag = 1;
               break;
           }
       }
   }

   cout<<"NAME "<<"ID# "<<"STATUS "<<"RATE"<<" ";
   for(int i=0;i<4;i++)
   {
       cout<<emp[i].strLast<<","<<emp[i].strFirst<<" ";
       cout<<emp[i].id<<" ";
       cout<<emp[i].cJobStatus<<" ";
       cout<<emp[i].dPayrate<<" ";
       cout<<" ";
   }
   _getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote