//####################################################################
// PERSONAL TELEPHONE DIRECTORY MANAGMENT SYSTEM
//####################################################################


#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<ctype.h>


enum boolean
{
false,
true
};

void box ( int x1, int y1, int x2, int y2);

void screen(void);

void heading ()
{
gotoxy(18,5); cout << "PERSONAL TELEPHONE DIRECTORY MANAGEMENT SYSTEM "<<endl;
}


class MENU
{
public:
void MAIN_MENU(void);
private:
int st1 ,st2;
};

class directory
{
public:
unsigned long tel_no;
char address[36],sex,name[26];
int age,dd,mm,yy;
public:
void getdata();
void showdata();
unsigned long get_number();
};


//--------------------------------------------------------------------
// FUNCTION TO GET SUBSCRIBER'S DATA
//--------------------------------------------------------------------

void directory::getdata(void)
{
char mname[26],maddress[36],msex,ch,t1[5],t3[10];
int d1,m1,y1,valid,t2,mage;unsigned long t4,mphone;
textcolor(LIGHTGRAY);
textbackground(BLACK);
box(10,3,70,7);
heading();
box(20,8,60,14);
box(5,22,75,24);

gotoxy(25,9); cout<< "Name : ";
gotoxy(25,10); cout<<"Address : ";
gotoxy(25,11); cout<<"Phone : ";
gotoxy(25,12); cout<<"Age : ";
gotoxy(25,13); cout<<"Sex : ";

do
{
valid = 1;
gotoxy(25,23);
cout<<"Enter the name of the Subscriber";
gotoxy(40,9);
gets(mname);
strupr(mname);
if (mname[0] == '0')
return;
if(strlen(mname) < 1|| strlen(mname)>25)
{
valid = 0;gotoxy(25,23);clreol();
cout<<"Enter correctly (Range: 1..25) ";getch();
}
}
while(!valid);

do
{
valid = 1;gotoxy(25,23);clreol();
cout<<"Enter address of the Subscriber ";
gotoxy(40,10);
gets(maddress);strupr(maddress);
if(maddress[0] == '0')
return;
if(strlen(maddress)<1 || strlen(maddress)>35)
{
valid = 0;gotoxy(25,23);clreol();
cout<<"Enter correctly (Range: 1..35) ";getch();
}
}
while(!valid);

do
{
valid = 1;
gotoxy(25,23);clreol();
cout<<"Enter phone no.of the Subscriber";
gotoxy(40,11); cin>>t3;
t4 = atol(t3);
mphone = t4;
if(t3[0] == '0')
return;
if(mphone<1||mphone>99999999)
{
valid = 0;
gotoxy(25,23);
clreol();
cout<<"Enter correctly ";
getch();
}
}
while(!valid);
do
{
valid = 1;
gotoxy(25,23);
cout<<"Enter age of the Subscriber ";
gotoxy(40,12);
gets(t1);
t2 = atoi(t1);
mage = t2;
if(t1[0] == '0')
return;
if(mage<1||mage>100)
{
valid = 0;
gotoxy(25,23);
cout<<"Enter correctly ";
getch();
}
}
while(!valid);
do
{
gotoxy(25,23);
cout<<"Enter sex of the Subscriber(M/F)";
gotoxy(40,13);
msex = getche();
msex = toupper(msex);
}
while(msex != 'M' && msex != 'F');
do
{
gotoxy(28,15);
cout<<"Do you want to save(y/n)";
ch = getche();
ch = toupper(ch);
}
while (ch != 'Y' && ch != 'N');
if(ch == 'N')
return;
strcpy(name,mname);
strcpy(address,maddress);
tel_no = mphone;
age = mage;
sex = msex;
dd = d1;
mm = m1;
yy = y1;
}

void directory::showdata(void)
{
clrscr();
box(5,16,75,21);
gotoxy(10,17);
textbackground(WHITE);textcolor(BLACK);
cprintf("THE Present record in the file is");
gotoxy(10,18);
cout<<"Name :"<<name<<"\n";
gotoxy(45,18);
cout<<"Address :"<<address<<"\n";
gotoxy(10,19);
cout<<"Phone No :"<<tel_no;
gotoxy(45,19);
cout<<"Sex :"<<sex;
gotoxy(10,20);
cout<<"Age :"<<age;
};

