这代码可以测试,为什么不能运行,提示:exe应用程序有错。
#include<iostream>#include<string>
#include<fstream>
using namespace std;
typedef struct log //存储记录
{
char datatime[25]; //存储时间
char w_d; //存储标志
float amount; //存储金额
}log;
typedef struct node_log //存储记录节点
{
log data; //存储记录
struct node_log *next; //下一存储记录节点指针
}node_log,*p_node_log;
typedef struct account //账户记录
{
char id[10]; //账号
char name[10]; //姓名
float balance; //帐户余额
}account;
typedef struct node_account //账户记录节点
{
account data; //帐户记录
struct node_log *nlog; //存储帐户节点指针
struct node_account *next; //下一帐户记录节点指针
}node_account,*p_node_account;
class money
{
public:
void inputaccount(); //输入初始的帐户数据
void outputaccount(); //显示改变和排序后的所有帐户数据
void deleteaccount(); //销户
void insertaccount(); //开户
void saveaccount(); //存钱
void drawaccount(); //取钱
// void traveraccount(); //查询帐号交易记录
// void sortdata(); //排序所有账号
private:
node_account *head1;
node_log *head2;
};
//ifstream infile("input.txt",ios::in);
void money::inputaccount() //输入初始数据
{
node_log *p3,*p4;
node_account *p1,*p2,*head;
int i=1;
int n=10;
head=NULL;
while(i<n)
{
p1=new node_account;
p3=new node_log;
cout<<"请输入ID号,姓名,账户余额:"<<endl;
cin>>p1->data.id>>p1->data.name>>p1->data.balance;
cout<<"请输入交易日期:"<<endl;
cin>>p3->data.datatime;
p2->next=p1;
p4->next=p3;
p4=p3;
p2=p1;
i++;
}
p2->next=NULL;
p4->next=NULL;
}
void money::outputaccount() //显示所有数据
{
node_account *p0;
node_log *p1;
p0=head1;
p1=head2;
while(p0!=NULL&&p1!=NULL)
{
cout<<p0->data.id<<" "<<p0->data.name<<" "<<p0->data.balance<<endl;
cout<<p1->data.datatime<<endl;
p0=p0->next;
p1=p1->next;
}
}
void money::deleteaccount() //销户
{
node_account *p0,*p1;
p0=head1;
while(p0->data.id!=p0->data.id&&p0->next!=NULL)
{
p1=p0;
p1=p1->next;
}
if(p0->data.id==p0->data.id)
{
if(head1==p0)
head1=p0->next;
else
p1->next=p0->next;
delete p0;
}
else
cout<<"对不起,没有这用户"<<endl;
}
void money::insertaccount() //开户
{
node_account *p0,*p1,*p2;
p1=head1;
p0=new node_account;
cout<<"请输入开户的ID号,你的姓名:"<<endl;
cin>>p0->data.id>>p0->data.name;
if(head1=NULL)
{
head1=p0;
p0->next=NULL;
}
else
while(p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
}
void money::saveaccount() //存钱
{
float amount;
node_account *p0;
p0=head1;
cout<<"请输入你的帐号:"<<endl;
cin>>p0->data.id;
if(p0->data.id!=NULL)
{
cout<<"你的帐户余额为:"<<p0->data.balance<<endl;
cout<<"请输入你要存款的金额:"<<endl;
cin>>amount;
p0->data.balance=p0->data.balance+amount;
cout<<"存入成功!"<<"你的余额为:"<<p0->data.balance<<endl;
}
else
cout<<"所找账户不存在,请重新输入:";
}
void money::drawaccount() //取钱
{
float amount;
node_account *p0;
p0=head1;
cout<<"请输入你的帐号:";
cin>>p0->data.id;
if(p0->data.id!=NULL)
{
cout<<"请选择取金额的数目:"<<endl;
cin>>amount;
if(amount>p0->data.balance)
{
cout<<"对不起,你的余额不足,请及时充值!"<<endl;
}
else
p0->data.balance=p0->data.balance-amount;
cout<<"你的账户余额为"<<p0->data.balance<<endl;
}
else
cout<<"对不起,你所找的帐户不存在,请重新输入!"<<endl;
}
/*void money::traveraccount() //查询帐户交易记录
{
node_account *p0;
p0=head1;
cout<<"请输入你的账号:";
cin>>p0->data.id;
if(p0->data.id!=NULL)
{
cout<<"你的帐号交易记录如下:"<<endl;
}
else
cout<<"所查找的用户不存在!"<<endl;
}
void money::sortdata() //排序所有帐户
{
node_account *p0,*p1,*p2;
p1=head1;
}
*/
int main()
{
money mon;
int ch=0;
while(1)
{
cout<<" "<<"*******欢迎使用银行自助服务系统******"<<endl;
cout<<" "<<"**************请选择操作*************"<<endl;
cout<<" *"<<" 1.开户 *"<<endl;
cout<<" *"<<" 2.销户 *"<<endl;
cout<<" *"<<" 3.存钱 *"<<endl;
cout<<" *"<<" 4.取钱 *"<<endl;
cout<<" *"<<" 5.查看账户信息 *"<<endl;
cout<<" *"<<" 6.退出系统 *"<<endl;
cout<<" *"<<"************************************"<<endl;
cin>>ch;
switch(ch)
{
case 1:
mon.insertaccount();
break;
case 2:
mon.deleteaccount();
break;
case 3:
mon.saveaccount();
break;
case 4:
mon.drawaccount();
break;
//case 5:
// mon.traveraccount();
// break;
case 6:
return 0;
break;
default:
cout<<"输入有误,请重新输入"<<endl;
}
}
}