international computer consulting company. Due to the enormous growth of the com
ID: 3536844 • Letter: I
Question
international computer consulting company.
Due to the enormous growth of the company, it has become necessary to create a payroll
program, which calculates employee salaries.
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).
Explanation / Answer
This is beta version, I am currently removing bugs(if have any).
To execute, plz make a file employee.dat
and also, rate me 5 stars or no stars..
Plz do justice with my time and hard work
#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);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.