利用结构体和构造函数并且采用输入输出文件实现ATM机系统。
主要功能有:
利用三种方法查询、开户、登陆、菜单、取款、修改密码、存款、转账、创建个人信息、输出、删除、增加、退出。
是一个功能齐全,完备的ATM机系统。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct per //定义结构体
{
char name[20];
char ID[20];
int money;
char mima[6];
struct per * next;
};
typedef struct person //定义另一结构体
{
struct per kehu;
struct person *next;
}L;
void chaxun(struct per *head); //各个函数的声明
void kaihu(struct per *head);
void denglu(struct per *head);
void caidan(struct per *head);
void qukuan(struct per *head);
void xgmm(struct per *head);
void cunkuan(struct per *head);
void zhuanzhang(struct per *head);
void chuangjian(struct person **Phead);
void shuchu(struct person *Phead);
void shanchu(struct person **Phead);
void zengjia(struct person **Phead);
void chaxun1(struct person *Phead);
void chaxun2(struct person *Phead);
void chaxun3(struct person *Phead);
void tuichu();
void menu();
/*主函数*/
//
void main()
{
char x;
char choose; //choose为定义输入选择的变量
int flag=1;
struct person *Phead=NULL; //Phead为定义二层头指针
struct per *head=NULL; //head为定义一层头指针
printf("*****************************\n");
printf("**欢迎使用ATM自动取款机系统**\n");
printf("*****************************\n");
printf("——————————————\n");
printf("| 1 开户 |\n");
printf("——————————————\n");
printf("| 2 登陆 |\n");
printf("——————————————\n");
printf("| 3 前台客户信息查询中心|\n");
printf("——————————————\n");
printf("| 4 请选择您的需求 |\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':chuangjian(&Phead);
shuchu(Phead); //调用后台输出函数
system("pause");
system("cls");
break;
case '2':chaxun1(Phead); //调用后台卡号查询函数
system("pause");
system("cls");
break;
case '3':chaxun2(Phead); //调用后台姓名查询函数
system("pause");
system("cls");
break;
case '4':
chaxun3(Phead); //调用后台余额查询函数
system("pause");
system("cls");
break;
case '5':shanchu(&Phead); //调用后台删除用户函数
system("pause");
system("cls");
break;
case '6':
zengjia(&Phead); //调用后台增加用户函数
system("pause");
system("cls");
break;
case '7':shuchu(Phead); //调用后台输出函数函数
system("pause");
system("cls");
break;
case '8':shuchu(Phead);
system("pause");
system("cls");
break;
case '0':flag=0;
printf("The end.\n");
break;
}
}
}
/*开户函数*/
void kaihu(struct per *head)
{
head=NULL;
FILE *fp; //定义文件指针
struct per *p1=NULL,*p2=NULL; //p1,p2为定义链表指针
p1=(struct per*)malloc(sizeof(struct 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;
printf("您的个人信息为");
printf("姓名:%s \n卡号:%s \n余额:%4d\n",p1->name,p1->ID,p1->money);
if(NULL==head) //为新用户开辟内存单元
{
head=(struct per *)malloc(sizeof(struct per));
head->next=p1; //进行头插法,将其作为第一个节点
}
else //为新增客户开辟内存单元
{
for(p2=head;p2->next!=NULL;p2=p2->