我是
靠谱客的博主
直率麦片,这篇文章主要介绍
c语言中简易ATM机的实现c语言中简易ATM机的实现,现在分享给大家,希望可以做个参考。
c语言中简易ATM机的实现
基本功能:
1,有管理员和普通用户两个角色
2,管理员能够执行的操作有:增加用户,注销用户,冻结用户,返回登录界面,关闭ATM机,查看所有用户的状态。
3,普通用户能够执行的操作有:余额查询,存款,取款,修改密码,转账,交易记录查询(未完成),返回登陆界面。
思路:利用单链表和文件操作实现基本功能
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<windows.h>
#include<string.h>
#include<time.h>
void loading()
{
int k=1;
for(;k<3;k++)
{
system("cls");
printf("| 请稍等. | n");
printf("| 加载中: -- | n");
Sleep(200);system("cls");
printf("| 请稍等.. | n");
printf("| 加载中: \ | n");
Sleep(200);system("cls");
printf("| 请稍等... | n");
printf("| 加载中: || | n");
Sleep(200);system("cls");
printf("| 请稍等.... | n");
printf("| 加载中: // | n");
Sleep(200);system("cls");
printf("| 请稍等..... | n");
printf("| 加载中: -- | n");
Sleep(200);system("cls");
printf("| 请稍等...... | n");
printf("| 加载中: \ | n");
Sleep(200);system("cls");
printf("| 请稍等...... | n");
printf("| 加载中: || | n");
Sleep(200);system("cls");
printf("| 请稍等...... | n");
printf("| 加载中: // | n");
Sleep(200);system("cls");
}
}
void show01()
{
system("color 0c");
printf("|********************************************************************| n");Sleep(50);
printf(" ____________________________________________________________________n");Sleep(50);
printf("| 欢迎使用ATM自助存取款系统 | n");Sleep(50);
printf("|");printf(" ");system("date/t");
printf("|");printf(" ");system("time/t");
}
void show002()
{
printf("|请输入您的账户: | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show02()
{
printf("|请输入您的密码: | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show03()
{
printf("|欢迎: | n");Sleep(50);
printf("| Administrator | n");Sleep(50);
printf("| 请选择要执行的操作: | n");Sleep(50);
printf("| 【1】添加账户 | n");Sleep(50);
printf("| 【2】注销账户 | n");Sleep(50);
printf("| 【3】冻结或解冻账户 | n");Sleep(50);
printf("| 【4】退出 | n");Sleep(50);
printf("| 【0】关闭ATM机 | n");Sleep(50);
printf("| 【10】查看所有用户情况 | n");Sleep(50);
}
void show04()
{
printf("|欢迎: | n");Sleep(50);
printf("| Admin | n");Sleep(50);
printf("| 请选择要执行的操作: | n");Sleep(50);
printf("| 【1】修改密码 | n");Sleep(50);
printf("| 【2】余额查询 | n");Sleep(50);
printf("| 【3】存款 | n");Sleep(50);
printf("| 【4】取款 | n");Sleep(50);
printf("| 【5】转账 | n");Sleep(50);
printf("| 【6】交易记录查询 | n");Sleep(50);
printf("| 【7】退卡 | n");Sleep(50);
printf("| 【0】关闭ATM机 | n");Sleep(50);
}
void show05()
{
printf("| 提示: 密码或账户名输入错误,请核对后重新输入 | n");Sleep(1000);
printf("| 即将返回登陆界面 | n");Sleep(5000);
}
void show06()
{
printf("| 请输入新密码: | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show07()
{
printf("| 请再输入一次新密码: | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show08()
{
}
void show09()
{
printf("| 提示: 密码修改成功 | n");Sleep(1000);
printf("| 请输入7退卡后重试 | n");Sleep(50);
}
void show10()
{
printf("| 已返回操作界面 | n");Sleep(50);
printf("| 请输入指令 | n");Sleep(2000);
}
void show11()
{
printf("| 提示:请放入钞票 | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show12()
{
printf("| 存入成功 | n");Sleep(50);
printf("| 提示: 请选择要执行的操作 | n");Sleep(50);
}
void show13()
{
printf("| 提示:请输入取款金额 | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show14()
{
printf("| 提示:请输入要转账的用户名 | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show15()
{
printf("| 转账完毕 | n");Sleep(50);
printf("| | n");Sleep(50);
}
void show16()
{
printf("| 转账失败 | n");Sleep(50);
printf("| 该用户不存在 | n");Sleep(50);
}
void show17()
{
printf("| 警告:您的帐户因为非法洗钱等违规操作已经被冻结 | n");Sleep(50);
printf("| 请联系管理员解冻 | n");Sleep(50);
printf("| 系统将于五秒钟后返回登陆界面 | n");Sleep(1000);
printf("| 系统将于四秒钟后返回登陆界面 | n");Sleep(1000);
printf("| 系统将于三秒钟后返回登陆界面 | n");Sleep(1000);
printf("| 系统将于二秒钟后返回登陆界面 | n");Sleep(1000);
printf("| 系统将于一秒钟后返回登陆界面 | n");Sleep(1000);
}
void show18()
{
printf("| 搜索失败 | n");Sleep(50);
printf("| 该用户不存在 | n");Sleep(50);
}
typedef struct atm
{
char name[20];
char key[20];
int money;
int freeze;
struct atm * pnext;
}atm;
struct atm * g_Head = NULL;
struct atm * g_End = NULL;
void add01()
{
char m[20],n[20];
atm * temp = (struct atm *)malloc(sizeof(struct atm));
struct atm * dtemp =g_Head;
printf("| 提示:请分别输入您新建用户的账户名和账户密码 | n");Sleep(50);
scanf("%s %s",m ,n );
getchar();
while(dtemp!=NULL)
{
if(strcmp(dtemp->name,m)==0||strcmp("hp",m)==0)
{
printf("| 提示:用户注册失败 | n");Sleep(50);
printf("| 原因:该帐户id已经被占用 | n");Sleep(50);
return ;
}
dtemp=dtemp->pnext ;
}
strcpy(temp->name ,m);
strcpy(temp->key ,n);
temp->freeze =0;
temp->money =0;
temp->pnext =NULL;
if (NULL==g_Head||NULL==g_End)
{
g_Head = temp;
g_End = temp;
}
else
{
g_End->pnext =temp;
g_End = temp;
}
printf("| 提示:用户添加成功 | n");Sleep(50);
printf("| | n");Sleep(50);
}
void del()
{
char i[20]={0};
struct atm *first=g_Head ;
struct atm *temp;
int sign=0;
printf("| 请输入要注销的账户名称: | n");Sleep(50);
printf("| | n");Sleep(50);
scanf("%s",i);
getchar();
while(first->pnext!=NULL)
{
if(strcmp(first->pnext->name ,i)==0)
{
sign++;
temp = first->pnext;
first->pnext =temp->pnext;
free(temp);
break;
}
first=first->pnext ;
}
if(sign!=0)
{
printf("| 提示: | n");Sleep(50);
printf("| 用户注销成功 | n");Sleep(50);
printf("| | n");Sleep(50);
}
else
{
printf("| 提示: | n");Sleep(50);
printf("| 用户注销失败 | n");Sleep(50);
printf("| 原因: | n");Sleep(50);
printf("| 该用户不存在 | n");Sleep(50);
}
return ;
}
void freeze()
{
int i=-1;
char k[20];
struct atm * ctemp =g_Head;
printf("| 请输入要冻结的账户名称 | n");Sleep(50);
printf("| | n");Sleep(50);
scanf("%s",k);
getchar();
while(ctemp!=NULL)
{
if((strcmp(k,ctemp->name)==0))
{
if(ctemp->freeze ==0)
{
printf("| 提示:该帐户当前状态为正常,是否冻结 ? | n");Sleep(50);
printf("| 【1】冻结该账户 | n");Sleep(50);
printf("| 【2】放弃操作返回上一级 | n");Sleep(50);
scanf("%d",&i);
getchar();
switch(i)
{
case 1:ctemp->freeze =1;
printf("| 提示:操作成功 | n");Sleep(50);
break;
case 2:break;
}
}
else
{
printf("| 提示:该帐户当前状态为冻结,是否解冻 ? | n");Sleep(50);
printf("| 【1】解冻该账户 | n");Sleep(50);
printf("| 【2】放弃操作返回上一级 | n");Sleep(50);
scanf("%d",&i);
getchar();
switch(i)
{
case 1:ctemp->freeze =0;
printf("| 提示:操作成功 | n");Sleep(50);
break;
case 2:break;
}
}
}
if(ctemp==NULL)
{
printf("| 提示:该账户不存在 | n");Sleep(50);
printf("| 请核对后再试 | n");Sleep(50);
}
ctemp=ctemp->pnext ;
}
return ;
}
void choose(char m[20])
{
struct atm * atemp=g_Head;
char i[20],j[20];
show06();
scanf("%s",i);
getchar();
show07();
scanf("%s",j);
getchar();
if(strcmp(i,j)==0)
{
while(atemp!=NULL)
{
if(strcmp(atemp->name ,m)==0)
{
strcpy(atemp->key,i);
show09();
}
atemp=atemp->pnext ;
}
}
else
{
printf("| 提示: 修改密码操作中两次输入密码不一致 | n");Sleep(1000);
printf("| 即将返回用户操作界面 | n");Sleep(1000);
show04();
}
}
void look(char m[20])
{
struct atm * atemp=g_Head;
while(atemp!=NULL)
{
if(strcmp(m,atemp->name )==0)
{
printf("| 您好: | n");Sleep(50);
printf("| 您的账户余额为:%d元 n",atemp->money);Sleep(50);
printf("| | n");Sleep(50);
show10();
break;
}
atemp=atemp->pnext ;
}
}
void in(char m[20])
{
struct atm * atemp=g_Head;
int i=-1,j=-1;
while(atemp!=NULL)
{
if(strcmp(m,atemp->name )==0)
{
show11();
scanf("%d",&i);
getchar();
atemp->money =atemp->money +i;
show12();
break;
}
atemp=atemp->pnext ;
}
}
void out(char m[20])
{
int i;
struct atm * atemp=g_Head;
while(atemp!=NULL)
{
if(strcmp(m,atemp->name)==0)
{
printf("%s",atemp->name);
show13();
scanf("%d",&i);
if(atemp->money<i)
{
printf("| 您的帐户余额不足,请您查询或存款后在进行此操作 | n");Sleep(50);
printf("| | n");Sleep(50);
break;
}
if(atemp->money>=i)
{
atemp->money = atemp->money -i;
printf("| 交易账单: | n");Sleep(50);
printf("| 本次取款:%d元 n",i);Sleep(50);
printf("| 帐户余额:%d元 n",atemp->money );Sleep(50);
printf("| | n");Sleep(50);
printf("| 取钞完毕 | n");Sleep(50);
break;
}
}
atemp=atemp->pnext ;
}
}
void transform(char m[20])
{
char i[20];
int j;
struct atm * atemp=g_Head;
struct atm * btemp=g_Head;
show14();
scanf("%s",i);
getchar();
while(atemp!=NULL)
{
if(strcmp(m,atemp->name )==0)
{
while(btemp!=NULL)
{
if(strcmp(i,btemp->name )==0)
{
printf("| 提示:请输入转账的金额 | n");Sleep(50);
printf("| | n");Sleep(50);
scanf("%d",&j);
getchar();
if(atemp->money >j||atemp->money ==j)
{
atemp->money =atemp->money -j;
btemp->money=btemp->money +j;
show15();
break;
}
else
{
printf("| 提示:您的余额不足 | n");Sleep(50);
printf("| 请存款或者输入较小的转账金额 | n");Sleep(50);
break;
}
}
btemp=btemp->pnext ;
}
break;
}
atemp=atemp->pnext;
}
if (atemp==NULL)
{
show16();
}
}
void search()
{
printf("| 正在努力建设中: | n");Sleep(50);
printf("| | n");Sleep(50);
}
void savetofile()
{
FILE * pfile=NULL;
atm * temp=g_Head;
char strbuf[60]={0};
char strscore[5];
char strscore1[5];
if(g_Head==NULL)
{
return ;
}
pfile=fopen("用户数据.txt","w+");
if(pfile==NULL)
{
printf(" 警告:文件丢失或不存在,请检查目录");
return;
}
while(temp!=NULL)
{
strcpy(strbuf,temp->name );
strcat(strbuf,",");
strcat(strbuf,temp->key );
strcat(strbuf,"+");
_itoa(temp->freeze,strscore,10);
strcat(strbuf,strscore);
strcat(strbuf,"-");
_itoa(temp->money,strscore1,10);
strcat(strbuf,strscore1);
strcat(strbuf,"@");
fwrite(strbuf,1,strlen(strbuf),pfile);
temp=temp->pnext;
strcat(strbuf,"%");
}
fclose(pfile);
}
void redfile()
{
char message[10000];
char a1[100],a2[100],a3[100],a4[100],a6[]={"%"};
int i=0,j=0,k=0,l=0,m=0,o=0;
int tempmoney=0;
int tempfreeze=0;
FILE*pfile;
pfile=fopen("用户数据.txt","rb");
if(NULL==pfile)
{
printf("| 警告:保存用户数据的文件丢失或不存在 | n");Sleep(4000);
printf("| | n");Sleep(50);
return;
}
while(!feof(pfile))
{
fscanf(pfile,"%s",message);
strcat(message,a6);
printf("原始数据是:%sn",message);Sleep(50);
for(i=0;message[i]!='%';)
{
atm * temp = (struct atm *)malloc(sizeof(struct atm));
if(message[i]!=',')
{
for(j=0;;j++,i++)
{
if(message[i]==',')
{
break;
}
a1[j]=message[i];
}
a1[j]='