Search

Pages

Telephone Directory



Telephone Directory

Telephone Directory Project in C++. Download this project form above link, it's completely free.
 
Telephone Directory

Telephone Directory

Telephone Directory

Telephone Directory

Telephone Directory




Source Code


/********** Login id --- hitesh  *********/
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <graphics.h>
# define PATH "c:\\tc\\bgi"
long int lilogin=1000;
void fnmenu();
void fndeptmenu();
void fndeptmain();
void fnempmain();
void fnteldirmain();
void fntelenquiry();
void fnadddept();
void fnviewdept();
void fnmoddept();
void fndeldept();
void fnaddemp();
void fnviewemp();
void fnmodemp();
void fndelemp();
void fnempmenu();
void fndirmenu();
void fnaddtel();
void fnenqmenu();
void fnenqbyname();
void fnenqbynum();
void fnlogin();
/**************************************************************************
* Structure : department
* Description : This structure helps us to assign department code
and dept name.
* Member variable
* icode : specifies dept code.
* acname : specifies dept name.

**************************************************************************/

struct department
{
long int icode;
char acname[15];
};
/**************************************************************************
* Structure : employee
* Description : This structure helps us to assign employee code
emploee name,location and to assign dept to a
particular emp.
* Member variable
* iecode : specifies emp code.
* acename : specifies emp name.
* aceloc : specifies emp location.
* sddept : specifies the variable of str. department
**************************************************************************/

struct employee
{
long int iecode;
char acename[25];
char aceloc[5];
struct department sddept;
};

/**************************************************************************
* Structure : tel
* Description : This structure helps us to assign telephone number
to every employee.
* Member variable
* itel : specifies telephone number.
* seemp1 : specifies the variable of str employee.

**************************************************************************/

struct tel
{
long int itel;
struct employee seemp1;
};
/*************************************************************************
* Function : main
* Description : The program execution starts from here.
The login screen is displayed here and when the
userID matches, the main menu screen comes.
* Input parameters
No parameters have been used.

***************************************************************************/

void main()
{
char coption='0';
fnlogin();
clrscr();
while(coption!='5')
{
fnmenu();
coption=getch();
switch(coption)
{
case '1':{fndeptmain();
break;}
case '2':{fnempmain();
break;}
case '3':{fnteldirmain();
break;}
case '4':{fntelenquiry();
break;
}
case '5': exit(1);

default:{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(20,15);
printf("wrong option....press any key to return ");
printf("\a");
getch();
}
}
}
getch();
}
/*************************************************************************
* Function : fnmenu
* Description : Here the user have to choose among given choice
based on the kind of work he wants to do.
* Input parameters
No parameters have been used.

***************************************************************************/

void fnmenu()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);
cleardevice();
gotoxy(20,3);
printf("TELEPHONE DIRECTORY MAINTENANCE SYSTEM");
gotoxy(19,4);
printf("_________________________________________");
gotoxy(35,8);
printf("MAIN MENU");
gotoxy(25,11);
printf("1.DEPARTMENT CODE MAINTENANCE");
gotoxy(25,14);
printf("2.EMPLOYEE MASTER MAINTENANCE");
gotoxy(25,17);
printf("3.TELEPHONE DIRECTORY MAINTENANCE");
gotoxy(25,20);
printf("4.TELEPHONE ENQUIRY");
gotoxy(25,23);
printf("5.EXIT");
gotoxy(20,26);
printf("ENTER YOUR OPTION:");
gotoxy(38,27);
printf("........");
gotoxy(38,26);
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
}
/*************************************************************************
* Function : fndeptmain
* Description : It gives the facility to user to add, view,
delete, modify and goto the main menu.
* Input parameters
No parameters have been used.

***************************************************************************/

