Payroll Data Entry using file handling in c
Here you will get a source code of Payroll Data Entry using File handling in C example with c language.
File Handling in c is the process for storing the data in a file using programming. It used for creating, reading, writing, deleting, manipulating, and organizing files on a storage device. Thereafter whenever we required, we can extract data from the file to work in the program.
File Handling in C
This File handling program require Employee’s details such as employee id, employee name, basic pay as input, calculates dearness allowance, house rent allowance, income tax & net salary and stores this details in files named payroll. Then again open the files in read mode and display the entire data of file.
Information of variable represents values:
eid – Employee id
ename – Employee name
basic – Basic pay
da – Dearness aloowance
hra – House rent allowance
tax – Income tax
gross – Gross salary
net – Net salary
The values of da, hra, tax, gross and net after calculated :
da=25% of basic
hra=10% of basic
gross=basic+da+hra
tax=30% of gross
net=gross-tax
Payroll Data Entry using file handling in c example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include<stdio.h> #include<conio.h> void main() { struct payroll { int eid; char ename[15]; int basic; float da,hra,tax; float gross,net; }p; char c; FILE *fp; //clrscr(); fp=fopen("payroll","a"); printf("Enter Employee Id, Name, Basic Pay:n"); while(scanf("%d%s%d",&p.eid,p.ename,&p.basic)!=EOF) { p.da=p.basic*.25; p.hra=p.basic*.1; p.gross=p.basic+p.da+p.hra; p.tax=p.gross*.3; p.net=p.gross-p.tax; fwrite(&p,sizeof(p),1,fp); } fclose(fp); fp=fopen("payroll","r"); printf("Contents of file:\n"); printf("__________________________________________________\n"); while(fread(&p,sizeof(p),1,fp)) { printf("\nEmployee Id :%d",p.eid); printf("\nEmployee Name :%s",p.ename); printf("\nBasic Pay :%d",p.basic); printf("\nDearness Allowance :%f",p.da); printf("\nHouse Rent Allowance :%f",p.hra); printf("\nIncome Tax :%f",p.tax); printf("\nNet Salary :%f",p.net); printf("\n--------------------------------------------------------------------\n"); } fclose(fp); getch(); } |
Output
Enter Employee Id, Name, Basic Pay:
101
Sam
8000
102
Adam
7000
103
Jhon
6000
^Z
Contents of file:
Employee Id :101
Employee Name :Sam
Basic Pay :8000
Dearness Allowance :2000.000000
House Rent Allowance :800.000000
Income Tax :3240.000000
Net Salary :7560.000000
Employee Id :102
Employee Name :Adam
Basic Pay :7000
Dearness Allowance :1750.000000
House Rent Allowance :700.000000
Income Tax :2835.000000
Net Salary :6615.000000
Employee Id :103
Employee Name :Jhon
Basic Pay :6000
Dearness Allowance :1500.000000
House Rent Allowance :600.000000
Income Tax :2430.000000
Net Salary :5670.000000
Check out our other C programming Examples