课程设计c语言版银行取款机系统.docx

上传人:b****6 文档编号:8040165 上传时间:2023-01-28 格式:DOCX 页数:27 大小:19.85KB
下载 相关 举报
课程设计c语言版银行取款机系统.docx_第1页
第1页 / 共27页
课程设计c语言版银行取款机系统.docx_第2页
第2页 / 共27页
课程设计c语言版银行取款机系统.docx_第3页
第3页 / 共27页
课程设计c语言版银行取款机系统.docx_第4页
第4页 / 共27页
课程设计c语言版银行取款机系统.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

课程设计c语言版银行取款机系统.docx

《课程设计c语言版银行取款机系统.docx》由会员分享,可在线阅读,更多相关《课程设计c语言版银行取款机系统.docx(27页珍藏版)》请在冰豆网上搜索。

课程设计c语言版银行取款机系统.docx

课程设计c语言版银行取款机系统

课程设计C语言版银行取款机系统

#include

#include

#include

#include

#defineboolint

#definetrue1

#defineLENsizeof(structperson)

structper/*定义全局结构体变量*/

{

charname[20];

charID[20];

intmoney;

charmima[6];

structper*next;

};

typedefstructperson

{

structperkehu;

structperson*next;

}L;

voidchaxun(structper*head);/*函数声明*/

voidkaihu(structper*head);

voiddenglu(structper*head);

voiddisplay(structper*head);

voidcaidan(structper*head);

voidqukuan(structper*head);

voidxgmm(structper*head);

voidcunkuan(structper*head);

voidzhuangzhang(structper*head);

voidtuichu();

voidmenu();

voidout(structperson*r);

voiddel(structperson**r);

voidsort(structperson**r);

voidinsert(structperson**r);

voidsearch1(structperson*r);

voidsearch2(structperson*r);

voidsearch3(structperson*r);

voidcreatelist(structperson**r);

/*主函数*/

/////////////////////////////////////////////

voidmain()

{

charx;

charchoose;

intflag=1;

structperson*r=NULL;/*定义头指针*/

structper*head=NULL;/*定义头指针*/

printf("********************************\n");

printf("**欢迎使用ATM自动取款机系统***\n");

printf("********************************\n\n\n\n");

printf("---------------------------\n");

printf("|1开户|\n");

printf("---------------------------\n");

printf("|2登录|\n");

printf("---------------------------\n");

printf("|3前台客户信息查询中心|\n");

printf("---------------------------\n");

printf("|请选择您的需求|\n");

printf("---------------------------\n");

scanf("%s",&x);

system("cls");

switch(x)

{

case'1':

system("cls");

kaihu(head);/*调用开户函数*/

break;

case'2':

system("cls");

denglu(head);/*调用登陆函数*/

break;

case'3':

system("cls");

menu();/*调用后台菜单函数*/

break;

}

while(flag)

{

system("cls");

menu();/*调用后台菜单函数*/

choose=getchar();

switch(choose)

{

case'1':

createlist(&r);

out(r);/*调用后台输出函数*/

system("pause");

system("cls");

break;

case'2':

search1(r);/*调用后台卡号查询函数*/

system("pause");

system("cls");

break;

case'3':

search2(r);/*调用后台姓名查询函数*/

break;

case'4':

search3(r);/*调用后台余额查询函数*/

break;

case'5':

del(&r);/*调用后台删除用户函数函数*/

break;

case'6':

insert(&r);/*调用后台增加用户函数*/

break;

case'7':

sort(&r);/*调用后台排序函数函数*/

out(r);/*调用后台输出函数函数*/

break;

case'8':

out(r);

break;

case'0':

flag=0;

printf("Theend.\n");

break;

}

}

}

/*开户函数*/

////////////////////////////////

voidkaihu(structper*head)