void fndeptmain()
{
char coption='0';
clrscr();
while(coption!='5')
{
fndeptmenu();
coption=getch();
switch(coption)
{
case '2': {cleardevice();
fnviewdept();
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

getch();
break;
}



case '1':{if(lilogin==1000)
fnadddept();
else
{
cleardevice();
gotoxy(30,15);
printf("access denied" );
getch();
}
break; }
case '3':{if(lilogin==1000)
fnmoddept();
else
{
cleardevice();
gotoxy(30,15);
printf("access denied" );
getch();
}
break;}
case '4': {if(lilogin==1000)
fndeldept();
else
{
cleardevice();
gotoxy(30,15);
printf("access denied" );
getch();
}
break;}
case '5':return;

default: {
cleardevice();
gotoxy(20,15);
printf("wrong option....press any key to return ");
printf("\a");
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
getch();
}
}
}
getch();
}

/*************************************************************************
* Function : fndeptmenu
* Description : It prints menu of department
* Input parameters
No parameters have been used.

***************************************************************************/

void fndeptmenu()
{

cleardevice();
gotoxy(20,3);
printf("TELEPHONE DIRECTORY MAINTENANCE SYSTEM");
gotoxy(19,4);
printf("_________________________________________");
gotoxy(25,8);

printf("DEPARTMENT CODE MAINTENANCE");
gotoxy(25,12);
printf("1.ADD NEW DEPARTMENT");
gotoxy(25,15);
printf("2.VIEW DEPARTMENT DETAIL");
gotoxy(25,18);

printf("3.MODIFY DEPARTMENT DETAIL");
gotoxy(25,21);
printf("4.DELETE DEPARTMENT");
gotoxy(25,24);
printf("5.GOTO MAIN MENU");


gotoxy(20,27);
printf("ENTER YOUR OPTION:");
gotoxy(38,28);
printf("........");
gotoxy(38,27);
setbkcolor(GREEN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
}
/*************************************************************************
* Function : fnempmain
* Description : It gives the facility to user to add, view,modify
delete and goto main menu.
* Input parameters
No parameters have been used.

***************************************************************************/



void fnempmain()
{char coption='0';
cleardevice();
while(coption!='5')
{
fnempmenu();
coption=getch();
switch(coption)
{
case '1':{ if(lilogin==1000)
fnaddemp();
else
{
cleardevice();
gotoxy(30,15);
printf("access denied" );
getch();
}
break;}
case '2':{cleardevice();
fnviewemp();
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

getch();
break;}
case '3':{if(lilogin==1000)
fnmodemp();
else
{
cleardevice();
gotoxy(30,15);
printf("access denied" );
getch();
}
break;}
case '4':{if(lilogin==1000)
fndelemp();
else
{
cleardevice();
gotoxy(30,15);
printf("access denied" );
getch();
}
break;}

case '5':{return;
}
default:{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(20,15);
printf("wrong option....press any key to return ");
printf("\a");
getch();
}
}
}
getch();
}
/*************************************************************************
* Function : fnempmenu
* Description : It prints menu of employee
* Input parameters
No parameters have been used.

***************************************************************************/

void fnempmenu()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);



cleardevice();
gotoxy(20,3);
printf("TELEPHONE DIRECTORY MAINTENANCE SYSTEM");
gotoxy(21,4);
printf("_________________________________________");
gotoxy(25,8);

printf("EMPLOYEE MASTER MAINTENANCE");
gotoxy(25,11);
printf("1.ADD NEW EMPLOYEE");
gotoxy(25,14);
printf("2.VIEW EMPLOYEE DETAIL");
gotoxy(25,17);
printf("3.MODIFY EMPLOYEE DETAIL");
gotoxy(25,20);
printf("4.DELETE EMPLOYEE");
gotoxy(25,23);
printf("5.GOTO MAIN MENU");
gotoxy(20,26);
printf("ENTER YOUR OPTION:");
gotoxy(38,27);
printf("........");
gotoxy(38,26);
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,600,470);
setlinestyle(1,3,2);
rectangle(15,15,595,465);
}
/*************************************************************************
* Function : fnteldirmain
* Description : It gives the facility to the user to add and
goto the main menu.
* Input parameters
No parameters have been used.

***************************************************************************/



