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

Problem statement: Create a program that will read an employee file, as below, c

ID: 3773233 • Letter: P

Question

Problem statement: Create a program that will read an employee file, as below,

create a output payroll register file, and then search the newly created file(using binary   
search algorithm)

The output file, or payroll register file, ( user chooses name ) is to have the following data

( each employee on one line )

a. Employee number ( left justified )

b. Department

  c. Pay Rate

d. Exempt

e. Hours Worked

f. Base Pay ( pay rate * hours worked )

g. Overtime pay

h. Total pay

Overtime pay is calculated only for nonexempt employees.
An employee is exempt if a “Y” appears in    the exempt column. Overtime is paid for all hours worked over 40. Overtime multiplier is 1.5. If an exempt employee works over 40 hours, the employee is only paid for 40 hours of work.  
Now ask the user if they wish to search the payroll register file.
   If yes, load the employee records from the register file into an array of struct   Assume there are at most fifty records.
   The user will be prompted for an employee number,
Do a binary search on the array of employee structs, determining if the employee   
is in the database.
If employee is in the database, print employee info,
If not, state so with an informational message. Repeat as long as the user wishes.
   The struct is to be named employRec and is to have at least 7 fields
   The array is to be named empArray
   The struct is to be declared in a file called employee.h along with function
prototypes
   The remaining functions for input/output file are to be in the files_ops.h and
files_ops.cpp. Function prototypes should be in the respective header file.
   Function main() is to be in a separate file called main.cpp

Here's a sample search
Please enter an employee number : 666
The record of employee with id 666 is
Department: xyz
PayRate   $xx.xx
Exempt: Y
Hours Worked : xxx

Base Pay :$xxxx.xx

Overtime : $xxxx.xx

Total Pay: $xxx.xx

Do you wish to search database?
Please enter an employee number : 129
   Employee seems not to exist

A sample text file ( “emp_data.txt” ) and binary search program is provided

TEXT FILE emp-data.txt

101 41 8.11 Y 49
666 1 66.66 Y 66
722 32 7.22 N 40
9876 23 9.99 N 39

Please provide output solution to prove your code works without error

Employee num Department PayRate Exempt Hours worked 101 41 8.11 Y 49 722 32 7.22 N 40 9876 23 9.99 N 39 666 1 66.66 Y 66

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int getData (FILE* spDataIn,
             int* empNo, int* dept, float* payRate, char* exempt, int* hours);
int writeData (FILE* spDataOut,
               int empNo, int dept, float payRate, char exempt, int hours, float basePay);
void calcBasePay (float payRate, int hours, float* basePay);

int main (void)
{

// Local Declarations
   FILE* spDataIn;
   FILE* spDataOut;

   int empNo;
   int dept;
   float payRate;
   char exempt;
   int hours;
   float basePay;

// Statements
   printf("Creates a payroll register... ");
   if (!(spDataIn = fopen("emp_data.txt", "r")))
   {
    printf("Error opening employee file ");
    return 100;
   }

   if (!(spDataOut = fopen("emp_data.txt", "w")))
   {
    printf("Error opening employee file ");
    return 102;
   } // of open output

   while (getData
         (spDataIn, &empNo, &dept, &payRate, &exempt, &hours))
    {
     calcBasePay (payRate, hours, &basePay);
     writeData (spDataOut, empNo, dept, payRate, exempt, hours, basePay);
    }

    fclose(spDataIn);
    fclose(spDataOut);

    printf("End employee payroll register ");
    return 0;
}

int getData (FILE* spDataIn, int* empNo, int* dept, float* payRate, char* exempt, int* hours)
{
// Local Declarations
   int ioResult;

// Statements
   ioResult = fscanf(spDataIn, "%d %d %f %c %d", empNo, dept, payRate, exempt, hours);

   if(ioResult == EOF)
   return 0;
   else
   return 1;
}

void calcBasePay (float payRate, int hours, float* basePay)
{

   *basePay = (payRate*hours);
   return;
}

int writeData (FILE* spDataOut, int empNo, int dept, float payRate, char exempt, int hours, float basePay)
{
   fprintf(spDataOut, "%d %d %f %c %d %f ", empNo, dept, payRate, exempt, hours, basePay);
   return 0;
}

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