{

head=NULL;

FILE*fp;/*定义文件指针*/

per*p1=NULL,*p2=NULL;/*定义链表指针*/

p1=(per*)malloc(sizeof(per));/*开辟内存单元*/

printf("请输入您的姓名:

\n");

scanf("%s",p1->name);

printf("请设置您的卡号:

\n");

scanf("%s",p1->ID);

printf("请设置您银行卡密码:

\n");

scanf("%s",p1->mima);

p1->money=0;

p1->next=NULL;

if(NULL==head)/*为新增客户开辟内存单元*/

{

head=(per*)malloc(sizeof(per));

head->next=p1;

}

else/*为新增客户开辟内存单元*/

{

for(p2=head;p2->next!

=NULL;p2=p2->next);

p2->next=p1;

}

if((fp=fopen("save.txt","ab+"))==NULL)/*打开文件*/

{

printf("cannotopenfile\n");

return;

}

if(fwrite(p1,sizeof(per),1,fp)!

=1)/*将链表信息写入文件中*/

printf("filewriteerror\n");

fclose(fp);

system("cls");

printf("您的个人信息为\n");

display(head);/*调用链表输出函数*/

}

/*登陆函数*/

/////////////////////////////////////

voiddenglu(structper*head)

{

chard[20];

charmima[20];

inti,j;

FILE*fp;/*定义文件指针*/

per*p,*q=NULL;

if((fp=fopen("save.txt","rb+"))==NULL)/*打开一个二进制文件,为读方式*/

{

printf("不能打开文件\n");/*如不能打开,则结束程序*/

}

p=(per*)malloc(sizeof(per));/*申请空间*/

head=p;

while(!

feof(fp))/*循环读数据直到文件尾结束*/

{

if(1!

=fread(p,sizeof(per),1,fp))

break;/*如果没读到数据,跳出循环*/

p->next=(per*)malloc(sizeof(per));/*为下一个结点申请空间*/

q=p;/*保存当前结点的指针,作为下一结点的前驱*/

p=p->next;/*指针后移,新读入数据链到当前表尾*/

}

q->next=NULL;/*最后一个结点的后继指针为空*/

fclose(fp);

printf("***********************\n");

printf("* 欢迎来到建设银行*\n");

printf("***********************\n");

for(j=1;j<4;j++)/*限制卡号输入的次数的循环*/

{

printf("请您输入卡号\n");

scanf("%s",d);

for(q=head;q!

=NULL;q=q->next)/*便利链表*/

{

if(strcmp(q->ID,d)!

=0)/*核对账号*/

{

continue;

}

else

{

for(i=1;i<4;i++)/*限制密码输入的次数的循环*/

{

printf("\n\n请输入您的密码\n");

scanf("%s",mima);

if(strcmp(q->mima,mima)!

=0)/*核对密码*/

{

printf("密码不正确,请重新输入密码\n");

system("pause");

system("cls");

continue;/*若密码不对,跳出循环*/

}

else

{

system("cls");

caidan(head);/*调用菜单函数*/

}

}

printf("\n\n\n您输入密码三次错误,谢谢光临\n");

system("pause");

system("cls");

exit(0);

}

}

printf("\n\n\n您输入的卡号有误,请重试\n");

system("pause");

system("cls");

}

printf("您的卡号三次输入错误,谢谢使用");

exit(0);

}

/*输出函数*/

////////////////////////////////////////////

voiddisplay(structper*head)

{

FILE*fp;

per*p,*q=NULL;

if((fp=fopen("save.txt","rb+"))==NULL)/*打开一个二进制文件,为读方式*/

{

printf("不能打开文件\n");/*如不能打开,则结束程序*/

}

p=(per*)malloc(sizeof(per));/*申请空间*/

head=p;

while(!

feof(fp))/*循环读数据直到文件尾结束*/

{

if(1!

=fread(p,sizeof(per),1,fp))

break;/*如果没读到数据,跳出循环*/

p->next=(per*)malloc(sizeof(per));/*为下一个结点申请空间*/

q=p;/*保存当前结点的指针,作为下一结点的前驱*/

p=p->next;/*指针后移,新读入数据链到当前表尾*/

printf("姓名:

%s\n卡号:

%s\n余额:

%4d\n",q->name,q->ID,q->money);

}

q->next=NULL;/*最后一个结点的后继指针为空*/

fclose(fp);

printf("\n");

printf("恭喜您开户成功,请登录\n");

system("pause");

system("cls");

denglu(head);

}

/*银行菜单函数*/

//////////////////////////////////////////

voidcaidan(structper*head)

{

head=NULL;

inti;

while

(1)

{

printf("请选择您需要的业务\n");/*银行业务菜单*/

printf("***********************************\n");

printf("**1取款*****2查询**\n");

printf("***********************************\n");

printf("**3转账*****4修改密码**\n");

printf("***********************************\n");

printf("**5存款*****6退出**\n");

printf("***********************************\n\n\n");

scanf("%d",&i);

if(i<6||i>0)

{

switch(i)

{

case1:

qukuan(head);/*调用银行取款函数*/

system("pause");

system("cls");

break;

case2:

system("cls");

chaxun(head);/*调用银行查询函数*/

break;;

case3:

system("cls");

zhuangzhang(head);/*调用银行转账函数*/

break;

case4:

system("cls");

xgmm(head);/*调用银行修改密码函数*/

break;

case5:

system("cls");

cunkuan(head);/*调用银行存款函数*/

break;

case6:

system("cls");

tuichu();/*调用银行退出函数*/

break;

}}

else

{

printf("您的输入有误\n");

system("pause");

system("cls");

}

}

}

/*银行取款函数函数*/

//////////////////////////////////////////

voidqukuan(structper*head)

{

head=NULL;

per*p;/*链表头指针*/

inti;

FILE*fp;/*文件头指针*/

fp=fopen("save.txt","rb+");/*开辟空间*/

p=(per*)malloc(sizeof(per));

fread(p,sizeof(per),1,fp);

fclose(fp);

system("cls");

printf("**************************************\n");

printf("**1:

100元*****2:

200元**\n");

printf("**************************************\n");

printf("**3:

300元*****4:

400元**\n");

printf("**************************************\n");

printf("**5:

500元*****6:

600元**\n");

printf("**************************************\n");

printf("请按要求选择您要取款的金额\n");

scanf("%d",&i);

if(i>6||i<=0)

{

printf("对不起,您的输入有误\n\n");

return;

}

else

{

i=100*i;

if(i>p->money)

{

printf("对不起,您的余额不足\n");

system("pause");

system("cls");

caidan(head);

}

else

{

p->money-=i;

if((fp=fopen("save.txt","wb+"))==NULL)/*打开文件*/

{

printf("cannotopenfile\n");

return;

}

if(fwrite(p,sizeof(per),1,fp)!

=1)/*将修改的信息重新写入文件*/

printf("filewriteerror\n");

printf("您已成功走取%d元\n",i);

p->next=NULL;

fclose(fp);/*关闭文件*/

}

}

}

/*银行转账函数*/

//////////////////////////////////////////

voidzhuangzhang(structper*head)

{

head=NULL;/*链表头指针*/

FILE*fp;/*文件头指针*/

chari[20],j[20],k;

per*p,*q=NULL;

if((fp=fopen("save.txt","rb+"))==NULL)/*打开一个二进制文件,为读方式*/

{

printf("不能打开文件\n");/*如不能打开,则结束程序*/

}

p=(per*)malloc(sizeof(per));/*申请空间*/

head=p;

while(!

feof(fp))/*循环读数据直到文件尾结束*/

{

if(1!

=fread(p,sizeof(per),1,fp))

break;/*如果没读到数据,跳出循环*/

p->next=(per*)malloc(sizeof(per));/*为下一个结点申请空间*/

q=p;/*保存当前结点的指针,作为下一结点的前驱*/

p=p->next;/*指针后移,新读入数据链到当前表尾*/

}

q->next=NULL;/*最后一个结点的后继指针为空*/

fclose(fp);

printf("请输入转账号码\n");

scanf("%s",i);

p=head;

for(p;p!

=NULL;p->next)

{

if(strcmp(i,p->ID)!

=0)

{

printf("请重新输入\n");

zhuangzhang(head);

}

else

{

system("cls");

printf("**************************************\n");

printf("**1:

100元*****2:

200元**\n");

printf("**************************************\n");

printf("**3:

300元*****4:

400元**\n");

printf("**************************************\n");

printf("**5:

500元*****6:

600元**\n");

printf("**************************************\n");

printf("请输入转账金额\n");

scanf("%d",&k);

if(k>6||k<=0)/*限制输入范围*/

{

printf("对不起,您的输入有误\n\n");

return;

}

else

{

k=k*100;

if(k>p->money)

{

printf("对不起,您的余额不足\n");

system("pause");

system("cls");

caidan(head);

}

else

{

printf("您已成功转账%d元\n",k);

p->money-=k;

if((fp=fopen("save.txt","wb+"))==NULL)/*打开文件*/

{

printf("cannotopenfile\n");

return;

}

if(fwrite(p,sizeof(per),1,fp)!

=1)/*将修改的信息重新写入文件*/

printf("filewriteerror\n");

p->next=NULL;

fclose(fp);

p->next=NULL;

system("pause");

system("cls");

}

}

}

}

}

/*银行查询函数*/

//////////////////////////////////////////

voidchaxun(structper*head)

{

head=NULL;/*链表头指针*/

per*p;/*文件头指针*/

FILE*fp;

fp=fopen("save.txt","rb+");/*打开文件*/

p=(per*)malloc(sizeof(per));

fread(p,sizeof(per),1,fp);/*将信息从文件中读出来*/

fclose(fp);

printf("您卡上原有余额为%d元\n\n",p->money);

system("pause");

system("cls");

}

/*银行修改密码函数*/

//////////////////////////////////////////

voidxgmm(structper*head)

{

head=NULL;/*链表头指针*/

per*p;

charmima[20];

FILE*fp;/*文件头指针*/

fp=fopen("save.txt","rb+");/*开辟内存*/

p=(per*)malloc(sizeof(per));/*打开文件*/

fread(p,sizeof(per),1,fp);/*将信

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1