Tuesday, February 18, 2014

How To Create Address Book Software in C++




#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<iomanip.h>

class abook
{
char hno[10];//house no
char sno[10];//streate No
char add[120];// Address
char name[30];//Name Of Person
char city[30];//City name
char state[30];//State And Provivence
char phone[15];//Phone Number
public:
void getdata();
void putdata();
};
void abook::getdata()
{
cout<<"Enter the name of person=\n";
cin.getline(name,30);
cout<<"Enter the house number=\n";
cin.getline(hno,10);
cout<<"Enter the len or streate no=\n";;
cin.getline(sno,10);
cout<<"Enter the local address=\n";
cin.getline(add,120);
cout<<"Enter the city name=\n";
cin.getline(city,30);
cout<<"Enter the state\providence=\n";
cin.getline(state,30);
cout<<"enter the phone number=\n";
cin.getline(phone,15);

}
void abook::putdata()
{
/*cout.write(name,30);
cout.write(hno,10);
cout.write(sno,10);
cout.write(add,120);
cout.write(city,30);
cout.write(state,30);
cout.write(phone,15);  */

cout<<"name person="<<name<<"\n";
cout<<"hno="<<hno<<"\n";
cout<<"streat\len  no="<<sno<<"\n";
cout<<"address="<<add<<"\n";
cout<<"city name="<<city<<"\n";
cout<<"state="<<state<<"\n";
cout<<"phone="<<phone<<"\n";
cout<<"====================================\n";
}
void main()
{
abook m;
fstream f;
f.open("abook.text",ios::ate|ios::in|ios::out|ios::binary);
f.seekg(0,ios::beg);
cout<<"Current content of stock"<<"\n";
while(f.read((char*)&m,sizeof(m)));
{
m.putdata();
}
f.clear();
cout<<"\n ADD AN ITEM\n";
m.getdata();
char ch;
cin.get(ch);
f.write((char*)&m,sizeof(m));
f.seekg(0);
cout<<"CONTENT OF APPEND FILE\n";
while(f.read((char*)&m,sizeof(m)));
{
m.putdata();
}
int last=f.tellg();
int n=last/sizeof(m);
cout<<"Number of object="<<n<<"\n";
cout<<"Total byte in the file"<<last<<"\n";
cout<<"Enter the object number to be updated \n";
int object;
cin>>object;
cin.get(ch);
int location=(object-1)*sizeof(m);
if(f.eof())

f.clear();
f.seekp(location);
cout<<"Enter the values of the object\n";
m.getdata();
cin.get(ch);
f.write((char*)&m,sizeof(m));
f.seekg(0);
cout<<"content of updated\n";
while(f.read((char*)&m,sizeof(m)))
{
m.putdata();
}
f.close();
getch();
}