You are on page 1of 7

//Employee & Project Management System for lab exercise for beginners in C.

#include<stdio.h>
#include<conio.h>

struct EmpData

{
int empid;
char ename[60];
float salary; //Employee details
float da;
float ta;
int pid;
}emp;

struct project

{
int pid;
char pname[60]; //project details
}pro;

FILE *femp,*fpro;
int rec,st;

void addEmp();
void addPro();
void listEmp();
int searchEmp();
void delEmp();
void listPro();
int searchPro();
void delPro();

main()
{

char ans, choice, ch1;


int flag,n;

rec=sizeof(emp);
st=sizeof(pro);

do
{
flag=1;
clrscr();
gotoxy(50,10);
textcolor(4);
printf("\n CONSTRUCTION COMPANY \n");
printf("\nPROJECT & EMPLOYEE MANAGEMENT SYSTEM");
printf("\n\n");

printf("[E] : EMPLOYEE MANAGEMENT SYSTEM ");


printf("[P] : PROJECT MANAGEMENT SYSTEM ");

printf("\n\t\t\tEnter Your Choice:");


fflush(stdin);
scanf("%c",&choice);
if(choice=='e'||choice=='E')
{
while(flag)
{
clrscr();
printf("\t\t EMPLOYEE MANAGEMENT SYSTEM");
printf("\n\t\t\t[A]Add record:");
printf("\n\t\t\t[L]List Record:");
printf("\n\t\t\t[S]Search Record:");
printf("\n\t\t\t[D]Delete Record:");
printf("\n\t\t\t[X]Exit To Main System:");
printf("\n\t\t\tEnter Your Choice:");
fflush(stdin);
scanf("%c",&ch1);
clrscr();
gotoxy(25,2);
textcolor(6);

printf("\t\t EMPLOYEE MANAGEMENT SYSTEM\n\n");

switch(ch1)
{
case 'a':
case 'A':
addEmp();
break;
case 'd':
case 'D':
delEmp();
break;
case 'l':
case 'L':
listEmp();
break;
case 's':
case 'S':
n=searchEmp();
break;
case 'x':
case 'X':
default:
flag=0;
printf("Control goes to Main Window");
}//switch
}//while
}//if
else
{
while(flag)
{
clrscr();
printf("\t\t PROJECT MANAGEMENT SYSTEM");
printf("\n\t\t\t[A]Add record:");
printf("\n\t\t\t[L]List Record:");
printf("\n\t\t\t[S]Search Record:");
printf("\n\t\t\t[D]Delete Record:");
printf("\n\t\t\t[X]Exit To Main System:");
printf("\n\t\t\tEnter Your Choice:");
fflush(stdin);
scanf("%c",&ch1);
clrscr();
gotoxy(25,2);
textcolor(6);

printf("\t\t PROJECT MANAGEMENT SYSTEM\n\n");

switch(ch1)
{
case 'a':
case 'A':
addPro();
break;
case 'd':
case 'D':
delPro();
break;
case 'l':
case 'L':
listPro();
break;
case 's':
case 'S':
n=searchPro();
break;
case 'x':
case 'X':
default:
flag=0;
printf("Control goes to Main Window");
}//switch
}//while
}//else

gotoxy(25,40);
fflush(stdin);
printf("\nDo you want to continue...(Y or N)");
scanf("%c",&ans);

}while(ans=='y'||ans=='Y');

printf("BYE..!!");
getch();
return 0;

}
//Function to add an employee to the file emp1.dat
void addEmp()

femp=fopen("d:\emp1.dat","a+");
fseek(femp,0,SEEK_END);
printf("\n\n\nEnter Employee ID:");
scanf("%d",&emp.empid);
printf("\n\n\nEnter Employee Name:");
scanf("%s",emp.ename);
printf("\n\n\nEnter Employee Salary:");
scanf("%f",&emp.salary);
printf("\n\nEnter Project Status:");
scanf("%d",&emp.pid);
emp.da=emp.salary*0.15;
emp.ta=emp.salary*0.10;
fwrite(&emp,rec,1,femp);

fclose(femp);

}
//Function to add a project to the file pro1.dat

