Humana
Humana
USING C LANGUAGE
Submitted to:
Mr. Arlene Baldelovar
Submitted by:
James David A. Casocot
Chosen Grace S. Awiten
COMPUTER PROGRAMMING 1
PROGRAM DESCRIPTION
employee records efficiently, offering functionalities like adding, editing, deleting, searching
for employees, viewing payroll details, and generating payslips. Upon startup, the program
presents a welcome screen with the current date and time, followed by a login prompt for users
to enter a valid username and password. If the credentials are correct, users are granted access
to the main menu, where they can choose from several options, including adding a new
employee, viewing employee payroll, editing existing employee details, deleting employee
records, searching for employees, and generating payslips. Employee details, such as ID, name,
position, daily rate, hours worked, and deductions, are stored in a file.
When adding an employee, the program calculates the gross salary, deductions, and net
pay before saving the data to the file. For editing or deleting employee records, the program
uses file handling techniques to read the original file, modify the required data, and write the
changes to a temporary file, which replaces the original file. The payroll option allows users to
view all employee records, including their salary, deductions, and net pay, while the search
function enables the user to find specific employees by ID. The program can also generate and
display payslips, which include salary details. Once the user opts to exit, the system displays a
farewell message and closes. Designed to handle employee data securely, the system ensures
safe data management through login authentication and reliable file operations.
ALGORITHM
1. Start
2. Declare Variables:
• Create an employee structure to store employee details.
• Declare a global employee variable (e.g., struct employee emp).
• Declare file pointers (e.g., FILE fp, temp_fp).
• Declare variables for user input (e.g., int choice, int emp_id, char uname[10],
char pword[10]).
3. Welcome Screen:
• Display a welcome message with the current date and time.
• Wait for the user to press any key to continue.
4. User Login:
• Prompt the user to input a username and password.
• Validate the credentials:
➢ If valid, display a loading screen and proceed to the main menu.
➢ If invalid, allow up to three attempts before exiting the program.
5. Display Main Menu:
• Show options:
1. Add Employee.
2. View Payroll.
3. Edit Employee.
4. Delete Employee.
5. Search Employee.
6. Generate Payslip.
7. Exit.
• Read the user's choice and call the corresponding function.
6. Add Employee:
• Open the file EmployeeData.dat in append mode.
• Prompt the user to input employee details:
➢ Employee ID, name, position, daily rate, hours worked, SSS
deduction, PhilHealth deduction, and cash advance.
• Calculate:
➢ Gross salary = hours_worked × daily_rate.
➢ Total deductions = sss_deduction + philhealth_deduction +
cashAd_deduction.
➢ Net pay = gross_salary - deductions.
• Write the employee details to the file using fprintf.
• Close the file.
7. View Payroll:
• Open the file EmployeeData.dat in read mode.
• If the file is empty, display a "No records found" message.
• Otherwise, read each employee's data using a loop and display their payroll
details in a table format.
• Close the file.
8. Edit Employee:
• Open the file EmployeeData.dat in read mode and a temporary file in write
mode.
• Prompt the user for the Employee ID to edit.
• Search for the record:
➢ If found, prompt the user to edit the details, recalculate salary and
deductions, and write the updated data to the temporary file.
➢ If not found, write the original data to the temporary file.
• Replace the original file with the temporary file.
• Close both files.
9. Delete Employee:
• Open the file EmployeeData.dat in read mode and a temporary file in write
mode.
• Prompt the user for the Employee ID to delete.
• Copy all records except the one to delete to the temporary file.
• Replace the original file with the temporary file.
• Close both files.
10. Search Employee:
• Open the file EmployeeData.dat in read mode.
• Prompt the user for the Employee ID to search.
• If found, display the employee's details.
• If not found, display a "Record not found" message.
• Close the file.
11. Generate Payslip:
• Open the file EmployeeData.dat in read mode.
• Read and display each employee's payslip one at a time.
• Allow the user to navigate to the next payslip or return to the main menu.
• Close the file.
12. Exit the Program:
• Display a message and terminate the program.
13. End
FLOWCHART
PROGRAM SOURCE CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define ENTER 13
#define BKSP 8
#define SPACE 32
#define TAB 9
#define BAR_LENGTH 50
struct employee {
char name[40], position[20];
int emp_id;
float hours_worked, daily_rate;
float gross_salary, deductions, sss_deduction, philhealth_deduction, cashAd_deduction,
net_pay;
};
int main(void) {
welcome();
login();
}
while (*text) {
putchar(*text);
fflush(stdout);
Sleep(delay);
text++;
}
void welcome(void) {
time_t t;
time(&t);
char* ctime_str = ctime(&t);
ctime_str[strlen(ctime_str) - 1] = '\0';
system("cls");
setcolor(11);
print_centerNdelayed("___________________________________________________\n",
230, 2);
print_centerNdelayed("| |\n", 230, 2);
printf("\t\t\t\t\t\t\t\t\t\t\t | %s |\n", ctime_str);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| WELCOME TO PAYROLL SYSTEM |\n", 230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| PRESS ANY KEY TO CONTINUE |\n", 230, 2);
print_centerNdelayed("|_________________________________________________|\n",
230, 2);
getch();
system("cls");
}
void login(void) {
char uname[10], pword[10];
int attempts = 0;
int progress = 0;
int step = 1, i;
char bar[BAR_LENGTH + 1];
int j;
setcolor(11);
system("cls");
print_centerNdelayed("________________________________________________________
_________\n", 230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| PAYROLL SYSTEM |\n", 230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| LOGIN YOUR ACCOUNT |\n", 230,
2);
print_centerNdelayed("
|_______________________________________________________________|\n\n", 230, 2);
printf("Loading...\n");
system("cls");
printf("\n\n\t\t\t\t\t\t\t\t\tLoading: [");
setcolor(11);
system("cls");
print_centerNdelayed("__________________________________________________
\n",230, 2);
print_centerNdelayed("| |\n",230, 2);
print_centerNdelayed("| WELCOME TO PAYROLL SYSTEM |\n",230,
2);
print_centerNdelayed("| |\n",230, 2);
print_centerNdelayed("| PRESS ANY KEY TO CONTINUE |\n",230, 2);
print_centerNdelayed("|________________________________________________|\n",230,
2);
getch();
system("cls");
menu();
return;
} else {
attempts++;
system("cls");
setcolor(4);
print_centerNdelayed("__________________________________________________
\n", 230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| LOGIN FAILED! |\n", 230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| PRESS ANY KEY TO TRY AGAIN
|\n", 230, 2);
print_centerNdelayed("|________________________________________________|\n", 230,
2);
getch();
system("cls");
setcolor(11);
if (attempts == 3) {
int i = 5;
setcolor(4);
print_centerNdelayed("__________________________________________________
\n", 230, 2);
print_centerNdelayed("| |\n", 230,
2);
print_centerNdelayed("| You have exceeded the maximum login attempts! |\n",
230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| PRESS ANY KEY TO EXIT |\n", 230, 2);
print_centerNdelayed("|________________________________________________|\n", 230,
2);
getch();
while ( i > 0) {
system("cls");
printf("\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\tThe Program is Exciting in
%d", i);
sleep(1);
i--;
}
exit(0);
}
}
}
}
void menu(void) {
int choice;
while (1) {
system("cls");
printf("_________________________________________________________________\n");
printf("| |\n");
printf("| PAYROLL SYSTEM |\n");
printf("| |\n");
printf("| MAIN MENU |\n");
printf("|_______________________________________________________________|\n\n\n"
);
printf("\n1. Add Employee");
printf("\n2. View Payroll");
printf("\n3. Edit Employee");
printf("\n4. Delete Employee");
printf("\n5. Search Employee");
printf("\n6. Payslip");
printf("\n7. Exit");
printf("\n\nENTER THE NUMBER OF YOUR CHOICE: ");
scanf("%d", &choice);
printf("_________________________________________________________________\n");
printf("| |\n");
printf("| PAYROLL SYSTEM |\n");
printf("| |\n");
printf("| MAIN MENU |\n");
printf("|_______________________________________________________________|\n\n\n"
);
printf("\n1. Add Employee");
printf("\n2. View Payroll");
printf("\n3. Edit Employee");
printf("\n4. Delete Employee");
printf("\n5. Search Employee");
printf("\n6. Payslip");
printf("\n7. Exit");
setcolor(4);
printf("\n\nInvalid choice! Enter again: ");
scanf("%d", &choice);
setcolor(11);
}
switch (choice) {
case 1: add_employee(); break;
case 2: view_payroll(); break;
case 3: edit_employee(); break;
case 4: delete_employee(); break;
case 5: search_employee(); break;
case 6: payslip(); break;
case 7:
printf("\nExiting the system...\n");
exit(0);
break;
default:
setcolor(4);
printf("\nInvalid choice! Try again.\n");
scanf("%d", &choice);
setcolor(11);
getch();
}
}
}
void add_employee(void) {
FILE *fp;
char c;
do {
setcolor(11);
system("cls");
printf("_________________________________________________________________\n");
printf("| |\n");
printf("| PAYROLL SYSTEM |\n");
printf("| |\n");
printf("| ADD EMPLOYEE |\n");
printf("|_______________________________________________________________|\n\n");
fp = fopen("EmployeeData.dat", "a+");
if (!fp) {
printf("Error opening file!\n");
getch();
menu();
return;
}
printf("\nAdd another employee? (Press 'y' if yes and press any key if no): ");
c = getch();
} while (c == 'y' || c == 'Y');
menu();
}
void view_payroll(void) {
FILE *fp;
system("cls");
print_centerNdelayed("________________________________________________________
_________\n", 230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| PAYROLL SYSTEM |\n", 230, 2);
print_centerNdelayed("| |\n", 230, 2);
print_centerNdelayed("| EMPLOYEES RECORD |\n", 230, 2);
print_centerNdelayed("
|_______________________________________________________________|\n\n", 230, 2);
fp = fopen("EmployeeData.dat", "r");
if (fp == NULL) {
printf("No records found.\n");
printf("Press any key to return to the main menu...");
getch();
menu();
return;
}
printf("_____________________________________________________________________
___________________________________________________________________________
___________________________________________________________________\n");
printf("\n");
printf(" EMPLOYEES INFORMATION: SALARY:
DEDUCTIONS:\n\n");
printf(" Gross Salary
Total Deductions");
printf("\n %-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s
%-15s %-15s\n", "Employee ID", "Employee Name", "Position", "Days Worked",
"Rate/Day", " ", "SSS Deduction", "PhilHealth Deduction", "Cash Advance
Deduction", " ", "Net Pay");
printf("_____________________________________________________________________
___________________________________________________________________________
___________________________________________________________________\n");
void edit_employee(void) {
FILE *fp, *temp_fp;
int emp_id, found = 0;
char c;
system("cls");
printf("\n====================== PAYROLL SYSTEM
=========================");
printf("\n============================================================
===========\n");
printf("\n========================= EDIT EMPLOYEE
==============================\n");
fp = fopen("EmployeeData.dat", "r");
if (fp == NULL) {
printf("No records found.\n");
printf("Press any key to return to the main menu...");
getch();
menu();
return;
}
fprintf(temp_fp, "%d %s %s %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",
emp.emp_id, emp.name, emp.position, emp.hours_worked, emp.daily_rate,
emp.gross_salary, emp.sss_deduction, emp.philhealth_deduction, emp.cashAd_deduction,
emp.deductions, emp.net_pay);
} else {
fprintf(temp_fp, "%d %s %s %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",
emp.emp_id, emp.name, emp.position, emp.hours_worked, emp.daily_rate,
emp.gross_salary, emp.sss_deduction, emp.philhealth_deduction, emp.cashAd_deduction,
emp.deductions, emp.net_pay);
}
}
fclose(fp);
fclose(temp_fp);
if (found) {
remove("EmployeeData.dat");
rename("TempEmployeeData.dat", "EmployeeData.dat");
void delete_employee(void) {
FILE *fp, *temp_fp;
int emp_id, found = 0;
system("cls");
printf("\n====================== PAYROLL SYSTEM
=========================");
printf("\n============================================================
===========\n");
printf("\n========================= DELETE EMPLOYEE
============================\n");
fp = fopen("EmployeeData.dat", "r");
if (fp == NULL) {
printf("No records found.\n");
printf("Press any key to return to the main menu...");
getch();
menu();
return;
}
fclose(fp);
fclose(temp_fp);
if (found) {
remove("EmployeeData.dat");
rename("TempEmployeeData.dat", "EmployeeData.dat");
printf("\nEmployee record deleted successfully.\n");
} else {
printf("\nEmployee ID %d not found.\n", emp_id);
remove("TempEmployeeData.dat");
}
void search_employee(void) {
FILE *fp;
int emp_id, found = 0;
system("cls");
printf("\n====================== PAYROLL SYSTEM
=========================");
printf("\n============================================================
===========\n");
printf("\n======================== SEARCH EMPLOYEE
=============================\n");
fp = fopen("EmployeeData.dat", "r");
if (fp == NULL) {
printf("No records found.\n");
printf("Press any key to return to the main menu...");
getch();
menu();
return;
}
printf("_________________________________________________________________\n");
printf("Employees Info:\n\n");
printf(" Employee ID : %d\n", emp.emp_id);
printf(" Employee Name : %s\n", emp.name);
printf(" Position : %s\n\n", emp.position);
printf("_________________________________________________________________\n");
printf("Salary:\n\n");
printf(" Days Worked : %.2f\n", emp.hours_worked);
printf(" Rate/day : %.2f\n\n", emp.daily_rate);
printf(" Gross Salary : %.2f\n", emp.gross_salary);
printf("_________________________________________________________________\n");
printf("Deductions:\n\n");
printf(" SSS Deduction : %.2f\n", emp.sss_deduction);
printf(" PhilHealth Deduction : %.2f\n", emp.philhealth_deduction);
printf(" Cash Advance Deduction : %.2f\n\n", emp.cashAd_deduction);
printf(" Total Deductions : %.2f\n\n", emp.deductions);
printf("_________________________________________________________________\n");
printf(" Net Pay : %.2f\n", emp.net_pay);
printf("_________________________________________________________________\n");
break;
}
}
fclose(fp);
if (!found) {
printf("\nEmployee with ID %d not found.\n", emp_id);
}
void payslip(void) {
FILE *fp;
char c;
fp = fopen("EmployeeData.dat", "r");
if (fp == NULL) {
system("cls");
printf("No records found.\n");
printf("Press any key to return to the main menu...");
getch();
menu();
return;
}
printf("_________________________________________________________________\n");
printf("Employees Info:\n\n");
printf(" Employee ID : %d\n", emp.emp_id);
printf(" Employee Name : %s\n", emp.name);
printf(" Position : %s\n\n", emp.position);
printf("_________________________________________________________________\n");
printf("Salary:\n\n");
printf(" Days Worked : %.2f\n", emp.hours_worked);
printf(" Rate/day : %.2f\n\n", emp.daily_rate);
printf(" Gross Salary : %.2f\n", emp.gross_salary);
printf("_________________________________________________________________\n");
printf("Deductions:\n\n");
printf(" SSS Deduction : %.2f\n", emp.sss_deduction);
printf(" PhilHealth Deduction : %.2f\n", emp.philhealth_deduction);
printf(" Cash Advance Deduction : %.2f\n\n", emp.cashAd_deduction);
printf(" Total Deductions : %.2f\n\n", emp.deductions);
printf("_________________________________________________________________\n");
printf(" Net Pay : %.2f\n", emp.net_pay);
printf("_________________________________________________________________\n");
} else {
system("cls");
printf("No employee records found!\n");
fclose(fp);
printf("Press any key to return to main menu");
getch();
menu();
}
while(1){
printf("\nPress 'n' for next employee, 'x' to return to return main menu:
");
c = getch();
if (c == 'n' || c == 'N') {
if (fscanf(fp, "%d %s %s %f %f %f %f %f %f %f %f",
&emp.emp_id, emp.name, emp.position, &emp.hours_worked, &emp.daily_rate,
&emp.gross_salary, &emp.sss_deduction, &emp.philhealth_deduction,
&emp.cashAd_deduction, &emp.deductions, &emp.net_pay) != EOF) {
system("cls");
printf("\n====================== PAYROLL
SYSTEM =========================");
printf("\n============================================================
=====\n");
printf("\n================== PAYROLL SYSTEM
=======================\n\n\n");
printf("_______________________________________________________________
__\n");
printf("Employees Info:\n\n");
printf(" Employee ID : %d\n", emp.emp_id);
printf(" Employee Name : %s\n", emp.name);
printf(" Position : %s\n\n", emp.position);
printf("_________________________________________________________________\n");
printf("Salary:\n\n");
printf(" Days Worked : %.2f\n", emp.hours_worked);
printf(" Rate/day : %.2f\n\n", emp.daily_rate);
printf(" Gross Salary : %.2f\n", emp.gross_salary);
printf("_________________________________________________________________\n");
printf("Deductions:\n\n");
printf(" SSS Deduction : %.2f\n", emp.sss_deduction);
printf(" PhilHealth Deduction : %.2f\n", emp.philhealth_deduction);
printf(" Cash Advance Deduction : %.2f\n\n", emp.cashAd_deduction);
printf(" Total Deductions : %.2f\n\n", emp.deductions);
printf("_________________________________________________________________\n");
printf(" Net Pay : %.2f\n", emp.net_pay);
printf("_________________________________________________________________\n");
} else {
system("cls");
printf("\nReached the last employee.\n");
printf("Press any key to return to main menu...\n");
getch();
menu();
}
} else if (c == 'x' || c == 'X') {
menu();
} else {
printf("\nInvalid Choice.\n");
}
}
fclose(fp);
}
PROGRAM OUTPUT (SCREENSHOT)