text file

int SearchRecord(int i)
{
int iname=0;
system("cls");
cout<<"\t\t**************Search Customer Record***************\n\n"<<endl;
if(i<=0)
{
cout<<"\nNothing to search!\n";
system("pause");
return i;
}
int ID,z;
cout<<"Enter the ID number you want to search:";
cin>>ID;
if(ID>i||ID<0)
{
cout<<"\nNot valid ID!\n";
system("pause");
return i;
}
for(z=0;z<=i;z++)
{
if(ID==mv[z].id)
{
cout<<"\t\t[ID] \t\t="<<mv[z].id<<endl;
cout<<"\t\t[Passport No \t\t="<<mv[z].passportno<<endl;
cout<<"\t\t[First Name \t\t="<<mv[z].firstname<<endl;
cout<<"\t\t[Last Name] \t\t="<<mv[z].lastname<<endl;
cout<<"\t\t[Originating City]\t\t="<<mv[z].originatingcity<<endl;
cout<<"\t\t[Destination City]\t\t="<<mv[z].destinationcity<<endl;
cout<<"\t\t[Flight Number] \t\t="<<mv[z].flightnumber<<endl;
cout<<"\t\t[Departure Time] \t\t="<<mv[z].departuretime<<endl;
cout<<"\t\t[Departure Date] \t\t="<<mv[z].departuredate<<endl;
cout<<"\t\t[Total Cost] \t\t="<<mv[z].totalcost<<endl;
cout<<"\t\t[Seat Class] \t\t="<<mv[z].seatclass<<endl;
cout<<"\t\t[Seat No] \t\t="<<mv[z].seatno<<endl;

cout<<endl<<endl;
cout<<"DATA SEARCH SUCCESSFULLY!";
system("pause");
}
}
return 0;
}

int DeleteRecord(int i)
{
int iname=0;
ofstream ofile;
int ID,z,a;
system("cls");
cout<<"\t\t**************Delete Customer Record***************\n\n"<<endl;
if(i<=0)
{
cout<<"\nNothing to delete!\n";
system("pause");
return i;

}
cout<<"Enter the ID number you want to delete:";
cin>>ID;
if(ID>i||ID<0)
{
cout<<"\nNot Valid ID!\n";
system("pause");
return i;
}
for(z=0;z<=i;z++)
{
if(ID == mv[z].id)
{
cout<<"\t\t[ID] \t\t="<<mv[z].id<<endl;
cout<<"\t\t[Passport No \t\t="<<mv[z].passportno<<endl;
cout<<"\t\t[First Name \t\t="<<mv[z].firstname<<endl;
cout<<"\t\t[Last Name] \t\t="<<mv[z].lastname<<endl;
cout<<"\t\t[Originating City]\t\t="<<mv[z].originatingcity<<endl;
cout<<"\t\t[Destination City]\t\t="<<mv[z].destinationcity<<endl;
cout<<"\t\t[Flight Number] \t\t="<<mv[z].flightnumber<<endl;
cout<<"\t\t[Departure Time] \t\t="<<mv[z].departuretime<<endl;
cout<<"\t\t[Departure Date] \t\t="<<mv[z].departuredate<<endl;
cout<<"\t\t[Total Cost] \t\t="<<mv[z].totalcost<<endl;
cout<<"\t\t[Seat Class] \t\t="<<mv[z].seatclass<<endl;
cout<<"\t\t[Seat No] \t\t="<<mv[z].seatno<<endl;
cout<<endl<<endl;
for(z=0;z<i;z++)
{
if(ID==mv[z].id)
{
strcpy(mv[z].passportno,mv[i-1].passportno);
strcpy(mv[z].firstname,mv[i-1].firstname);
strcpy(mv[z].lastname,mv[i-1].lastname);
strcpy(mv[z].originatingcity,mv[i-1].originatingcity);
strcpy(mv[z].destinationcity,mv[i-1].destinationcity);
strcpy(mv[z].flightnumber,mv[i-1].flightnumber);
strcpy(mv[z].departuretime,mv[i-1].departuretime);
strcpy(mv[z].departuredate,mv[i-1].departuredate);
strcpy(mv[z].totalcost,mv[i-1].totalcost);
strcpy(mv[z].seatclass,mv[i-1].seatclass);
strcpy(mv[z].seatno,mv[i-1].seatno);
cout<<"DATA DELETE SUCCESSFULLY!";
system("pause");
ofile.open("SaveData.txt",ios::trunc);

if(ofile.fail())
{
{
cout<<"error writting to directory\n\n";
}
for(a=0;a<i;a++)
ofile<<mv[z].id<<endl;
ofile<<mv[z].passportno<<endl;
ofile<<mv[z].firstname<<endl;
ofile<<mv[z].lastname<<endl;
ofile<<mv[z].originatingcity<<endl;
ofile<<mv[z].destinationcity<<endl;
ofile<<mv[z].flightnumber<<endl;
ofile<<mv[z].departuretime<<endl;
ofile<<mv[z].departuredate<<endl;
ofile<<mv[z].totalcost<<endl;
ofile<<mv[z].seatclass<<endl;
ofile<<mv[z].seatno<<endl;
}
ofile.close();
}
}
}
}
return--i;
}

[b]please help me.if i want to delete one record the program can delete but the program delete all the record in the text file got any solution for this........tq
[/b]
Last edited on
closed account (zb0S216C)
What do you need help with?

Wazzak
Topic archived. No new replies allowed.