void fnteldirmain()
{
char coption='0';
cleardevice();
while(coption!='2')
{
fndirmenu();
coption=getch();
switch(coption)
{
case '1':{if(lilogin==1000)
fnaddtel();
else
{
cleardevice();
gotoxy(30,15);
printf("access denied" );
getch();
}
break;}
case '2':{return;
}
default:{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

gotoxy(20,15);
printf("wrong option....press any key to return ");
printf("\a");
getch();
}
}
}
getch();
}
/*************************************************************************
* Function : fndirmenu
* Description : It prints menu of directory
* Input parameters
No parameters have been used.

***************************************************************************/

void fndirmenu()
{
cleardevice();
gotoxy(20,3);
printf("TELEPHONE DIRECTORY MAINTENANCE SYSTEM");
gotoxy(21,4);
printf("_________________________________________");
gotoxy(25,8);

printf("TELEPHONE DIRECTORY MAINTENANCE");
gotoxy(25,15);
printf("1.ADD NEW NUMBER");
gotoxy(25,19);

printf("2.GOTO MAIN MENU");
gotoxy(25,23);
printf("ENTER YOUR OPTION:");
gotoxy(43,24);
printf("........");
gotoxy(43,23);
setbkcolor(BROWN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
}

/*************************************************************************
* Function : fntelenquiry
* Description : It gives the facility to the user to enquiry
on telephone number and on employee name.
* Input parameters
No parameters have been used.

***************************************************************************/


void fntelenquiry()
{
char coption='0';
cleardevice();
while(coption!='3')
{
fnenqmenu();
coption=getch();
switch(coption)
{
case '1':{fnenqbyname();
break;}
case '2':{fnenqbynum();
break;}
case '3':{return;
}
default:{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

gotoxy(20,15);
printf("wrong option....press any key to return ");
printf("\a");
getch();
}
}
}
getch();
}
/*************************************************************************
* Function : fnenqmenu
* Description : It prints menu of enquiry
* Input parameters
No parameters have been used.

***************************************************************************/

void fnenqmenu()
{
cleardevice();
gotoxy(20,3);
printf("TELEPHONE DIRECTORY MAINTENANCE SYSTEM");
gotoxy(19,4);
printf("_________________________________________");
gotoxy(29,8);

printf("TELEPHONE ENQUIRY");
gotoxy(29,14);
printf("1.ENQUIRY BY NAME");
gotoxy(29,18);
printf("2.ENQUIRY BY NUMBER");
gotoxy(29,22);
printf("3.GOTO MAIN MENU");
gotoxy(29,26);

printf("ENTER YOUR OPTION:");
gotoxy(47,27);
printf("........");
gotoxy(47,26);
setbkcolor(MAGENTA);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
}
/*************************************************************************
* Function : fnadddept
* Description : Departments are created with department code starting
with 1000 and department name is entered that is unique.
* Input parameters: No parameters have been used.

***************************************************************************/


void fnadddept()
{
FILE*fp=fopen("dept.txt","ab");
struct department sddept,temp;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);
setbkcolor(MAGENTA);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

fclose(fp);
fp=fopen("dept.txt","rb+");

sddept.icode=1000;

while(fread(&sddept,sizeof(sddept),1,fp)==1)
{}
cleardevice();
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
sddept.icode+=1;
gotoxy(25,10);
printf("DEPARTMENT CODE: %ld",sddept.icode);
gotoxy(43,11);
printf("______");
gotoxy(25,14);
printf("DEPARTMENT NAME:" );
gotoxy(43,15);
printf(".......");
gotoxy(43,14);

fflush(stdin);
scanf("%s",sddept.acname);
if(strlen(sddept.acname)>15)
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(10,15);
printf("NAME SHOULD BE LESS THAN 15 CHARACTER.....PRESS ANY KEY TO RETURN");
printf("\a");
getch();

return;
}
rewind(fp);
while(fread(&temp,sizeof(temp),1,fp)==1)
{
if(strcmpi(sddept.acname,temp.acname)==0)
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

gotoxy(20,15);
printf("NAME EXIST.....PRESS ANY KEY TO RETURN");
printf("\a");
getch();
return;
}
}
fwrite(&sddept,sizeof(sddept),1,fp);
fclose(fp);
}
/*************************************************************************
* Function : fnviewdept
* Description : Departments details are viewed in tabular format
* Input parameters: No parameters have been used.

***************************************************************************/

