![]() |
#2
G梦2014-09-04 15:28
|
只有本站会员才能查看附件,请 登录

void Cancle(LinkList &l)
{
ClientInfo *CI=new ClientInfo;
ClientInfo *p=new ClientInfo;
ClientInfo *q=new ClientInfo;
CI=l.cFirst->next;
int CardNum;
char*PlaneNum=new char;
cout<<"===========退票============"<<endl;
cout<<"请输入您的证件号:";
cin>>CardNum;
while(1)
{
if(CI->CardNum!=CardNum&&CI!=NULL)
{
CI=CI->next;
}
if(CI==NULL)
{
cout<<"证件号输入有误,请重新输入:";
CI=l.cFirst->next;
cin>>CardNum;
}
else
{
break;
}
}
cout<<"您的所有订单信息如下:"<<endl;
/*@@@显示该客户所有订单信息@@@*/
while(CI!=NULL)
{
if(CI->CardNum==CardNum)
{
cout<<"======================="<<endl;
cout<<"姓名: "<<CI->name<<endl;
cout<<"订单号: "<<CI->OrderNum<<endl;
cout<<"证件号: "<<CI->CardNum<<endl;
cout<<"航班号: "<<CI->PlaneNum<<endl;
cout<<"======================="<<endl;
CI=CI->next;
}
else
{
CI=CI->next;
}
}
CI=l.cFirst->next;
cout<<"请输入您想要退票的航班号:";
fflush(stdin);
gets(PlaneNum);
while(1)
{
if(strcmp(CI->PlaneNum,PlaneNum)!=0&&CI!=NULL)
{
CI=CI->next;
}
if(CI==NULL)
{
cout<<"航班号输入有误,请重新输入:";
CI=l.cFirst->next;
fflush(stdin);
gets(PlaneNum);
}
else
{
break;
}
}
//销毁结点
q=CI=l.cFirst->next;
while(strcmp(CI->PlaneNum,PlaneNum)!=0&&CI!=NULL)
{
p=CI;
CI=CI->next;
}
if(strcmp(CI->PlaneNum,PlaneNum)==0)
{
p->next=CI->next;
delete CI;
CI=NULL;
cout<<"退票成功!";
}
ofstream fout("航班预订情况.txt");
if(!fout)
{
cout<<"文件打开失败!";
exit(-1);
}
while(q!=NULL)
{
cout<<"111";
cout<<q->PlaneNum;
cout<<"222";
fout<<q->PlaneNum<<" ";
fout<<q->name<<" "<<q->OrderNum<<" "<<endl;
q=q->next;
}
fout.close();
}
{
ClientInfo *CI=new ClientInfo;
ClientInfo *p=new ClientInfo;
ClientInfo *q=new ClientInfo;
CI=l.cFirst->next;
int CardNum;
char*PlaneNum=new char;
cout<<"===========退票============"<<endl;
cout<<"请输入您的证件号:";
cin>>CardNum;
while(1)
{
if(CI->CardNum!=CardNum&&CI!=NULL)
{
CI=CI->next;
}
if(CI==NULL)
{
cout<<"证件号输入有误,请重新输入:";
CI=l.cFirst->next;
cin>>CardNum;
}
else
{
break;
}
}
cout<<"您的所有订单信息如下:"<<endl;
/*@@@显示该客户所有订单信息@@@*/
while(CI!=NULL)
{
if(CI->CardNum==CardNum)
{
cout<<"======================="<<endl;
cout<<"姓名: "<<CI->name<<endl;
cout<<"订单号: "<<CI->OrderNum<<endl;
cout<<"证件号: "<<CI->CardNum<<endl;
cout<<"航班号: "<<CI->PlaneNum<<endl;
cout<<"======================="<<endl;
CI=CI->next;
}
else
{
CI=CI->next;
}
}
CI=l.cFirst->next;
cout<<"请输入您想要退票的航班号:";
fflush(stdin);
gets(PlaneNum);
while(1)
{
if(strcmp(CI->PlaneNum,PlaneNum)!=0&&CI!=NULL)
{
CI=CI->next;
}
if(CI==NULL)
{
cout<<"航班号输入有误,请重新输入:";
CI=l.cFirst->next;
fflush(stdin);
gets(PlaneNum);
}
else
{
break;
}
}
//销毁结点
q=CI=l.cFirst->next;
while(strcmp(CI->PlaneNum,PlaneNum)!=0&&CI!=NULL)
{
p=CI;
CI=CI->next;
}
if(strcmp(CI->PlaneNum,PlaneNum)==0)
{
p->next=CI->next;
delete CI;
CI=NULL;
cout<<"退票成功!";
}
ofstream fout("航班预订情况.txt");
if(!fout)
{
cout<<"文件打开失败!";
exit(-1);
}
while(q!=NULL)
{
cout<<"111";
cout<<q->PlaneNum;
cout<<"222";
fout<<q->PlaneNum<<" ";
fout<<q->name<<" "<<q->OrderNum<<" "<<endl;
q=q->next;
}
fout.close();
}
源程序已经上传,主要出现问题的就是我贴的一个cancle()退票函数,删除一个结点指针后为什么不能正确写入文件了啊,楼主表示自己都快调崩溃了,就是发现不了问题,求大神相助


