U
Unpopular
void directory::modification()//???????????
{
clrscr();
cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @
@@@@@@ ";
cout<< "\n\t=====@ @ @ @ @ @ @@ @
@ =====";
cout<< "\n\t=====@@@@@@ @ @ @ @ @ @ @ @ @
@@@ =====";
cout<< "\n\t=====@ @ @ @ @ @ @ @@
@ @ =====";
cout<< "\n\t @@@@@@ @@@@@ @@@@@ @ @@@@@ @ @
@@@@@@ \n\n\n\n";
cout<<"I am inside the modification function before opening of
addressesFiile.";
getch();
long pn;
int n,i;
ifstream inFile;
ofstream outFile;
inFile.open("addressesFile");
if(!inFile)
{
cout<<"\nI am inside the modification function after opening
of addressesFiile. Checking now with if";
getch();
cout<<"\n File not found!";
outFile.close();
exit(-1);
}
outFile.open("new");
cout<<"\nI am inside the modification function after just creating
new";
getch();
n=test();
if(n==0)
{
cout<<"\nI am inside the modification function. new is
empty";
getch();
cout<<"\n The file is empty. ! ";
getch();
return;
}
cout<<"\nI am inside the modification function before entering the
while loop.";
getch();
int deleteMe = 0;
while(inFile.good())
{
inFile.read((char*)&obj,sizeof(obj));
outFile.write((char*)&obj,sizeof(obj));
cout<<"\nI am inside the modification function inside the while
loop and I have finished round "<<deleteMe+1;
deleteMe = deleteMe + 1;
getch();
}
cout<<"\nI am inside the modification function just outside
the while loop.";
inFile.close();
outFile.close();
outFile.open("addressesFile",ios::trunc);
inFile.open("new");
if(inFile.fail())
{
cout<<"\n Sorry! File not found !";
exit(-1);
}
char ch;
cout<<"\n Enter the Land Line Phone Number or the Contact :";
cin>>pn;
ch=cin.get();
cin.get(ch);
for(i=0;i<n;i++)
{
inFile.read((char*)&obj,sizeof(obj));
char d;
if(pn==landLinePhone)
{
//view1();
cout<<" Name : "<<obj.contactName<<"\n";
cout<<" Home Address : "<<obj.homeAddress<<"\n";
cout<<" EMAIL ADDRESS : "<<obj.email<<"\n";
cout<<" Cellular Phone Nmber : "<<obj.cellularPhone<<"\n";
cout<<" Land Line Phone Number : "<<obj.landLinePhone<<"\n
\n";
d=check("HOUSE PHONE NUMBER ");
if((d=='y') || (d=='Y'))
{
cout<<"\n Enter the new land line phone number of the
contact, please. :";
cin>>landLinePhone;
ch=cin.get();
cin.get(ch);
}
if(check("OFFICE PHONE NUMBER ")=='Y')
{
cout<<"\n Enter the new cellular phone number of the
contact, please. :";
cin>>cellularPhone;
ch=cin.get();
cin.get(ch);
}
if(check("Name of the Contact")=='y')
{
cout<<"\n Enter the name of the contact, please. : ";
cin.getline(contactName,20,'\n');
}
if(check("HOME ADDRESS")=='y')
{
cout<<"\n Enter the new Home Address of the contact,
please. :";
cin.getline(homeAddress,50,'\n');
}
if(check("EMAIL ADDRESS:")=='y')
{
cout<<"\n Enter the new E-mail Address of the contact,
please. :";
cin.getline(email,25,'\n');
}
}//the outer if ends here.
outFile.write((char*)&obj,sizeof(obj));
}
outFile.close();
inFile.close();
}
{
clrscr();
cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @
@@@@@@ ";
cout<< "\n\t=====@ @ @ @ @ @ @@ @
@ =====";
cout<< "\n\t=====@@@@@@ @ @ @ @ @ @ @ @ @
@@@ =====";
cout<< "\n\t=====@ @ @ @ @ @ @ @@
@ @ =====";
cout<< "\n\t @@@@@@ @@@@@ @@@@@ @ @@@@@ @ @
@@@@@@ \n\n\n\n";
cout<<"I am inside the modification function before opening of
addressesFiile.";
getch();
long pn;
int n,i;
ifstream inFile;
ofstream outFile;
inFile.open("addressesFile");
if(!inFile)
{
cout<<"\nI am inside the modification function after opening
of addressesFiile. Checking now with if";
getch();
cout<<"\n File not found!";
outFile.close();
exit(-1);
}
outFile.open("new");
cout<<"\nI am inside the modification function after just creating
new";
getch();
n=test();
if(n==0)
{
cout<<"\nI am inside the modification function. new is
empty";
getch();
cout<<"\n The file is empty. ! ";
getch();
return;
}
cout<<"\nI am inside the modification function before entering the
while loop.";
getch();
int deleteMe = 0;
while(inFile.good())
{
inFile.read((char*)&obj,sizeof(obj));
outFile.write((char*)&obj,sizeof(obj));
cout<<"\nI am inside the modification function inside the while
loop and I have finished round "<<deleteMe+1;
deleteMe = deleteMe + 1;
getch();
}
cout<<"\nI am inside the modification function just outside
the while loop.";
inFile.close();
outFile.close();
outFile.open("addressesFile",ios::trunc);
inFile.open("new");
if(inFile.fail())
{
cout<<"\n Sorry! File not found !";
exit(-1);
}
char ch;
cout<<"\n Enter the Land Line Phone Number or the Contact :";
cin>>pn;
ch=cin.get();
cin.get(ch);
for(i=0;i<n;i++)
{
inFile.read((char*)&obj,sizeof(obj));
char d;
if(pn==landLinePhone)
{
//view1();
cout<<" Name : "<<obj.contactName<<"\n";
cout<<" Home Address : "<<obj.homeAddress<<"\n";
cout<<" EMAIL ADDRESS : "<<obj.email<<"\n";
cout<<" Cellular Phone Nmber : "<<obj.cellularPhone<<"\n";
cout<<" Land Line Phone Number : "<<obj.landLinePhone<<"\n
\n";
d=check("HOUSE PHONE NUMBER ");
if((d=='y') || (d=='Y'))
{
cout<<"\n Enter the new land line phone number of the
contact, please. :";
cin>>landLinePhone;
ch=cin.get();
cin.get(ch);
}
if(check("OFFICE PHONE NUMBER ")=='Y')
{
cout<<"\n Enter the new cellular phone number of the
contact, please. :";
cin>>cellularPhone;
ch=cin.get();
cin.get(ch);
}
if(check("Name of the Contact")=='y')
{
cout<<"\n Enter the name of the contact, please. : ";
cin.getline(contactName,20,'\n');
}
if(check("HOME ADDRESS")=='y')
{
cout<<"\n Enter the new Home Address of the contact,
please. :";
cin.getline(homeAddress,50,'\n');
}
if(check("EMAIL ADDRESS:")=='y')
{
cout<<"\n Enter the new E-mail Address of the contact,
please. :";
cin.getline(email,25,'\n');
}
}//the outer if ends here.
outFile.write((char*)&obj,sizeof(obj));
}
outFile.close();
inFile.close();
}