unsigned long directory::get_number()
{
return tel_no;
}


class file_operation
{
public:
directory obj;
void add();
void edit();
void delet();
void report();
};


//------------------------------------------------------------------
// FUNCTION TO ADD RECORDS
//------------------------------------------------------------------

void file_operation::add()
{
ofstream file;
file.open("Telephone.dat",ios::app);
if(!file)
{
cout<<"Cannot open this file"<<"\n";
}
obj.getdata();
file.write((char*)this,sizeof(file_operation));
file.close();
}


//--------------------------------------------------------------------
// FUNCTION TO DELETE RECORDS
//--------------------------------------------------------------------

void file_operation::delet()
{
char reply;unsigned long tno,rtno;
clrscr();
box(10,3,70,7);
heading();
box(15,10,65,15); gotoxy(25,13);cout<<"Enter telephone no to delete:";cin>>tno;
fstream file;
file.open("Telephone.dat",ios::in);
fstream temp;
temp.open("temp.dat",ios::out);
file.seekg(0,ios::beg);
while(!file.eof())
{
file.read((char*)this,sizeof(file_operation));
if(file.eof())
break;
if(tno!=obj.get_number())
temp.write((char*)this,sizeof(file_operation));
}
file.close();
temp.close();
file.open("Telephone.dat",ios::out);
temp.open("temp.dat",ios::in);
temp.seekg(0,ios::beg);
while(!temp.eof())
{
temp.read((char*)this,sizeof(file_operation));
if(temp.eof())
break;
file.write((char*)this,sizeof(file_operation));
}
file.close();
temp.close();
}


//--------------------------------------------------------------------
// FUNCTION TO EDIT RECORDS
//--------------------------------------------------------------------

void file_operation::edit()
{
char reply;
unsigned long t_no,rtno;
cout<<"Enter telephone no to edit:";cin>>t_no;
int recno,i=0;
fstream file;
file.open("Telephone.dat",ios::in);
while (file.read((char*)this,sizeof(file_operation)))
{
i++;
if(t_no == obj.get_number())
{
obj.showdata();
break;
}
}
file.close();
recno = i;
file.open("Telephone.dat",ios::out|ios::ate);
obj.getdata();
int location;
location = (recno-1)*sizeof(file_operation);
file.seekp(location);
file.write((char*)this,sizeof(file_operation));
file.close();
}


//--------------------------------------------------------------------
// FUNCTION TO DISPLAY LIST OF SUBSCRIBER'S
//--------------------------------------------------------------------

void file_operation::report()
{
clrscr();
int row=5,found = 0,flag=0;
char ch;
textcolor(BLACK+BLINK);
textbackground(WHITE);
gotoxy(28,1);
cprintf("List of Subscriber");
textcolor(BLACK);gotoxy(1,3);clreol();
gotoxy(1,3);
cout<<"NAME ADDRESS PHONE_NO";
textcolor(LIGHTGRAY);textbackground(BLACK);
fstream file;
file.open("Telephone.dat",ios::in);
file.seekg(0,ios::beg);
while(file.read((char*)this,sizeof(file_operation)))
{
flag=0;delay(20);found=1;gotoxy(1,row);
cout<<obj.name; gotoxy(20,row);
cout<<obj.address; gotoxy(41,row);
cout<<obj.tel_no;
if(row==23)
{
flag=1;
row=5;
gotoxy(1,28);
cout<<"Press any key to continue or<ESC>to exit";
ch=getche();
if(ch==27)
{ break;
}
clrscr();
textcolor(BLACK); textbackground(WHITE);
gotoxy(28,1);
cprintf("LIST OF SUBSCRIBERS");
textcolor(BLACK); gotoxy(1,3);clreol();
gotoxy(1,3);
cout<<"NAME ADDRESS PHONE_NO";
textcolor(LIGHTGRAY);
textbackground(BLACK);
}
else
row++;
}
if(!found)
{
gotoxy(5,10);
cout<<"\Records not found";
}
if(!flag)
{
gotoxy(1,25);
cout<<"Press any key to continue";
getche();
}
file.close();
}
file_operation mainobj;


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// FUNCTION TO DISPLAY MAIN MENU
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void MENU::MAIN_MENU(void)
{
boolean flag=true;
textbackground(1);
textcolor(15);
int ch=0;
do
{
clrscr();
box(10,2,72,6);
heading();
gotoxy(33,7); cout<< "MAIN MODULE";
box ( 24,8,54,15);
box ( 24,6,54,18);
gotoxy(25,10);cprintf(" 1 : ADD SUBSC ");
gotoxy(25,11);cprintf(" 2 : EDIT SUBSC ");
gotoxy(25,12);cprintf(" 3 : DELE SUBSC ");
gotoxy(25,13);cprintf(" 4 : SUBSCRIB LIST ");
gotoxy(25,14);cprintf(" 0 : QUIT ");
gotoxy(25,17);cprintf(" ENTER CHOICE :-->>");
gotoxy(45,17); cin>>ch;
if(ch == 1)
{
clrscr();
mainobj.add();
}
else
if(ch == 2)
{
clrscr();
mainobj.edit();
}
else
if(ch == 3)
{
clrscr();
mainobj.delet();
}
else
if(ch == 4)
{
clrscr();
mainobj.report();
}
else
if(ch == 0)
{
break;
}
}
while (flag);
};