void fnviewdept()
{
FILE *fp1=fopen("dept.txt","rb");
struct department sddept;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);
/*setbkcolor(GREEN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,595,465);
*/
rewind(fp1);
//gotoxy(20,15);
printf("\n\n\tDEPARTMENTCODE\tDEPARTMENTNAME\n");

while(fread(&sddept,sizeof(sddept),1,fp1)==1)
{
printf("\t%ld \t%s\n",sddept.icode,sddept.acname);

}
fclose(fp1);
}
/*************************************************************************
* Function : fnaddemp
* Description : Employees are created with employe code starting
with 1000 and employee name and employee loca
tion must be in their limits.
* Input parameters: No parameters have been used.

***************************************************************************/



void fnaddemp()
{
FILE*fp=fopen("emp.txt","ab");
FILE*fp1=fopen("dept.txt","rb");
struct employee seemp,temp;
struct department temp1;
int icount=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

fclose(fp);
fp=fopen("emp.txt","rb+");
seemp.iecode=1000;
while(fread(&seemp,sizeof(seemp),1,fp)==1)
{}
cleardevice();
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,600,470);
setlinestyle(1,3,2);
rectangle(15,15,595,465);

seemp.iecode+=1;
gotoxy(10,10);
printf("EMPLOYEE CODE: %ld",seemp.iecode);
gotoxy(25,11);
printf("______");
gotoxy(10,13);
printf("EMPLOYEE NAME:" );
gotoxy(25,14);
printf("............");
fflush(stdin);
gotoxy(25,13);
scanf("%s",seemp.acename);
gotoxy(10,16);
printf("EMPLOYEE LOCATION:" );
gotoxy(29,17);
printf("..........");
fflush(stdin);
gotoxy(29,16);
gets(seemp.aceloc);
if(strcmpi(seemp.aceloc,"\0")==0)
strcpy(seemp.aceloc,"del");
gotoxy(10,17);
fnviewdept();
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,600,470);
setlinestyle(1,3,2);
rectangle(15,15,595,465);
gotoxy(28,21);
printf("EMPLOYEE DEPTCODE:" );

gotoxy(47,22);
printf(".......");
gotoxy(47,21);

fflush(stdin);
scanf("%ld",&seemp.sddept.icode);
rewind(fp1);
while(fread(&temp1,sizeof(temp1),1,fp1)==1)
{
if(seemp.sddept.icode==temp1.icode)
{
icount++;
strcpy(seemp.sddept.acname,temp1.acname);
fclose(fp1);
break;
}
}
if(icount==0)
{
cleardevice();
gotoxy(20,25);
printf("WRONG ID");
getch();
return;
}

gotoxy(28,27);
printf("EMPLOYEE DEPTNAME:" );

gotoxy(47,28);
printf("_________");
gotoxy(47,27);
printf("%s",seemp.sddept.acname);

if(strlen(seemp.aceloc)>5)
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

gotoxy(10,20);
printf("LOCATION SHOULD BE LESS THAN 5 CHARACTER.....PRESS ANY KEY TO RETURN");
printf("\a");
getch();
return;

}

if(strlen(seemp.acename)>25)
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

gotoxy(10,20);
printf("NAME SHOULD BE LESS THAN 25 CHARACTER.....PRESS ANY KEY TO RETURN");
printf("\a");
getch();
return;
}
rewind(fp);
while(fread(&temp,sizeof(temp),1,fp)==1)
{
}
fwrite(&seemp,sizeof(seemp),1,fp);
fclose(fp);
getch();
}
/*************************************************************************
* Function : fnviewemp
* Description : employee details are viewed in tabular format
* Input parameters: No parameters have been used.

***************************************************************************/


