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

Your task as a programmer is to create a menu driven program. Your program must-

ID: 3557744 • Letter: Y

Question

Your task as a programmer is to create a menu driven program. Your program must-reads from already existing data file data.txt which contains the unknown number of records.

You may think of record as struct in C:

Define Employee as struct with the following field:

First Name

Last Name

Gender

Social Security

Age

Hours Worked

Rate

A pointer to Employee

The salary should be calculated on the weekly basis of 40 hours. Any time over 40 hours worked, is considered to be overtime. When working overtime, employees get paid 1.5 of their normal salary. (For example: If an employee worked an hour overtime, and he was normally paid $20.00 per hour, his overtime would be calculated as $20.00 x 1.5 = $30.00)

Since you have unknown number of records in Data.txt file. You must create

A link list.

Your Menu should allow the user to add, delete, print, sort by last name and

Save the result of operation into file name result.txt.

Sample

1. List all employees to the screen with their salary.

            2. Add an employee to the payroll.

            3. Delete an employee from the payroll.

            4. List all the female employees.

            5. List all employees with overtime.

            8. Quit and Save.

Extra Credit: provide necessary functions to allow two employee of opposite

Sex to get married or divorce. Also function to print married people with their

Spouse first name.

Explanation / Answer

COMPLETE PROGRAM

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct xrec
{//information about the worker//
char FirstName[11];
char LastName[11];
char SSN[12];
char Gender;
double Hours, Rate, Salary;
}

void PrintEmployees(struct xrec a[], int n);
void ComputeSalary(struct xrec a[], int n);
int DisplayMenu(void);
int Search(struct xrec a[], int n, char * t);
int main ()
{
struct xrec Temp;
struct xrec Max[100];
int Size=0, Com, i, d, j, k, x, temp, Final;
char TSSN[12];

FILE *infile;
//to open files//
infile =fopen("Data.txt", "r");
if(infile==NULL)

//if file does not exist//
{printf("File Not Found ");
exit(0);
}
while(fscanf(infile,"%10s 510s %c %lf %lf",Temp.FirstName,Temp.LastName,Temp.SSN, EOF))
{
Temp.FirstName[10] ='';
Temp.LastName[10]='';
Temp.SSN[12]='';
Max[Size++]=Temp;
}fclose(infile);
ComputeSalary(Max,Size);
do
{
Com=DisplayMenu();
switch(Com)
{//to print information//
case1:
PrintEmployees(Max,Size);
break;
case2:
printf("First Name:");
fflush(stdin);
gets(Temp.FirstName);
printf("Last Name:");
fflush(stdin);
gets(Temp.LastName);
printf("SSN:");
fflush(stdin);
gets(Temp.SSN);
printf("Gender:");
fflush(stdin);
scanf("%c",&Temp.Gender);
printf("Rate:");
scanf("%lf",&Temp.Rate);
printf("Hours:");
scanf("%lf",&Temp.Hours);
Max[Size++]=Temp;
ComputeSalary(Max,Size);
break;
case3:
printf("SSN:");
fflush(stdin);
gets(TSSN);
d=Search(Max,Size,TSSN);
if(d<0)
printf("Invalid SSN");
else
{Max[d]=Max[--Size];
}break;
case4:
case5:
case6:
for(x=0;x<Size ; x++)
{
for(k=0;k<Size-1;k++)
{
for(j=0;j<Size-1-k;j++)
{
Final=strcmp()Max[j].LastName,Max[j+1];
if(Final>0)
{

Max[j]=Max[j+1];
}
}
}
printf("%10s,%10s",Max[ x].LastName, Max[ x].FirstName);
}break;
case7:
case8:
infile=fopen("Data.txt","w");
for(i=0;i<Size;i++)
fprintf(infile, "%10s %10s %11s %c %lf %lf ",Max[i].FirstName,
Max[i].LastName,Max[i].SSN, Max[i].Gender,Max[i].Hours, Max[i].Rate );
printf("File is Updated");
fclose(infile);
break;
default:printf("Invalid Input");
break;}}
while(Com!=8);
return 0;
}
int Search(struct xrec a[], int n, char *t)
{int i;
for(i=0;i<n;i++)
if(strcmp(a[i].SSN,t)==0)
return i;
return -1;}
int DisplayMenu(void)
//display menu choices 1,2,3,4,5,6,7,8//
{int Choice;
printf("1.List All Employees to the Screen With Their Salary.");
printf("2.Add an Employee to the Payroll.");
printf("3.Delete an Employee From the Payroll");
printf("4.List All the Female Employeesn");
printf("5.List All Employees With Overtime");
printf("6.Alphabetize the List of Employees");
printf("7.Who Gets the Highest Salary");
printf("8.Quit and Save.");
printf("Your Choice: ");
scanf("%d",&Choice);
return Choice;}