//--------------------------------------------------------------------
// FUNCTION TO FORM A BOX
//--------------------------------------------------------------------

void box ( int x1, int y1, int x2, int y2)
{
int i;
textbackground(1);
textcolor(15);
gotoxy(x1,y1); cout<<char(218);
gotoxy(x2,y2); cout<<char(217);
gotoxy(x2,y1); cout<<char(191);
gotoxy(x1,y2); cout<<char(192);
for ( i= x1+1; i<= x2-1; i++)
{
gotoxy( i, y1);cout<<char(196);
gotoxy(i,y2); cout<<char(196);
}

for ( i= y1+1; i<= y2-1; i++)
{
gotoxy(x1, i);cout<<char(179);
gotoxy(x2,i); cout<<char(179)
;
}
}


//--------------------------------------------------------------------
// FUNCTION TO MAKE THE SCREEN
//--------------------------------------------------------------------

void screen(void)
{
clrscr();
box(4,3,76,23);
delay(80);
box(7,5,73,21);
delay(80);
box(10,7,70,19);
delay(80);
box(14,7,66,19);
delay(80);
box(18,7,62,19);
delay(80);
box(22,9,58,17);
delay(80);
gotoxy(32,10); cout<<"COMPUTER PROJECT ";
delay(80);
gotoxy(38,12); cout<<"ON";
delay(80);
gotoxy(25,13); cout<< " PERSONAL TELEPHONE DIRECTORY ";
delay(80);
gotoxy(30,16); cout<< " BY ---->>> GAURAV & HARSH ";
gotoxy(21,25); cout<< "<<<<-- press any key to continue......-->>>>";
getch();
}


void main(void)
{ clrscr();
char ch[100];
char i,j;
gotoxy(24,18);
i=18;
textcolor(i+1);
cprintf("PRESENTS PROJECT'2000...");
gotoxy(24,19);
textcolor(i+5);
cprintf("copy rights reserved'2000");
gotoxy(24,20);
textcolor(i+8);
cprintf("press enter to continue");
getch();
clrscr();
gotoxy(30,12);
cprintf("loading ");
j=3;
textcolor(j);
for(i=0;i<8;i++)
{
cprintf(".");
delay(600);

}
struct intro
{
char pro[20];
char pronam[20];
char dir[20];
char dirnam[20];
char gra[20];
char graname[20];
};
intro a={ "DIRECTOR", "Nitin " , "PRODUCER", "Nitin ","GRAPHICS EDITOR", "Nitin "};
i=30;
for(j=12;j>10;j--)
{
gotoxy(i,j);
cout<<a.pro;
gotoxy(i,j+2);
cout<<a.pronam;
delay(1000);

clrscr();
gotoxy(i,j+4);
cout<<a.dir;

gotoxy(i,j+6);
cout<<a.dirnam;
delay(1000);
clrscr();
gotoxy(i,j+8);
cout<<a.gra;

gotoxy(i,j+10);
cout<<a.graname;
delay(1000);
clrscr();

}
textbackground(1);
textcolor(15);
MENU menu;
screen();
menu.MAIN_MENU();
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// END OF THE PROJECT
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

< Back