16.3k views
3 votes
Write a program that will create an array of Employees and calculate their weekly salary. For the employee structure you need to store eid, name, address, hourly Rate, total Hours, bonus, and, salary. You need to ask the user for the number of employees in the company. Then create an array of Employee structure of that size. Next, take details of all employees by creating a user-defined function named readEmployee. Next, compute the weekly salary of each employee and finally print into the output. Create two more user-define functions named Compute Salary and PrintEmployee to generate gross salary and print employee details into output. You have to store the result into a text file named EmployeeSalary.txt as well. [Note: You have to use Structure and File I/O. Use pointers wherever necessary.]

User Yuvrajsinh
by
3.9k points

1 Answer

5 votes

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;

}

User Reticulated Spline
by
4.1k points