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: 3537139 • Letter: Y

Question



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



The record should consist of the following fields for each employee:


First Name


Last Name


Social Security Number


Gender (Male or Female)


Hours Worked




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)



The menu should contain the following choices:

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 (Roses of the G-ds).

5. List all employees with overtime

6.    Alphabetize the list of employees.

7.    Who gets the highest salary.

8. Quit and Save.




Please note: If an employee is deleted from the database, he/she should no longer exist in the database, when the program is rerun.



Please comment your program adequately and name it 6.c(Points will be deducted if there are no comments, or the program is incorrectly named).



Note : you receive 20 more points if you do it dynamically (link list)



PLEASE ANSWER WITH C LANGUAGE, NOT C++ OR JAVA! WILL RATE PROPERLY






Explanation / Answer

first make a file employee.dat



#include <stdio.h>

#include <string.h>


struct Employee

{

char FirstName[20];

char LastName[20];

int ssn;

char Gender;

long hrs;

int salary;

};


int main()

{

while(1==1)

{

printf("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 (Roses of the G-ds). 5. List all employees with overtime. 6. Alphabetize the list of employees. 7. Who gets the highest salary. 8. Quit and Save. ");

int choice=0;

int num=0;

int i=0,j;

struct Employee Employees[100];

scanf("%d",&choice);


FILE *fp;

fp = fopen("employee.dat", "r");

char FirstName[20];

char LastName[20];

int ssn;

char Gender;

int hrs;

int salary;

while(!feof(fp))

{

fscanf(fp,"%s %s %d %c %d",&FirstName,&LastName,&ssn,&Gender,&hrs);

if(hrs>40)

{

salary=((hrs-40)*1.5*20)+(20*40);

}

else

{

salary=(hrs*20);

}

strncpy(Employees[num].FirstName,FirstName,sizeof(Employees[num].FirstName));

strncpy(Employees[num].LastName,LastName,sizeof(Employees[num].LastName));

Employees[num].Gender=Gender;

Employees[num].ssn=ssn;

Employees[num].salary=salary;

Employees[num].hrs=hrs;


num++;

}

fclose(fp);


if(choice==1)

{

printf("FirstName LastName Gender Hrs SSN Salary ");

for(i=0;i<num-1;i++)

{

printf("%s %s %c %d %d %d ",Employees[i].FirstName,Employees[i].LastName,Employees[i].Gender,Employees[i].hrs,Employees[i].ssn,Employees[i].salary);

}

printf(" ");

}

if(choice==2)

{

printf("Enter the employee's firstname ");

scanf("%s",&FirstName);

printf("Enter the employee's lastname ");

scanf("%s",&LastName);

printf("Enter the employee's SSN ");

scanf("%d",&ssn);

printf("Enter the employee's Hrs ");

scanf("%d",&hrs);

printf("Enter the employee's Gender ");

scanf("%s",&Gender);



strncpy(Employees[num].FirstName,FirstName,sizeof(Employees[num].FirstName));

strncpy(Employees[num].LastName,LastName,sizeof(Employees[num].LastName));

Employees[num].Gender=Gender;

Employees[num].salary=salary;

Employees[num].ssn=ssn;

Employees[num].hrs=hrs;

num++;


fp = fopen("employee.dat", "a+");

fprintf(fp,"%s %s %d %c %d ",FirstName,LastName,ssn,Gender,hrs);


fclose(fp);


printf("Successully entered the employee ");

}

if(choice==3)

{

char name[20];

printf("Enter the employee name to be deleted: ");

scanf("%s",&name);

FILE *newfp;

newfp =fopen("temp.dat","w");


for(i=0;i<num;i++)

{

if(strcmp(Employees[i].FirstName,name)!=0)

{

fprintf(newfp,"%s &s %c %d %d ",Employees[i].FirstName,Employees[i].LastName,Employees[i].Gender,Employees[i].hrs,Employees[i].ssn);

}

}

fclose(newfp);

int status=remove("employee.dat");

if(status==0)

{

rename("temp.dat","employee.dat");

printf("Successfully deleted employee ");

num--;

}

else

{

printf("Employee can't be deleted. There is some problem ");

}


}

if(choice==4)

{

for(i=0;i<num;i++)

{

if((Employees[i].Gender=='F')||(Employees[i].Gender=='f'))

{

printf("%s %s %c %d %d %d ",Employees[i].FirstName,Employees[i].LastName,Employees[i].Gender,Employees[i].hrs,Employees[i].ssn,Employees[i].salary);

}

}

printf(" ");

}

if(choice==5)

{

for(i=0;i<num;i++)

{

if(Employees[i].hrs>40)

{

printf("%s %s %c %d %d %d ",Employees[i].FirstName,Employees[i].LastName,Employees[i].Gender,Employees[i].hrs,Employees[i].ssn,Employees[i].salary);

}

printf(" ");

}

}

if(choice==6)

{

char temp[100][20];

char dummy[20];

for(i=0;i<num;i++)

{

strcpy(temp[i],Employees[i].FirstName);

strcat(temp[i]," ");

strcat(temp[i],Employees[i].LastName);

}

for(i=1;i<num-1;i++)

{

for(j=1;j<num-i;j++)

{

if(strcmp (temp[j-1], temp[j]) > 0)

{

strcpy(dummy, temp[j-1]);

strcpy(temp[j-1], temp[j]);

strcpy(temp[j], dummy);

}

}

}

for(i=0;i<num;i++)

{

printf("%s ",temp[i]);

}

}


if(choice==7)

{

int max=0;

int maxe=0;

for(i=0;i<num;i++)

{

if(i==0)

{

max=Employees[i].salary;

maxe=i;

}

else

{

if(max<Employees[i].salary)

{

max=Employees[i].salary;

maxe=i;

}

}


}

printf("%s %s has max salary: %d ",Employees[maxe].FirstName,Employees[maxe].LastName,Employees[maxe].salary);

printf(" ");


}

if(choice==8)

{

exit(1);


}

}

}