Answer:
See explaination
Step-by-step explanation:
#include <stdio.h>
#include <malloc.h>
typedef struct {
int eid;
char name[30];
char address[50];
float hourlyRate;
int totalHours;
float bonus;
float salary;
}employee;
void readEmployee(employee *employees, int size){
int i;
for(i = 0; i < size; ++i){
printf("Enter details of employee %d\\", i + 1);
printf("Enter eid: ");
scanf("%d", &employees[i].eid);
printf("Enter name: ");
scanf("%s", employees[i].name);
printf("Enter address: ");
scanf("%s", employees[i].address);
printf("Enter hourly rate: ");
scanf("%f", &employees[i].hourlyRate);
printf("Enter total hours: ");
scanf("%d", &employees[i].totalHours);
printf("Enter bonus percentage: ");
scanf("%f", &employees[i].bonus);
}
}
void ComputeSalary(employee *employees, int size){
int i;
for(i = 0; i < size; ++i){
employees[i].salary = (1 + (employees[i].bonus / 100.0)) * employees[i].hourlyRate * employees[i].totalHours;
}
}
void PrintEmployee(employee *employees, int size){
int i;
for(i = 0; i < size; ++i){
printf("Employee %d\\", i + 1);
printf("Eid: %d\\", employees[i].eid);
printf("Name: %s\\", employees[i].name);
printf("Address: %s\\", employees[i].address);
printf("Total hours: %d\\", employees[i].totalHours);
printf("Hourly rate: $%.2f\\", employees[i].hourlyRate);
printf("Bonus: %.2f%%\\", employees[i].bonus);
printf("Salary: $%.2f\\", employees[i].salary);
}
}
int main(){
int i, size;
employee *employees;
printf("Enter number of employees: ");
scanf("%d", &size);
employees = (employee *) malloc(sizeof(employee) * size);
readEmployee(employees, size);
ComputeSalary(employees, size);
PrintEmployee(employees, size);
return 0;
}