I am working on a project called Payroll Management System... and am using C as the platform.
The project will look to ADD..VIEW..DELETE..& EDIT employee details. All this will be done by the Administrator.
I have been working on it a bit lately.. and i know before i seek help.. i need 2 post what ever i have done...
i am a little weak with the files concept... but whatever i have done i m posting here.. glad if i could get feedback and help.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
struct user
{
int eno;
char name[50];
float basic,allow,deduct;
};
void addEmp(); //Adds new record to database
void disEmp(); //Displays all records from database
void delEmp(); //Requests Employee No and removes record from database
void modEmp(); //Requests Employee No and enables re-entry of data
void main()
{
int choice;
clrscr();
printf("\n==============WELCOME ADMIN !==============\n");
printf(" 1 -> Add Record\n");
printf(" 2 -> Display Record\n");
printf(" 3 -> Delete Record\n");
printf(" 4 -> Modify Record\n\n");
printf(" 0 -> Exit\n\n");
printf(" Selection : ");
scanf("%d",&choice);
switch(choice)
{
case 0: break;
case 1: addEmp(); break;
case 2: disEmp(); break;
case 3: delEmp(); break;
case 4: modEmp(); break;
default: clrscr(); main();
}
}
void addEmp()
{
user e;
int choice;
do
{
clrscr();
printf("\n==============ADD RECORD==============\n");
printf(" Employee Number :\t");
scanf("%d",&e.eno);
printf("\n Name :\t");
fflush(stdin);
gets(e.name);
printf("\n Basic Salary :\t");
scanf("%f",&e.basic);
printf("\n Allowances :\t");
scanf("%f",&e.allow);
printf("\n Deductions :\t");
scanf("%f",&e.deduct);
printf("\n\n 1 -> Save\n 2 -> Cancel\n Selection : ");
scanf("%d",&choice);
}
while(!(choice==1)||(choice==2));
if(choice==1)
{
printf("\nRecord Saved.");
}
else
{
printf("\nRecord Cancelled.");
}
printf("\nEnter Another Record?");
printf("\n 1 -> Yes\n 2->No\n Selection : ");
scanf("%d",&choice);
if(choice==1)
addEmp();
else
return;
main();
}
void disEmp()
{
user e;
clrscr();
{
printf("\n===============PAYSLIP - EMP.NO : %d===============\n",e.eno);
printf("\n Name :\t%s",e.name);
printf("\n Basic Salary :\t%f",e.basic);
printf("\n Allowances :\t%f",e.allow);
printf("\n Deductions :\t%f",e.deduct);
printf("\n Gross Salary :\t%f",e.basic+e.allow);
printf("\n Net Salary :\t%f",e.basic+e.allow-e.deduct);
printf("\n===================================================\n");
}
main();
}
void delEmp()
{
fstream data,temp;
user e;
int eno;
clrscr();
printf("\n==============DELETE RECORD==============\n");
printf("Enter Employee No. to delete record :");
scanf("%d",&eno);
rename("data.dat","temp.dat");
data.open("data.dat",ios::app);
temp.open("temp.dat",ios::in);
temp.seekg(0,ios::beg);
while(temp.read((char*)&e,sizeof(e))){
if(!(e.eno==eno)){
cout<<"Record to delete "<<e.eno;
data.write((char*) &e,sizeof(e));
}
}
data.close();
temp.close();
system("Del temp.dat");
main();
}
void modEmp()
{
fstream data,temp;
user e;
int eno;
clrscr();
printf("\n==============MODIFY RECORD==============\n");
printf("Enter Employee No. to modify record :");
scanf("%d",&eno);
rename("data.dat","temp.dat");
data.open("data.dat",ios::app);
temp.open("temp.dat",ios::in);
temp.seekg(0,ios::beg);
while(temp.read((char*)&e,sizeof(e))){
if(!(e.eno==eno)){
cout<<"Record to delete "<<e.eno;
data.write((char*) &e,sizeof(e));
}
}
data.close();
temp.close();
system("Del temp.dat");
main();
}