Code PDF
Code PDF
#include<fstream>
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
class telephone
{
private:
char name[30];
char fname[30];
char address[100];
char phone[15];
char city[20];
char state[30];
char b_address[100];
char b_phone[15];
char email[50];
public:
void read_data()
{
cout<<"\n Name :";
cin.ignore();
gets(name);
cout<<"\n Father name :";
gets(fname);
cout<<"\n Address :";
gets(address);
cout<<"\n Phone No :";
gets(phone);
cout<<"\n city :";
gets(city);
cout<<"\n State :";
gets(state);
cout<<"\n Business address :";
gets(b_address);
cout<<"\n Business phone no . :";
gets(b_phone);
cout<<"\n Email :";
gets(email);
}
void display_record()
{
system("cls");
cout<<"\n\t\t\t\t Subscriber Details";
cout<<"\n\t\t---------------------------------------------------------------";
cout<<"\n\n\t\tName : ";
cout<<name;
cout<<"\n\n\t\tFather name : ";
cout<<fname;
cout<<"\n\n\t\tAddress : ";
cout<<address;
cout<<"\n\n\t\tPhone No : ";
cout<<phone;
cout<<"\n\n\t\tcity : ";
cout<<city;
cout<<"\n\n\t\tState : ";
cout<<state;
cout<<"\n\n\t\tBusiness address : ";
cout<<b_address;
cout<<"\n\n\t\tBusiness phone no . : ";
cout<<b_phone;
cout<<"\n\n\t\tEmail : ";
cout<<email;
}
void disp_name_phone()
{
cout<<"\n"<<name<<"\t\t\t"<<phone<<"\t"<<address;
}
int count_pages()
{
int rec,pages;
rec=pages=0;
ifstream fin;
fin.open("telephone.dat",ios::binary);
while(fin.read((char*)this,sizeof(telephone)))
rec++;
fin.close();
pages= rec/20;
if((rec%20)!=0)
pages++;
return(pages);
}
void main_menu();
void search_menu();
void report_menu();
void add_member();
void delete_member();
void modify_member();
void search_name();
void search_phone();
void search_address();
void search_email();
void search_fname();
void report_list();
void report_name_phone();
void report_name_address();
void report_name_phone_address();
void report_name_email();
};
case 2: delete_member();
break;
case 3: modify_member();
break;
case 4: report_menu();
break;
case 5: search_menu();
break;
case 6: break;
}while(choice!=6);
return ;
}
case 2: report_name_phone();
break;
case 3: report_name_phone_address();
break;
case 4: report_name_email();
break;
case 5: break;
void telephone::add_member()
{
system("cls");
ofstream file;
file.open("telephone.dat",ios::app);
read_data();
file.write((char*)this ,sizeof(telephone));
file.close();
return;
}
void telephone::delete_member()
{
ofstream fout;
ifstream fin;
fin.open("telephone.dat",ios::binary);
fout.open("temp.dat",ios::binary);
system("cls");
char tphone[15];
int found=0;
cout<<"\n Enter Telephone no to delete :";
cin.ignore();
gets(tphone);
while(fin.read((char *)this,sizeof(telephone)))
{
if(strcmpi(this->phone,tphone)!=0)
fout.write((char*)this,sizeof(telephone));
else
found=1;
}
fin.close();
fout.close();
remove("telephone.dat");
rename("temp.dat","telephone.dat");
if(found==1)
cout<<"\n Record Sucessfully deleted ";
else
cout<<"\n Record not found";
getch();
}
void telephone::modify_member()
{
ofstream fout;
ifstream fin;
fin.open("telephone.dat",ios::binary);
fout.open("temp.dat",ios::binary);
char tphone[15];
int found=0;
system("cls");
cout<<"\n Enter Telephone no to modify :";
cin.ignore();
gets(tphone);
while(fin.read((char *)this,sizeof(telephone)))
{
if(strcmp(tphone,this->phone)==0)
{
read_data();
found=1;
}
fout.write((char*)this,sizeof(telephone));
}
fin.close();
fout.close();
remove("telephone.dat");
rename("temp.dat","telephone.dat");
if(found==1)
cout<<"\n Record Sucessfully modified";
else
cout<<"\n Record not found";
getch();
}
void telephone::search_address()
{
ifstream fin;
fin.open("telephone.dat",ios::binary);
char taddress[100];
int found ;
found =0;
system("cls");
cout<<"\n Search Screen";
cout<<"\n\n\t\t Address :";
cin.ignore();
cin>>taddress;
while(fin.read((char*)this, sizeof(telephone)))
{
if (strcmpi(taddress,this->address)==0)
{
display_record();
found =1;
}
}
fin.close();
if(found ==0)
cout<<"\n Record does not exist";
getch();
return;
}
void telephone::search_email()
{
ifstream fin;
fin.open("telephone.dat",ios::binary);
char temail[100];
int found ;
found =0;
system("cls");
cout<<"\n Search Screen";
cout<<"\n\n\t\t Email :";
cin.ignore();
gets(temail);
while(fin.read((char*)this, sizeof(telephone)))
{
if (strcmpi(temail,this->email)==0)
{
display_record();
found =1;
}
}
fin.close();
if(found ==0)
cout<<"\n Record does not exist";
getch();
return;
}
void telephone::search_fname()
{
ifstream fin;
fin.open("telephone.dat",ios::binary);
char tfname[100];
int found ;
found =0;
system("cls");
cout<<"\n Search Screen";
cout<<"\n\n\t\t Father Name :";
cin.ignore();
gets(tfname);
while(fin.read((char*)this, sizeof(telephone)))
{
if (strcmpi(tfname,this->fname)==0)
{
display_record();
found =1;
}
}
fin.close();
if(found ==0)
cout<<"\n Record does not exist";
getch();
return;
}
void telephone::search_name()
{
ifstream fin;
fin.open("telephone.dat",ios::binary);
char tname[100];
int found ;
found =0;
system("cls");
cout<<"\n Search Screen";
cout<<"\n\n\t\t Name :";
cin.ignore();
gets(tname);
while(fin.read((char*)this, sizeof(telephone)))
{
if (strcmpi(tname,this->name)==0)
{
display_record();
found =1;
}
}
fin.close();
if(found ==0)
cout<<"\n Record does not exist";
getch();
return;
}
void telephone::search_phone()
{
ifstream fin;
fin.open("telephone.dat",ios::binary);
char tphone[100];
int found ;
found =0;
system("cls");
cout<<"\n Search Screen";
cout<<"\n\n\t\t Phone No :";
cin.ignore();
gets(tphone);
while(fin.read((char*)this, sizeof(telephone)))
{
if (( strcmpi(tphone,this->phone)==0) || strcmpi(tphone,this->b_phone)==0)
{
display_record();
found =1;
}
}
fin.close();
if(found ==0)
cout<<"\n Record does not exist";
getch();
return;
}
void telephone::report_list()
{
int pages = count_pages();
int cur_page=1;
int n=0;
ifstream fin;
fin.open("telephone.dat",ios::binary);
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n-------------------------------------------------------------------------------------------------------------------";
cout<<"\n\n S.No"<<"\t\t Name \t\t\tAddress\t\t Phone\t\t\tEmail";
cout<<"\n-------------------------------------------------------------------------------------------------------------------";
while(fin.read((char*)this, sizeof(telephone)))
{
n++;
if(n%21==0)
{
cout<<"\n------------------------------------------------------------------------------------------------------------";
cout<<"\n\t\t\t\tPress any key to continue...........";
getch();
cur_page++;
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n------------------------------------------------------------------------------------------------------------";
cout<<"\n\n S.No"<<"\t\t Name \t\t\tAddress\t\t Phone\t\tEmail";
cout<<"\n------------------------------------------------------------------------------------------------------------";
}
cout<<"\n"<<n<<"\t |\t"<<this->name<<"\t |\t"<<this->address<<"\t |\t "<<this->phone<<"\t |
\t"<<this->email;
}
cout<<"\n-------------------------------------------------------------------------------------------------------------------";
cout<<"\n Total Records :"<<n;
fin.close();
getch();
return;
}
void telephone::report_name_phone_address()
{
int pages = count_pages();
int cur_page=1;
int n=0;
ifstream fin;
fin.open("telephone.dat",ios::binary);
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n-----------------------------------------------------------------------------";
cout<<"\n\n S.No"<<"\t\t Name \t\t\tAddress\t\t Phone\t\t";
cout<<"\n-----------------------------------------------------------------------------";
while(fin.read((char*)this, sizeof(telephone)))
{
n++;
if(n%21==0)
{
cout<<"\n----------------------------------------------------------------------";
cout<<"\n\t\t\t\tPress any key to continue...........";
getch();
cur_page++;
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n--------------------------------------------------------------------------";
cout<<"\n\n S.No"<<"\t\t Name \t\t\tAddress\t\t Phone\t\t";
cout<<"\n--------------------------------------------------------------------------";
}
cout<<"\n"<<n<<"\t |\t"<<this->name<<"\t |\t"<<this->address<<"\t |\t "<<this->phone<<"\t | \t";
}
cout<<"\n----------------------------------------------------------------------------";
cout<<"\n Total Records :"<<n;
fin.close();
getch();
return;
}
void telephone::report_name_address()
{
int pages = count_pages();
int cur_page=1;
int n=0;
ifstream fin;
fin.open("telephone.dat",ios::binary);
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n-----------------------------------------------------------------------------";
cout<<"\n\n S.No"<<"\t\t Name \t\t\t\t\t\t Address";
cout<<"\n-----------------------------------------------------------------------------";
while(fin.read((char*)this, sizeof(telephone)))
{
n++;
if(n%21==0)
{
cout<<"\n----------------------------------------------------------------------";
cout<<"\n\t\t\t\tPress any key to continue...........";
getch();
cur_page++;
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n--------------------------------------------------------------------------";
cout<<"\n S.No"<<"\t\t Name \t\t\t\t\t\t Address";
cout<<"\n--------------------------------------------------------------------------";
}
cout<<"\n"<<n<<"\t |\t"<<this->name<<"\t |\t\t\t\t\t"<<this->address;
}
cout<<"\n----------------------------------------------------------------------------";
cout<<"\n Total Records :"<<n;
fin.close();
getch();
return;
}
void telephone::report_name_email()
{
int pages = count_pages();
int cur_page=1;
int n=0;
ifstream fin;
fin.open("telephone.dat",ios::binary);
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n--------------------------------------------------------------------------------------------------";
cout<<"\n\n S.No"<<"\t\t Name \t\t\t\t\t Email";
cout<<"\n--------------------------------------------------------------------------------------------------";
while(fin.read((char*)this, sizeof(telephone)))
{
n++;
if(n%21==0)
{
cout<<"\n-------------------------------------------------------------------------------------------";
cout<<"\n\t\t\t\tPress any key to continue...........";
getch();
cur_page++;
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n-------------------------------------------------------------------------------------------";
cout<<"\n S.No"<<"\t\t Name \t\t\t\t Email";
cout<<"\n-------------------------------------------------------------------------------------------";
}
cout<<"\n"<<n<<"\t |\t"<<this->name<<"\t |\t\t\t"<<this->email;
}
cout<<"\n--------------------------------------------------------------------------------------------------";
cout<<"\n Total Records :"<<n;
fin.close();
getch();
return;
}
void telephone::report_name_phone()
{
int pages = count_pages();
int cur_page=1;
/* steps to show report menu and data */
int n=0;
ifstream fin;
fin.open("telephone.dat",ios::binary);
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n-----------------------------------------------------------------------------";
cout<<"\n\n S.No"<<"\t\t Name \t\t\t\t Phone";
cout<<"\n-----------------------------------------------------------------------------";
while(fin.read((char*)this, sizeof(telephone)))
{
n++;
if(n%21==0)
{
cout<<"\n----------------------------------------------------------------------";
cout<<"\n\t\t\t\tPress any key to continue...........";
getch();
cur_page++;
system("cls");
cout<<"\n\t\t\t\t Report "<<cur_page<< " of "<<pages;
cout<<"\n--------------------------------------------------------------------------";
cout<<"\n S.No"<<"\t\t Name \t\t\t Phone";
cout<<"\n--------------------------------------------------------------------------";
}
cout<<"\n"<<n<<"\t |\t"<<this->name<<"\t |\t\t"<<this->phone;
}
cout<<"\n------------------------------------------------------------------------------";
cout<<"\n Total Records :"<<n;
fin.close();
getch();
return;
}
int main()
{
telephone t;
cout<<"\n\n\n\n\n\t\t\t VAISNO TRAVEL
AGENCY"<<"\n\t\t\t===========================";
cout<<"\n\n\t\t\tMADE BY:- VAIBHAV GOEL"<<"\n\n\t\t\tAIR FORCE SCHOOL HINDAN, GZB";
getch();
system("cls");
t.main_menu();
return 0;
}