void addPro()
{
fpro=fopen("d:\pro1.dat","a+");
fseek(fpro,0,SEEK_END);
printf("\n\n\nEnter Project ID:");
scanf("%d",&pro.pid);
printf("\n\n\nEnter Project Name:");
scanf("%s",pro.pname);
fwrite(&pro,st,1,fpro);
fclose(fpro);

//Function to list the file emp1.dat


void listEmp()
{
int i=0;
femp=fopen("d:\emp1.dat","a+");

fseek(femp,SEEK_SET,0);
printf("\nSNo.\tEmpID\tName\tProject\tSalary\tTA\tDA\tTotal");
printf("\n----------------------------------------------\n");

while(fread(&emp,rec,1,femp)==1)
{
++i;

printf("\n%d\t%d\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f",i,emp.empid,emp.ename
,emp.pid,emp.salary,emp.ta,emp.da,(emp.salary+emp.ta+emp.da));
}
fclose(femp);

getch();
}

//Function to list the file pro1.dat


void listPro()
{
int i=0;
fpro=fopen("d:\pro1.dat","a+");
rewind(fpro);
printf("\nSNo\tProID\tName\t");
printf("\n----------------------------------------------\n");

while(fread(&pro,st,1,fpro)!=NULL)
{ ++i;
printf("\n%d\t%d\t\t%s",i,pro.pid,pro.pname);
}

fclose(fpro);
getch();
}
//Function to search an employee in the file emp1.dat

int searchEmp()
{
int no,s=0;
clrscr();
femp=fopen("d:\emp1.dat","a+");
printf("\nEnter no to search:");
fflush(stdin);
scanf("%d",&no);
clrscr();
gotoxy(25,2);
textcolor(6);

printf("\nEmployee Management System");


printf("\n\n");
fseek(femp,SEEK_SET,0);

printf("\nEmpID\tName\tProject\tSalary\tTA\tDA\tTotal");
printf("\n---------------------------------------\n");

while(fread(&emp,rec,1,femp)!=NULL)
{

if(emp.empid==no)
{

printf("\n%d\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f",emp.empid,emp.ename,emp.pid,emp
.salary,emp.ta,emp.da,(emp.salary+emp.ta+emp.da));
s=no;
break;
}
}
if(s==0)
printf("\nNO DATA FOUND");
fclose(femp);

getch();
return(s);

}
//Function to search a project in the file pro1.dat

int searchPro()
{
int no,s=0;

fpro=fopen("d:\pro1.dat","a+");
clrscr();
printf("\nEnter no to search:");
fflush(stdin);
scanf("%d",&no);
clrscr();
gotoxy(25,2);
textcolor(6);

printf("\nProject Management System");


printf("\n\n");
fseek(fpro,SEEK_SET,0);
printf("\nPro ID\tName\t");
printf("\n---------------------------------------\n");

while(fread(&pro,st,1,fpro)!=NULL)
{
if(no==pro.pid)
{
printf("\n%d\t%s",pro.pid,pro.pname);
s=no;
break;
}
}
if(s==0)
printf("\nNO DATA FOUND");
fclose(fpro);
getch();
return(s);

//Function to delete an employee from the file emp1.dat


void delEmp()
{
int no;

printf("\n \n\n\nEnter the following to Delete: (Enter a


key)\n");
getch();
no=searchEmp();
printf("The record U want to delete is id = %d \n",no);
femp=fopen("d:\emp1.dat","w");
fseek(femp,SEEK_SET,0);
while(fread(&emp,rec,1,femp)!=NULL)
{
if(emp.empid!=no)
fwrite(&emp,rec,1,femp);

}
fclose(femp);
}

//Function to delete a project from the file pro1.dat


void delPro()
{

int no;

printf("\n \n\n\nEnter the following to Delete: (Enter a


key)\n");
getch();
no=searchPro();
printf("The record U want to delete is id = %d \n",no);
fpro=fopen("d:\pro1.dat","w");

fseek(fpro,SEEK_SET,0);
while(fread(&emp,rec,1,fpro)!=NULL)
{
if(emp.empid!=no)
fwrite(&emp,rec,1,fpro);

}
fclose(fpro);
}