void fnviewemp()
{
FILE *fp1=fopen("emp.txt","rb");
int icount;

struct employee seemp;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

rewind(fp1);
gotoxy(9,5);
printf("CODE EMPLOYEENAME LOCATION DEPTCODE DEPTNAME \n");

while(fread(&seemp,sizeof(seemp),1,fp1)==1)
{
printf("\t%ld %s\t\t%s\t %ld\t %s\n",seemp.iecode,seemp.acename,seemp.aceloc,seemp.sddept.icode,seemp.sddept.acname);

}
fclose(fp1);
}
/*************************************************************************
* Function : fnaddtel
* Description : for valid empcode, telephone no is generated.
* Input parameters: No parameters have been used.

***************************************************************************/

void fnaddtel()
{
FILE*fp=fopen("dir.txt","ab");
FILE*fp1=fopen("emp.txt","rb");
struct tel sttel,temp;
struct employee seemp;
long int icount;
int icount1=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

fclose(fp);
fp=fopen("dir.txt","rb+");
cleardevice();
setbkcolor(GREEN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

sttel.itel=1;
printf("\n\n\n\tENTER THE EMPLOYEE ID:\t");
scanf("%ld",&icount);
printf(" \t.......");


while(fread(&seemp,sizeof(seemp),1,fp1)==1)
{
if(seemp.iecode==icount)
{ sttel.seemp1=seemp;
fclose(fp1);
icount1++;
break;
}
}

if(icount1==0)
{
gotoxy(15,15);
printf("WRONG ID.......PRESS ANY KEY TO CONTINUE");
fclose(fp);
getch();
return;
}
while(fread(&temp,sizeof(temp),1,fp)==1)
{
if(temp.seemp1.sddept.icode== sttel.seemp1.sddept.icode)
sttel.itel+=1;
}
sttel.itel+= sttel.seemp1.sddept.icode*1000;

printf("\n\n\tTELEPHONE NO:\t%ld\n",sttel.itel);
fwrite(&sttel,sizeof(sttel),1,fp);
fclose(fp);
getch();

}
/*************************************************************************
* Function : fnenqbyname
* Description : for valid empname, all details of that employee
is printed.
* Input parameters: No parameters have been used.

***************************************************************************/

void fnenqbyname()
{
FILE*fp=fopen("dir.txt","rb");
char acnam[25];
int icount=0;
struct tel temp,sttel;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

cleardevice();
setbkcolor(GREEN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(25,10);
printf("ENTER THE NAME:");
scanf("%s",acnam);
while(fread(&temp,sizeof(temp),1,fp)==1)
{
if(strcmpi(temp.seemp1.acename,acnam )==0)
{
sttel=temp;
icount++;
break;

}
}
if(icount==0)
{
gotoxy(15,20);
printf("WRONG NAME.......PRESS ANY KEY TO CONTINUE");
fclose(fp);
getch();
return;
}
cleardevice();
setbkcolor(MAGENTA);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(15,10);
printf("CODE:%ld",sttel.seemp1.iecode);
gotoxy(15,11);
printf("NAME:%s",sttel.seemp1.acename);
gotoxy(15,12);
printf("LOCATION:%s",sttel.seemp1.aceloc);
gotoxy(15,13);
printf("DEPTCODE:%ld",sttel.seemp1.sddept.icode);

gotoxy(15,14);
printf("DEPTNAME:%s",sttel.seemp1.sddept.acname);
gotoxy(15,15);
printf("TELEPHONENO:%ld",sttel.itel);
getch();
}
/*************************************************************************
* Function : fnenqbynum
* Description : for valid telephone number, all details of
owner employee is printed.
* Input parameters: No parameters have been used.

***************************************************************************/

void fnenqbynum()
{
FILE*fp=fopen("dir.txt","rb");
long int litelno;

int icount=0;
struct tel temp,sttel;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

cleardevice();
setbkcolor(BROWN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(25,10);
printf("ENTER THE NUMBER:");
scanf("%ld",&litelno);

while(fread(&temp,sizeof(temp),1,fp)==1)
{
if(temp.itel==litelno)
{
sttel=temp;
icount++;
break;
}
}
if(icount==0)
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,600,470);
setlinestyle(1,3,2);
rectangle(15,15,595,465);

gotoxy(15,20);
printf("WRONG NUMBER.......PRESS ANY KEY TO CONTINUE");
printf("\a");
fclose(fp);
getch();
return;
}
cleardevice();
setbkcolor(GREEN);
setlinestyle(3,2,1);
rectangle(10,10,600,470);
setlinestyle(1,3,2);
rectangle(15,15,595,465);
gotoxy(15,10);
printf("CODE:%ld",sttel.seemp1.iecode);
gotoxy(15,11);
printf("NAME:%s",sttel.seemp1.acename);
gotoxy(15,12);
printf("LOCATION:%s",sttel.seemp1.aceloc);
gotoxy(15,13);
printf("DEPTCODE:%ld",sttel.seemp1.sddept.icode);

gotoxy(15,14);
printf("DEPTNAME:%s",sttel.seemp1.sddept.acname);
gotoxy(15,15);
printf("TELEPHONENO:%ld",sttel.itel);

getch();



}
/*************************************************************************
* Function : fnmoddept
* Description : for valid deptcode,modification is done with checking
deptname limit
* Input parameters: No parameters have been used.

***************************************************************************/

void fnmoddept()
{
FILE*fp=fopen("dept.txt","rb");
long int licode;
int icount=0,icounter=0;
struct department dep;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

cleardevice();
setbkcolor(BLUE);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

printf("\n\n\t DEPTCODE:");
scanf("%ld",&licode);
while(fread(&dep,sizeof(dep),1,fp)==1)
{
if(dep.icode==licode)
{icounter++;
break;}
icount++;
}
fclose(fp);
fp=fopen("dept.txt","rb+");
if(icounter==0)
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(20,15);
printf(" WRONG DEPARTMENT CODE");
getch();
return;
}
while(1)
{
printf("\tENTER NEW DEPTNAME:");
scanf("%s",dep.acname);
if(strlen(dep.acname)>15)
{
cleardevice();
setbkcolor(RED);


setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

printf("NAME SHOULD BE LESS THAN 15 CHARACTERS");
printf("\a");
getch();
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,600,470);
setlinestyle(1,3,2);
rectangle(15,15,595,465);

}
else
break;
}


