该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
class Card{
public:
Card(char a[10],int b,double c)
{
strcpy(num,a);
code=b;
money=c;
}
char num[10];
int code;
double money;
};
struct node
{
Card *cod;
node *next;
};
node *createlist(int n);//创建链表
node *findnum(char m[10],node *head);//核对卡号
int findcode(int q,node *head);//核对密码
void fetchmoney(node *head);//取款
void search(node *head);//查询余额
void zhuan(node *head,node *curnode);//转帐
void change_code(node *head);//更改密码
void exit();//退卡
void lock();//锁卡
void save(node *head);//保存信息
int main()
{
node *temp, *listhead=NULL;
int times=0;
listhead=createlist(2);
cout<
cout<
char p[10];
cin>>p;
temp=findnum(p,listhead);
if(temp)
{
while(times<3)
{
cout<
int q;
cin>>q;
if(findcode(q,temp)==0)
{
cout<
times++;
}
else
{
for(int i=0; ;i++)
{
cout<
cout<
cout<取款"<查询余额"<
cout<转帐"<更改密码"<
cout<退出"<
cout<
cout<
int r;
cin>>r;
if(r==1)
{
cout<
fetchmoney(temp);
save(listhead);
}
if(r==2)
{
cout<
search(temp);
save(listhead);
}
if(r==3)
{
cout<
zhuan(temp,listhead);
save(listhead);
}
if(r==4)
{
cout<
change_code(temp);
save(listhead);
}
if(r==5)
{
exit();
goto end;
}
}
}
}
if(times==3)
lock();
}
else
cout<
return 0;
end:
return 1;
}
node *createlist(int n)
{
node *temp, *tail=NULL, *head=NULL;
head=new node;
char x[10];
int y;
double z;
ifstream infile("outfile.txt",ios::in);
infile>>x>>y>>z;
if(head==NULL)
{
cout<
return NULL;
}
else
{
head->cod=new Card(x,y,z);
head->next=NULL;
tail=head;
}
for(int i=0;i
{
temp=new node;
char x[10];
int y;
double z;
if(temp==NULL)
{
cout<
return head;
}
else
{
while(!infile.eof())
infile>>x>>y>>z;
infile.close();
temp->next=NULL;
temp->cod=new Card(x,y,z);
tail->next=temp;
tail=temp;
}
}
return head;
}
node *findnum(char m[10],node *head)
{
while(head)
{
if((strcmp(head->cod->num,m))==0)
{
return head;
}
head=head->next;
}
return NULL;
}
int findcode(int q,node *head)
{
if(head->cod->code==q)
return 1;
}
void fetchmoney(node *head)
{
cout<
double s;
cin>>s;
if(head->cod->money<0)
cout<
if((head->cod->money)>s)
{
head->cod->money=(head->cod->money)-s;
cout<
}
else
{
cout<
}
}
void search(node *head)
{
cout<cod->money<
}
void zhuan(node *head,node *curnode)
{
cout<
char t[10];
cin>>t;
node *hold=findnum(t,curnode);
if(hold)
{
cout<
double d;
cin>>d;
if((head->cod->money)>d)
{
cout<
head->cod->money=(head->cod->money)-d;
hold->cod->money=(hold->cod->money)+d;
}
else
cout<
}
else
cout<
}
void change_code(node *head)
{
cout<
int e,f,g;
cin>>e;
if((head->cod->code)==e)
{
cout<
cin>>f;
cout<
cin>>g;
if(f==g)
{
(head->cod->code)=g;
cout<
}
else
cout<
}
else
cout<
}
void exit()
{
cout<
cout<
}
void lock()
{
cout<
}
void save(node *head)
{ ofstream outfile("outfile.txt",ios::out);
while(head)
{
outfile<cod->num<cod->code<cod->money<
head=head->next;
}
}