Professional Documents
Culture Documents
developed by : ------------
name : Kavita Bisht
Class : XII - A :
Sesssion : 2015-16
roll No : 15
-------------
*/
// HEADER FILES
# include<iostream>
# include<conio.h>
#include<string.h>
#include<fstream>
# include<stdio.h>
using namespace std;
// CLASS DECLARATION
void line()
{
int i;
for(i=0;i<80;i++)
cout<<"-";
}
class addressbook
{
private :
int sno;
char name[20];
char address[80];
char state[20];
char phoneno[30];
char city[20];
char rno[10];
char rn[20];
public:
char choice[20];
void main_menu(); // function to display main menu
void add_record(); // function to add record in a data file
void delete_record(); // function to delete record from data file
void modify_record(); // function to modify a record in a data file
void search_menu() ; // function to display search menu
void search_sno();
void search_name();
void search_address();
void search_phoneno();
void search_city();
void search_state();
} b;
// function to display main menu of record----------
case 2:
delete_record();
break;
case 3:
modify_record();
break;
case 4:
search_menu();
break;
case 5:
report_menu();
break;
case 6: break;
default :
cout<<"\n Wrong Choice...... Try Again ";
}while(choice!=6);
return;
}
}
void addressbook::display()
{
return;
}
// Function to add new record
void addressbook::add_record()
{
ofstream fout;
fout.open("address.book",ios::app|ios::binary);
input_data();
fout.write((char *)this, sizeof(addressbook));
fout.close();
return;
}
void addressbook::delete_record()
{
ifstream fin;
ofstream fout;
int tsno;
int flag =0;
system("cls");
cout<<"\n Enter serial no to delete :";
cin>>tsno;
fin.open("address.book",ios::binary);
fout.open("temp.dat");
while(fin.read((char*)this, sizeof(addressbook)))
{
if(tsno!=sno)
fout.write((char*)this,sizeof(addressbook));
else
flag=1;
}
fin.close();
fout.close();
if(flag==1)
cout<<"\n\n Record Sucessfully removed ";
else
cout<<"\n Serial no. :"<<tsno <<" does not exist...Try again";
getch();
return;
}
void addressbook::modify_record()
{
ifstream fin;
ofstream fout;
int tsno;
int front =0;
system("cls");
cout<<"\n Enter sno. to Modify :";
cin>>tsno;
fin.open("address.book",ios::binary);
fout.open("temp.dat");
while(fin.read((char*)this, sizeof(addressbook)))
{
if(tsno == sno)
{ input_data(); front=1; }
fout.write((char*)this,sizeof(addressbook));
}
fin.close();
fout.close();
if(front==1)
cout<<"\n\n Record Sucessfully modified ";
else
cout<<"\n Serial no. :"<<tsno <<" does not exist...Try again";
getch();
return;
void addressbook::search_menu()
{
int search;
do{
system("cls");
cout<<"\n\n\t\t\t search menu ";
cout<<"\n \n\t\t\t 1.s.no.";
cout<<"\n \n\t\t\t 2.Name";
cout<<"\n\n\t\t\t 3.Phone no.";
cout<<"\n\n\t\t\t 4. Address";
cout<<"\n\n\t\t\t 5. City";
cout<<"\n\n\t\t\t 6. State";
cout<<"\n\n\t\t\t 7. Exit";
cout<<"\n\n\t\t\t enter your choice (1...7):";
cin>>search;
switch(search)
{
case 1:
search_sno();
getch();
break;
case 2:
search_name();
getch();
break;
case 3:
search_address();
getch();
break;
case 4:
search_phoneno();
getch();
break;
case 5:
search_state();
break;
case 6:
search_city();
getch();
break;
case 7:
break;
default :
cout<<"\n wrong search..... try again!!";
}while(search!=7);
return;
}
/*--------------function to search record serial no. wise ------*/
void addressbook::search_sno()
{
ifstream fin;
fin.open("address.book");
int tsno;
int found=0;
system("cls");
cout<<"\n Enter serial number to search : ";
cin>>tsno;
while(fin.read((char*)this,sizeof(addressbook)))
{
if(tsno == sno)
{
system("cls");
cout<<"\n Information of a person ";
cout<<"\n--------------------------------------------------------"<<endl;
display();
found = 1;
}
}
fin.close();
if(found==0)
cout<<"\n\n Serial no. : "<<tsno <<" does not exist in our address book.... Try again";
return;
}
/*--------------function to search record accoring to name ------*/
void addressbook::search_name()
{
ifstream fin;
fin.open("address.book");
char tname[20];
int fit=0;
system("cls");
cout<<"\n Enter Name to search :";
cin>>tname;
while(fin.read((char*)this,sizeof(addressbook)))
{
if(strcmpi(tname,name)==0)
{
system("cls");
cout<<"\n Information of person ";
cout<<"\n--------------------------------------------------------"<<endl;
display();
fit=1;
}
}
fin.close();
if(fit==0)
cout<<"\n No such name : "<<strupr(tname)<<" exist in our address book... Try again";
return;
}
/*--------------function to search record acording to address ------*/
void addressbook::search_address()
{
ifstream fin;
fin.open("address.book");
char tadd[80];
int flag=0;
system("cls");
cout<<"\n Enter Address to search :";
cin>>tadd;
while(fin.read((char*)this,sizeof(addressbook)))
{
if(strcmpi(tadd,address)==0)
{
system("cls");
cout<<"\n Information of a person ";
cout<<"\n--------------------------------------------------------"<<endl;
display();
flag=1;
}
}
fin.close();
if(flag==0)
cout<<"\n No such address : "<<strupr(tadd)<<" exist in our address book... Try again";
return;
}
/*---function to search student record according to phone no.-----*/
void addressbook::search_phoneno()
{
ifstream fin;
fin.open("address.book");
char ph[20];
int flag=0;
system("cls");
cout<<"\n Enter Phone no. to search :";
cin>>ph;
while(fin.read((char*)this,sizeof(addressbook)))
{
if(strcmpi(ph,phoneno)==0)
{
system("cls");
cout<<"\n Information of a person ";
cout<<"\n--------------------------------------------------------"<<endl;
display();
flag=1;
}
}
fin.close();
if(flag==0)
cout<<"\n No such phone no. : "<<strupr(ph)<<" exist in our address book... Try again";
return;
}
/*--------function to search record according to state ------*/
void addressbook::search_state ()
{
ifstream fin;
fin.open("address.book");
char st[30];
int flag=0;
system("cls");
cout<<"\n Enter name of state to search :";
cin>>st;
while(fin.read((char*)this,sizeof(addressbook)))
{
if(strcmpi(st,state)==0)
{
system("cls");
cout<<"\n Information of a person";
cout<<"\n--------------------------------------------------------"<<endl;
display();
flag=1;
}
}
fin.close();
if(flag==0)
cout<<"\n No such name of state : "<<strupr(st)<<" exist in our address book... Try again";
return;
}
/*---------function to search record according city ------*/
void addressbook::search_city()
{
ifstream fin;
fin.open("address.book");
char ct[20];
int flag=0;
system("cls");
cout<<"\n Enter Phone no. to search :";
cin>>ct;
while(fin.read((char*)this,sizeof(addressbook)))
{
if(strcmpi(ct,city)==0)
{
system("cls");
cout<<"\n Information of a person";
cout<<"\n--------------------------------------------------------"<<endl;
display();
flag=1;
}
}
fin.close();
if(flag==0)
cout<<"\n No such name of city : "<<strupr(ct)<<" exist in our address book... Try again";
return;
}
case 3:
search_menu();
break;
case 4:
report_menu();
break;
case 5:
report_name();
break;
case 6: break;
default :
cout<<"\n Wrong choice ... Try again";
}
} while(choice!=5);
return ;
}
// function to read data from text file and display them on the screen
void addressbook::report_complete()
{
int record = record_count(); // function call to find out total available record
int pages;
if(record<=20)
pages = 1;
else
pages = record/20 + 1 ;
int row= 6;
int cur_page=1;
ifstream fin ;
fin.open("address.book",ios::binary);
system("cls");
cout<<"\n\t\t\t\t\t COMPLETE REPORT \n";
line();
cout<<"\n sno. \t\t\tName \t\t\taddress \t\t\t phoneno. \t\t\t state \t\t\t city \t\t\t ";
line();
cout<<"\n";
while(fin.read((char *)this, sizeof(addressbook)))
{
cout<<sno<<"\t\t"<<name<<"\t\t"<<phoneno<<"\t\t"<< state<<"\t\t"<<city<<"\n";
row++;
if( row>=20)
{
cur_page++;
cout<<"\n\n Press any key to continue.....";
getch();
row =6;
line();
cout<<"\n Page "<< cur_page << " of "<< pages;
line();
}
}
getch();
fin.close();
return ;
}
void addressbook::report_name()
{
char tname[20];
system("cls");
while(fin.read((char*)this, sizeof(addressbook)))
{
if(tname==name )
{
row= row+1;
no++;
if(row>=20)
{
cout<<"\n\n Press any key to continue ................";
getch();
cout<<"\n\t\t ADDRESS BOOK";
cout<<"\n\t\t name :"<<tname<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"sno.\tName\taddress\tphone no. \t state\t city\n";
cout<<"-------------------------------------------------------------------------------"<<endl;
row =6;
}
cout<<sno<<"\t"<<name<<"\t"<<address<<"\t"<<phoneno<<"\t"<<state<<"\t"<<city<<endl;
}
}
fin.close();
cout<<"-------------------------------------------------------------------------------"<<endl;
getch();
return ;
void addressbook::report_address()
{
char tadd[80];
system("cls");
cout<<"\n Enter address :";
cin>>tadd;
system("cls");
cout<<"\n\t\t ADDRESS BOOK ";
cout<<"\n\t\t address "<<tadd<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"sno\tName\taddress\t phone no. \t state\t city\n";
cout<<"-------------------------------------------------------------------------------"<<endl;
while(fin.read((char*)this, sizeof(addressbook)))
{
if(tadd==address )
{
row= row+1;
no++;
if(row>=20)
{
cout<<"\n\n Press any key to continue ................";
getch();
cout<<"\n\t\t ADDRESS BOOK";
cout<<"\n\t\t address :"<<tadd<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"sno.\tName\taddress\tphone no. \t state\t city\n";
cout<<"-------------------------------------------------------------------------------"<<endl;
row =6;
}
cout<<sno<<"\t"<<name<<"\t"<<address<<"\t"<<phoneno<<"\t"<<state<<"\t"<<city<<endl;
}
}
fin.close();
cout<<"-------------------------------------------------------------------------------"<<endl;
getch();
return ;
int addressbook::record_count()
{
int n=0;
ifstream fin;
fin.open("address.book",ios::binary);
return 0;
}