fseek(fp,icount*sizeof(dep),SEEK_CUR);
fwrite(&dep,sizeof(dep),1,fp);
fclose(fp);

}
/*********************************************************************
* Function : fndeldept
* Description : for valid deptcode,deletion is done in dept records
* Input parameters: No parameters have been used.

***************************************************************************/

void fndeldept(){
struct department sddep;
FILE*fp=fopen("dept.txt","rb");
FILE*fp1=fopen("dep.txt","wb");
long int icode,icount=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

cleardevice();
setbkcolor(BLUE);

setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

printf("\n\n\t DEPTCODE:");
scanf("%ld",&icode);
while(fread(&sddep,sizeof(sddep),1,fp)==1)
{
if(sddep.icode!=icode)
fwrite(&sddep,sizeof(sddep),1,fp1);
else
icount++;
}
if(icount==0)
{cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(20,15);
printf(" WRONG DEPARTMENT ID" );
getch();
}

fclose(fp1);
fclose(fp);
remove("dept.txt");
rename("dep.txt","dept.txt");
}
/*********************************************************************
* Function : fnmodemp
* Description : for valid empcode,modification is done with checking
empname,emploc limit
* Input parameters: No parameters have been used.

***************************************************************************/



void fnmodemp()
{
FILE*fp=fopen("emp.txt","rb");
FILE*fp1=fopen("dept.txt","rb");

long int ldcode;
int icount=0,icounter=0,icount1=0;
struct employee seemp;
struct department temp1;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

cleardevice();
setbkcolor(BROWN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(10,5);
printf(" EMPCODE:");
scanf("%ld",&ldcode);
while(fread(&seemp,sizeof(seemp),1,fp)==1)
{
if(seemp.iecode==ldcode)
{icounter++;
break;
}
icount++;
}
fclose(fp);
fp=fopen("emp.txt","rb+");
if(icounter==0)
{
cleardevice();
setbkcolor(RED);

setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(20,15);
printf(" WRONG EMPLOYEE CODE");
printf("\a");
getch();
return;
}
while(1)
{
printf("\tENTER NEW EMPLOYEENAME:");
scanf("%s",seemp.acename);
if(strlen(seemp.acename)>25)
{
cleardevice();
setbkcolor(RED);

setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

printf("NAME SHOULD BE LESS THAN 25 CHARACTERS");
printf("\a");
getch();
cleardevice();
}
else
break;
}

while(1)
{
printf("\tENTER NEW LOCATION:");
scanf("%s",seemp.aceloc);

if(strcmpi(seemp.aceloc,"\0")==0)
strcpy(seemp.aceloc,"del");
if(strlen(seemp.aceloc)>5)
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(10,15);
printf("LOCATION SHOULD BE LESS THAN 5 CHARACTERS");
printf("\a");
getch();
cleardevice();
setbkcolor(BROWN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
}
else
break;
}
fnviewdept();
setbkcolor(BROWN);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);

printf("\tENTER NEW DEPTCODE:");
fflush(stdin);
scanf("%ld",&seemp.sddept.icode);

while(fread(&temp1,sizeof(temp1),1,fp1)==1)
{
if(seemp.sddept.icode==temp1.icode)
{
icount1++;
strcpy(seemp.sddept.acname,temp1.acname);
}
}
if(icount1==0)
{
cleardevice();
gotoxy(30,15);
printf("WRONG ID");
getch();
return;
}

printf("\n\tEMPLOYEE DEPTNAME:%s",seemp.sddept.acname );
fclose(fp1);

getch ();
cleardevice();
fseek(fp,icount*sizeof(seemp),SEEK_CUR);
fwrite(&seemp,sizeof(seemp),1,fp);
fclose(fp);

}
/*********************************************************************
* Function : fndelemp
* Description : for valid empcode,deletion is done in employee
records
* Input parameters: No parameters have been used.

***************************************************************************/

void fndelemp(){
struct employee sedep;
FILE*fp=fopen("emp.txt","rb");
FILE*fp1=fopen("dep.txt","wb");
long int licode;
int icount=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

cleardevice();
setbkcolor(MAGENTA);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(10,8);

printf(" EMPCODE:");
scanf("%ld",&licode);
while(fread(&sedep,sizeof(sedep),1,fp)==1)
{
if(sedep.iecode!=licode)
fwrite(&sedep,sizeof(sedep),1,fp1);
else
icount++;
}
if(icount==0)
{cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(25,15);
printf("WRONG EMPLOYEE ID" );
getch();
}
fclose(fp1);
fclose(fp);
remove("emp.txt");
rename("dep.txt","emp.txt");
}
/*********************************************************************
* Function : fnlogin
Description : take login id and check it with empcodes
available in employee records and if present
it continue to main menu otherwise exit
printing error message.

* Input parameters: No parameters have been used.

***************************************************************************/
void fnlogin()
{

int icount=0;

struct employee sedep;

FILE*fp=fopen("emp.txt","rb");
char ch;
int gd=DETECT,gm;
initgraph(&gd,&gm,PATH);

cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(25,15);
printf("ENTER THE LOGINID:");
gotoxy(44,16);
printf(".......");
gotoxy(44,15);
scanf("%ld",&lilogin);
while(fread(&sedep,sizeof(sedep),1,fp)==1)
{
if(sedep.iecode==lilogin)
{icount++;
break;
}
}
if(icount==1||lilogin==1000)
return;
else
{
cleardevice();
setbkcolor(RED);
setlinestyle(3,2,1);
rectangle(10,10,620,470);
setlinestyle(1,3,2);
rectangle(15,15,615,465);
gotoxy(30,15);
printf("WRONG ID SYSTEM EXIT");
printf("\a");
getch();
exit(0);
}
}


For Documentation of this project drop a comment with your mail id, we provides full documentation soon........ as possible.


1 comment

 

Popular Posts