Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- /* structure to store employee salary details */
- struct employee {
- int empId;
- char name[255];
- int basic, bonus;
- int absent, salaryDeduc;
- float gross, net;
- };
- /* prints payslip for the requested employee */
- void printSalary(struct employee e1) {
- printf("\n\t\t************************************************");
- printf("\n\t\t* EMPLOYEE OFFICIAL PAY SLIP *");
- printf("\n\t\t************************************************\n");
- printf("\n\t\tName: \t\t\t %s", e1.name);
- printf("\n\t\tEmployee ID: \t\t %d", e1.empId);
- printf("\n\n\t\tBasic Salary: \t\t %d", e1.basic);
- printf("\n\t\tBonus: \t\t\t %d", e1.bonus);
- printf("\n\t\t------------------------------------------------");
- printf("\n\t\tGross Salary: \t\t %.2f PHP", e1.gross);
- printf("\n\t\t------------------------------------------------\n");
- printf("\n\n\t\tDeductions (4%% per absent)");
- printf("\n\t\tSalary Deduction: (Absent * 0.04) x Basic Salary");
- printf("\n\t\tSalary Deduction: \t %d", e1.salaryDeduc);
- printf("\n\t\t------------------------------------------------");
- printf("\n\t\tNet Salary: \t\t %.2f PHP", e1.net);
- printf("\n\t\t------------------------------------------------\n\n");
- }
- /* display all the employee records entered */
- void display(struct employee e1) {
- printf("\n\t\t____________________________________________\n");
- printf("\t\tEmployee ID: \t\t %d", e1.empId);
- printf("\n\t\t--------------------------------------------\n");
- printf("\t\tEmployee Name: \t %s", e1.name);
- printf("\n\t\tBasic Salary: \t %d", e1.basic);
- printf("\n\t\tBonus: \t\t %d", e1.bonus);
- printf("\n\t\tAbsent: \t %d", e1.absent);
- }
- int main() {
- int i, num, flag, empID;
- int choice;
- struct employee *e1;
- printf("\n\t\t************************************************");
- printf("\n\t\t* EMPLOYEE PAYROLL SYSTEM *");
- printf("\n\t\t************************************************\n");
- /* get the number of employees from the user */
- printf("\n\t\tEnter the number of employees:");
- scanf("%d", &num);
- /* dynamically allocate memory to store employee salary details */
- e1 = (struct employee *)malloc(sizeof(struct employee) * num);
- system("cls");
- printf("\n\t\t************************************************");
- printf("\n\t\t* EMPLOYEE PAYROLL SYSTEM *");
- printf("\n\t\t************************************************\n");
- /* get the employee salary details from the customer */
- printf("\n\t\tEnter details for every employee:\n");
- for (i = 0; i < num; i++) {
- printf("\n\t\tEmployee ID: ");
- scanf("%d", &(e1[i].empId));
- fflush(stdin);
- printf("\t\tEmployee Name: ");
- gets(e1[i].name);
- printf("\n\t\tBasic Salary: PHP ");
- scanf("%d", &(e1[i].basic));
- printf("\t\tBonus: PHP");
- scanf("%d", &(e1[i].bonus));
- printf("\n\t\tEnter the deductions: \n");
- printf("\t\tAbsent: ");
- scanf("%d", &(e1[i].absent));
- printf("\n");
- }
- /* printing payslip for the given employee ID */
- while (1) {
- printf("\n\n\t\t[1] SHOW ALL RECORDS\n");
- printf("\t\t[2] ADD NEW EMPLOYEE RECORD\n");
- printf("\t\t[3] PRINT THE SALARY SLIP\n");
- printf("\t\t[4] EXIT\n");
- printf("\n\t\tEnter your choice : ");
- scanf("%d", &choice);
- switch(choice){
- case 1 : /*printing all the records entered before printing the slip */
- printf("\n\t\t************************************************");
- printf("\n\t\t* EMPLOYEE LIST *");
- printf("\n\t\t************************************************\n");
- for (i = 0; i < num; i++) {
- display(e1[i]);
- }
- printf("\n\n");
- break;
- case 2 : /*adding a new member in the employee list created */
- printf("\n\t\t************************************************");
- printf("\n\t\t* ADD NEW EMPLOYEE *");
- printf("\n\t\t************************************************\n");
- num++;
- i = num-1;
- printf("\n\t\tEmployee ID: ");
- scanf("%d", &(e1[i].empId));
- fflush(stdin);
- printf("\t\tEmployee Name: ");
- gets(e1[i].name);
- printf("\n\t\tBasic Salary: PHP ");
- scanf("%d", &(e1[i].basic));
- printf("\t\tBonus: PHP");
- scanf("%d", &(e1[i].bonus));
- printf("\n\t\tEnter the deductions: \n");
- printf("\t\tAbsent: ");
- scanf("%d", &(e1[i].absent));
- printf("\n");
- break;
- case 3 : /* gross and net salary calculation */
- for (i = 0; i < num; i++) {
- e1[i].gross = e1[i].basic + e1[i].bonus;
- e1[i].salaryDeduc = (0.04 * e1[i].absent) * e1[i].basic;
- e1[i].net = e1[i].gross - e1[i].salaryDeduc;
- }
- printf("\n\t\t************************************************");
- printf("\n\t\t* EMPLOYEE OFFICIAL PAY SLIP *");
- printf("\n\t\t************************************************\n");
- printf("\n\t\tEnter employee ID to get payslip:");
- scanf("%d", &empID);
- flag = 0;
- for (i = 0; i < num; i++) {
- if (empID == e1[i].empId) {
- printSalary(e1[i]);
- flag = 1;
- }
- }
- if (!flag) {
- printf("\n\n\t\tNo Record Found!!\n");
- }
- break;
- case 4 :
- exit(0);
- break;
- default:
- printf("\n\t\tInvalid Choice");
- }
- printf("\n\t\tPress any key to go back in Main Menu...");
- getch();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment