You are on page 1of 40

Shri Dharmasthala Manjunatheshwara a College of Engineering & Technology,

Dharwad 580002.
(An Autonomous Institution Affiliated to VTU, Belgaum)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

A Project Report on

TELEPHONE DIRECTORY MANAGEMENT SYSTEM

Under the guidance of Mr. R G Yadwad Mr. Anand D Vaidya

A Project by, Sudeep M Sumeet Shah 2SD10CS102 2SD10CS105

Contents

Introduction Requirements Design Implementation Outputs Conclusion Appendix: source code

1. Introduction

In this era of telecom services there is a strong need of way to store contact details. In industries where many employees work at different locations telephone is the only way to contact, hence we need a way to easily store and search the contact details of the employee.
This project is aimed at storing telephone number and searching the telePhone number and employee details easily.

2. Requirements
Background
This document contains the high level design of the project that has to be executed in order to complete the course programming fundamentals. The project is a telephone directory maintenance system, for which portions have been implemented already.

Business requirements: The following are the requirements for this


project.
1 2 3

Department Code maintenance Employee Master maintenance Telephone Directory maintenance Telephone Enquiry

Completed completed Completed

Completed

Main menu:
You have to select any one of the section to continue Department Maintenance Employee Maintenance Telephone Directory Maintenance

1. Department Code Maintenance:


Here you are generating a code for the department name. Code should be 4 digit ,it must starts from 1000 and every department should have unique code. Display all the departments along with the department codes in a tabular format.

2. Employee Maintenance:
Here you are adding a new employee and viewing the information of employee. Employee name should not exceed 25 characters. Employee ID should be generated by the system, it should starts with 1000 and every employee has unique ID. Display all the employees along with their department codes ,employee ID and other details in a tabular formate. 3. Telephone Enquiry Maintenance: It contains, Add new telephone Enquiry on employee name Enquiry on Telephone number

Add new telephone: For a given employee ID, system should generates telephone number as, 4 digit of telephone number contains department code of respective employee ID and rest 3 digits starts from 000 to 111. Enquiry on employee name: Case insensitive name search should be provided. If the name exists, the details of all the telephone numbers whose owner names match should be displayed. If name doesnt exists an error message should be displayed. Enquiry on employee number: Telephone number should be exists. If the telephone number does not exists ,an error message should be displayed. If the number exists , the details should be displayed.

3. Design

4. Implementation
Functions Used:
void login(); authenticates an user at login void main_menu(); provides an interface for the user after login, where he can choose the further options. void dept_main(); provides the interface for user to handle the department details. void emp_main(); provides the interface for user to handle the employee details. void tel_main(); provides the interface to generate a telephone number for the user. void add_emp(); adds an employee taking the name and generating his ID. void add_tel(); adds a telephone number of an employee. void print_emp(); prints the details of employee void add_dept(); adds the department to the department database void tel_enq(); searches for a telephone no./user name given user name/telephone no. void emp_enq(); telephone no. enquiry by name. void telno_enq(); user name search by telephone no. void print_dept(); prints department details. Void clrscr(); clears the screen.

5. Testing
Login for the first time.

Main menu, after login

Adding a new department.

Printing department details

Employee maintenance menu

Adding an employee.

Printing employee details

Telephone numbers maintenance

Adding a telephone number

Searching a telephone number

Enquiry by name

Enquiry by number

6. Conclusion Since
the program is working properly to meet the requirements, we can say that the task of creating an easy way to manage telephone numbers, employee details and department details is satisfactorily achieved with the help of file-handling capability of C language.

Appendix: source code.


//FileFunctions.h : file with all the required function definitions, structure declarations and preprocessor directives. . #include<stdio.h> #include<conio.h> #include<string.h> #include<ctype.h> #include<dos.h> #include<stdlib.h>

void login(); void main_menu(); void dept_main(); void emp_main(); void tel_main(); void add_emp(); void add_tel(); void print_emp(); void add_dept(); void tel_enq(); void emp_enq(); void telno_enq(); void print_dept(); void clrscr();

struct emp{ char ename[25]; int emp_id; char dname[7]; int dcode; char location[20]; long int pno; }; struct emp e;

struct dept{ char dname[7]; int dcode; }; struct dept d;

struct telext{ int ext; }; struct telext t; //end of FileFunctions.h //main.c file int main(){ //main_menu();

login(); return 0; } //end of main.c file //mainmenu.c void main_menu(){ int ch; clrscr(); printf("\n printf("\n printf("\n\n\n"); printf(" printf(" printf("\n\n printf("\n printf("\n printf("\n printf("\n printf("\n\n\n scanf("%d",&ch); switch(ch){ case 1: dept_main(); break; case 2: emp_main(); MAIN MENU\n"); =========\n"); 1. Department Maintenance"); 2. Employee Maintenance"); 3. Telephone Directory Maintenance"); 4. Telephone Enquiry Menu"); 5. Exit"); ENTER YOUR CHOICE :"); Telephone Directory And Maintenance System\n"); ==========================================\n");

break; case 3: tel_main(); break; case 4: tel_enq(); break; case 5: printf("\nYou have Choosen to get out of the program.\n\n\n"); //getch(); exit(0); break; default: printf("\nEntered Choice is Not Valid. Re-enter Your Choice.\n"); clrscr(); main_menu(); } } //end of mainmenu.c //FileFunctions.c file with all functions needed void login(){ fflush(stdin); int flag=0; int emp_id; long int size; FILE *fp, *check;

size=sizeof(e); int chkflag=100;

printf("\n printf("\n printf("\n\n\n"); printf(" printf(" printf("\n\n

Telephone Directory And Maintenance System\n"); ==========================================\n");

LOGIN SCREEN\n"); ============\n"); ENTER USER ID : ");

scanf("%d",&emp_id); /*chkflag=checkdigit(emp_id); if(chkflag==99){ login(); } check = fopen ( "EMPLOYEE.DAT", "a" ) ; if ( check == NULL ){ if(emp_id==123){ printf("\nLogged in as maintainence mode."); printf("\nAs no User Exist."); main_menu(); } }*/ fp = fopen ( "EMPLOYEE.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "EMPLOYEE.DAT", "wb+" ) ; if ( fp == NULL ){

puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fp); while(fread(&e,size,1,fp)==1){ if(e.emp_id==emp_id){ flag++; break; } } fclose(fp); if(flag==1) main_menu(); else{ if(emp_id==123){ printf("\n\nThis Id is valid IF NO uSer Exist."); printf("\nIn The Employee database"); getch(); clrscr(); main_menu(); } printf("\n\n Entered user id is not VALID."); getch(); clrscr(); login();

void add_emp(){ long int size,sized; int emp_id=999; int dcode; char dname[7],name[20]; FILE *fp, *fd; size=sizeof(e); sized=sizeof(d);

clrscr(); printf("\n printf("\n printf("\n\n\n"); printf("\n printf(" printf(" ADD AN EMPLOYEE\n"); =================\n\n\n\n"); Enter employee name :"); Telephone Directory And Maintenance System\n"); ==========================================\n");

scanf("%s",name); fp = fopen ( "EMPLOYEE.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "EMPLOYEE.DAT", "wb+" ) ; if ( fp == NULL ){

puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fp); while(fread(&e,size,1,fp)==1){ if(e.emp_id > emp_id) emp_id=e.emp_id; } emp_id++; fseek(fp,0,SEEK_END); e.emp_id=emp_id; printf("\n printf("\n Employee code : %d",emp_id); Department code : ");

scanf("%d",&dcode);

fd = fopen ( "DEPARTMENT.DAT", "rb+" ) ; if ( fd == NULL ){ fd = fopen ( "DEPARTMENT.DAT", "wb+" ) ; if ( fd == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fd); while(fread(&d,sized,1,fd)==1){

if(d.dcode == dcode){ //printf("\b%s\n",d.dname); strcpy(dname,d.dname); break; } } fclose(fd); printf("\n Department name :%s",dname);

strcpy(e.dname,dname); printf("\n Enter Location : ");

scanf("%s",e.location); strcpy(e.ename,name); e.pno=0; e.dcode=dcode; fwrite(&e,size,1,fp);

printf("\n\n\n getch(); fclose(fp); emp_main(); }

Press any Key To continue .. \n");

void print_emp(){ long int size; size=sizeof(e);

clrscr(); FILE *fp; printf("\n printf("\n printf("\n\n\n"); printf("\n printf(" EMPLOYEE DETAILS\n"); ==================\n\n\n\n"); Telephone Directory And Maintenance System\n"); ==========================================\n");

fp = fopen ( "EMPLOYEE.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "EMPLOYEE.DAT", "wb+" ) ; if ( fp == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fp); printf("__________________________________________________________________"); printf("\nNAME EMP.ID DEPARTMENT DEPT_ID LOCATION PHONE NO.\n");

printf("__________________________________________________________________"); while(fread(&e,size,1,fp)==1){ printf("\n%-12s%-10d%-12s%-11d%-12s%ld\n",e.ename,e.emp_id,e.dname,e.dcode,e.location,e.pno); } printf("\nPress any Key To continue .. \n"); getch(); emp_main();

void add_dept(){ int d_id=999; long int size; char dname[7]; size=sizeof(d); FILE *fp; clrscr(); printf("\n printf("\n printf("\n\n\n"); printf("\n printf(" printf(" ADD A DEPARTMENT\n"); =================\n\n\n\n"); Enter Department name :"); Telephone Directory And Maintenance System\n"); ==========================================\n");

scanf("%s",dname);

fp = fopen ( "DEPARTMENT.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "DEPARTMENT.DAT", "wb+" ) ; if ( fp == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fp);

while(fread(&d,size,1,fp)==1){ if(strcmpi(d.dname,dname)==0){ printf("\nEnter Department Name already exist."); getch(); dept_main(); } } rewind(fp); while(fread(&d,size,1,fp)==1){ if(d.dcode > d_id) d_id=d.dcode; }

d_id++; fseek(fp,0,SEEK_END); strcpy(d.dname,strupr(dname)); d.dcode=d_id; printf("\n Department code : %d",d.dcode);

fwrite(&d,size,1,fp); printf("\n\n\n getch(); fclose(fp); dept_main(); } Press any Key To continue .. \n");

void add_tel(){

long int size, sizet; size=sizeof(e); sizet=sizeof(t); char location[15]; int dcode,tlast=0; long int tno; int emp_id; FILE *fp, *ft; clrscr();

printf("\n printf("\n printf("\n\n\n"); printf("\n printf(" printf("

Telephone Directory And Maintenance System\n"); ==========================================\n");

ADD A Telephone number\n"); ======================\n\n\n\n"); Enter Employee id :");

scanf("%d",&emp_id);

fp = fopen ( "EMPLOYEE.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "EMPLOYEE.DAT", "wb+" ) ; if ( fp == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } }

rewind(fp); while(fread(&e,size,1,fp)==1){ if(e.pno > 999999){ printf("\nThis Employee Already has Alloted \nA telephone Number"); getch(); tel_main(); break; } } rewind(fp); while(fread(&e,size,1,fp)==1){ if(e.emp_id == emp_id){ strcpy(location,e.location); dcode=e.dcode; break; } }

ft = fopen ( "TEL.DAT", "rb+" ) ; if ( ft == NULL ){ ft = fopen ( "TEL.DAT", "wb+" ) ; if ( ft == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } }

rewind(ft); while(fread(&t,sizet,1,ft)==1){ if(t.ext > tlast){ tlast=t.ext; } } tlast++; //t.ext=tlast; //printf("\n\n%d\n\n",dcode); tno=dcode*1000+tlast; t.ext=tno; fseek(ft,0,SEEK_END); fwrite(&t,sizet,1,ft); fclose(ft); printf("\n printf("\n printf("\n e.pno=tno; fseek(fp,-size,SEEK_CUR); fwrite(&e,size,1,fp); printf("\n\n\n getch(); fclose(fp); tel_main(); Press any Key To continue .. \n"); Location : %s",location); Department Code :%d",dcode); Telephone number Allocated : %ld",tno);

void tel_enq(){ int ch; clrscr();

printf("\n printf("\n printf("\n\n\n");

Telephone Directory And Maintenance System\n"); ==========================================\n");

//printf("\nEmployee Maintenance Menu\n"); //printf("=========================\n\n\n\n"); printf("\n printf("\n Telephone Enquiry Menu"); ======================");

printf("\n\n\n printf("\n printf("\n printf("\n\n\n scanf("%d",&ch); switch(ch){ case 1: emp_enq(); break; case 2: telno_enq(); break;

1. Enquiry On Employee Name"); 2. Enquiry On Telephone Number"); 3. Main Menu"); ENTER YOUR CHOICE :");

case 3: main_menu(); break; default: printf("\nEntered Choice is Not Valid. Re-enter Your Choice.\n"); getch(); tel_enq(); }

void emp_enq(){ char name[15]; long int size; size=sizeof(e); FILE *fp; clrscr();

printf("\n printf("\n printf("\n\n\n"); printf("\n printf("

Telephone Directory And Maintenance System\n"); ==========================================\n");

Enquirey By Name\n"); ================\n\n\n\n");

printf("

Enter Employee Name :");

scanf("%s",name);

fp = fopen ( "EMPLOYEE.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "EMPLOYEE.DAT", "wb+" ) ; if ( fp == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fp); printf("__________________________________________________________________"); printf("\nNAME EMP.ID DEPARTMENT DEPT_ID LOCATION PHONE NO.\n");

printf("__________________________________________________________________"); while(fread(&e,size,1,fp)==1){ if(strcmpi(e.ename,name)==0){ printf("\n%-12s%-10d%-12s%-11d%-12s%ld\n",e.ename,e.emp_id,e.dname,e.dcode,e.location,e.pno); }

} printf("\nPress any Key To continue .. \n"); getch(); fclose(fp); tel_enq(); }

void telno_enq(){ //char name[15];

long int telno; long int size; size=sizeof(e); FILE *fp; clrscr(); printf("\n printf("\n printf("\n\n\n"); printf("\n printf(" Enquirey By Number\n"); ================\n\n\n\n"); Telephone Directory And Maintenance System\n"); ==========================================\n");

printf("

Enter Telephone number :");

scanf("%ld",&telno); fp = fopen ( "EMPLOYEE.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "EMPLOYEE.DAT", "wb+" ) ; if ( fp == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fp); printf("__________________________________________________________________"); printf("\nNAME EMP.ID DEPARTMENT DEPT_ID LOCATION PHONE NO.\n");

printf("__________________________________________________________________"); while(fread(&e,size,1,fp)==1){

if(telno==e.pno){ printf("\n%-12s%-10d%-12s%-11d%-12s%ld\n",e.ename,e.emp_id,e.dname,e.dcode,e.location,e.pno); }

} printf("\nPress any Key To continue .. \n"); getch(); fclose(fp); tel_enq(); }

void print_dept(){ long int size; size=sizeof(d); FILE *fp; clrscr();

printf("\n printf("\n printf("\n\n\n"); printf("\n printf("

Telephone Directory And Maintenance System\n"); ==========================================\n");

List Of Department With Their Dept Code\n"); =========================================\n\n\n\n");

fp = fopen ( "DEPARTMENT.DAT", "rb+" ) ; if ( fp == NULL ){ fp = fopen ( "DEPARTMENT.DAT", "wb+" ) ;

if ( fp == NULL ){ puts ( "Cannot open file" ) ; exit(0) ; } } rewind(fp); printf("_________________________________________"); printf("\nDEPARTMENT NAME DEPArtMENT CODE\n");

printf("_________________________________________"); while(fread(&d,size,1,fp)==1){ printf("\n%-22s%-14d",d.dname,d.dcode); } printf("\nPRESS ANY KeY tO CONtiNUe .."); getch(); fclose(fp); dept_main();

void clrscr(){ int i; for(i=0; i<35; i++){ printf("\n"); } } //end of FileFunctions.c

//deptmaint.c manages the department void dept_main(){ int ch; clrscr(); printf("\n printf("\n printf("\n\n\n"); printf("\n printf(" printf("\n\n\n\n printf("\n printf("\n printf("\n\n\n scanf("%d",&ch); switch(ch){ case 1: add_dept(); break; case 2: print_dept(); break; case 3: main_menu(); break; default: Department Maintenance Menu\n"); ===========================\n"); 1. Add Department"); 2. Print Department Detail"); 3. Goto Main Menu"); ENTER YOUR CHOICE :"); Telephone Directory And Maintenance System\n"); ==========================================\n");

printf("\nEntered Choice is Not Valid. Re-enter Your Choice.\n"); getch(); dept_main(); } } //end of deptmaint.c //empmaint.c void emp_main(){ int ch; clrscr(); printf("\n printf("\n printf("\n\n\n"); printf("\n printf(" printf("\n printf("\n printf("\n printf("\n\n\n scanf("%d",&ch); switch(ch){ case 1: add_emp(); break; case 2: print_emp(); Employee Maintenance Menu\n"); =========================\n\n\n\n"); 1. Add Employee\n"); 2. Print Employee Detail\n"); 3. Goto Main Menu\n"); ENTER YOUR CHOICE :"); Telephone Directory And Maintenance System\n"); ==========================================\n");

break; case 3: main_menu(); break; default: printf("\nEntered Choice is Not Valid. Re-enter Your Choice.\n"); clrscr(); emp_main(); } } //end of empmaint.c //telemaint.c void tel_main(){ int ch; clrscr(); printf("\n printf("\n printf("\n\n\n"); printf("\n printf("\n printf("\n\n scanf("%d",&ch); switch(ch){ case 1: add_tel(); break; 1. Add Telephone Number\n"); 2. Goto Main Menu\n"); ENTER YOUR CHOICE :"); Telephone Directory And Maintenance System\n"); ==========================================\n");

case 2: main_menu(); break; default: printf("\nEntered Choice is Not Valid. Re-enter Your Choice.\n"); clrscr(); tel_main(); }

} //end telemaint.c

Sudeep M

You might also like