银行ATM机工作流程模拟编程(代码)

本文介绍了一个基于ATM自动取款机系统的实现,包括登录、查询、取款、存款、修改密码等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<stdio.h>
#include<stdlib.h>
#include <conio.h>
#include <string.h>

void denglu(struct people *head,struct people *p);
void jiemian(struct people *head,struct people *p);
void chaxun(struct people *head,struct people *p);
void qukuan(struct people *head,struct people *p);
void cunkuan(struct people *head,struct people *p);
void xiugai(struct people *head,struct people *p);
void tuika(struct people *head,struct people *p);
void xinxi(struct people *head,struct people *p);



struct people
{
    char name[10];
    char account[20];
    char password[10];
    float money;
    struct people*next;
};



void main()
{
    int i,z,a,t=0;
    char account[20],password[10],ch;
    struct people *head,*p;
    FILE *fp=fopen("1.txt","r");
    head=NULL;

    if(fp==NULL){printf("系统出错");return 1;}
    for(i=0;i<5;i++)
    {
        p=(struct people*)malloc(sizeof(struct people));
        fscanf(fp,"%s%s%s%f",p->name,p->account,p->password,&(p->money));
        p->next=head;
        head=p;
    }
    fclose(fp);
    printf("***********欢迎使用ATM自动取款机***********\n");
    printf("*******************************************\n");
    denglu(head,p);
        
}


void denglu(struct people *head,struct people *p)
{
    int a;
    char account[20];
    int i=0,t=0;
    char password[10],ch;
    printf("请输入卡号:");
    scanf("%s",account);
    //scanf("account:%s\npassword:",account);
    for(a=0;a<5;a++)
    {
        if(strcmp(account,p->account)==0)
        {

            printf("请输入密码:");
            while(1)
            {
                 while((ch=getch())!='\r')
                 {
                    password[i++]=ch;
                    putchar('*');
                 }
                 password[i]='\0';
                   t++;
                 if(strcmp(password,p->password)==0)
                 {
                     system("cls");
                     printf("\n欢迎使用本系统!\n");
                     jiemian(head,p);
                     break;
                 }
                 else
                 {
                     if(t<3)
                     {
                         printf("\n密码错误,请重新输入:");
                         i=0;
                     }
                     else
                     {
                             printf("\n对不起,你无权使用本系统! 退出系统!\n");
                            for(i=0;i<1000000000;i++);
                            system("cls");
                            main();
                     }
                 }
            }
            
           
        }
        else p=p->next;
        
    }
}

void jiemian(struct people *head,struct people *p)
{
    int z;
    printf("1-----------个人信息\n");
    printf("2-----------查询余额\n");
    printf("3---------------取款\n");
    printf("4---------------存款\n");
    printf("5-----------修改密码\n");
    printf("0---------------退卡\n");
    while(1)
    {
        printf("\n请输入序号:");
        scanf("%d",&z);
        switch(z)
        {
        case 1:system("cls");xinxi(head,p);break;
        case 2:system("cls");chaxun(head,p);break;
        case 3:system("cls");qukuan(head,p);break;
        case 4:system("cls");cunkuan(head,p);break;
        case 5:system("cls");xiugai(head,p);break;
        case 0:system("cls");tuika(head,p);break;
        default:printf("操作序号不合法!!!");
        return ;
        }
    }
}

void xinxi(struct people *head,struct people *p)
{
    char gg;
    printf("***********************************************\n");
    printf("            用户名:%s\n",p->name);
    printf("              帐号:%s\n",p->account);
    printf("***********************************************\n");
    printf("按任意键返回菜单,按N键退卡!\n");
    if(gg=getch()=='n')
    {system("cls");tuika(head,p);}
    else
    {system("cls");jiemian(head,p);}
}

void chaxun(struct people *head,struct people *p)
{
    char gg;
    printf("余额:%7.2f元\n",p->money);
    printf("按任意键返回菜单,按N键退卡!\n");
    if(gg=getch()=='n')
    {system("cls");tuika(head,p);}
    else
    {system("cls");jiemian(head,p);}
}


void qukuan(struct people *head,struct people *p)
{
    char gg;
    float a;
    struct people *f;
    FILE *fp=fopen("1.txt","w+");
    printf("请输入取款金额:");
    scanf("%f",&a);
    if(a>p->money)
        printf("余额不足!");
    else
    {
        printf("成功取款%7.2f元\n",a);
        p->money=p->money-a;
            f=head;
            while(f!=NULL)
            {
                fprintf(fp,"%s\t%s\t%s\t%f\n",f->name,f->account,f->password,p->money);
                 f=f->next;
            }
            fclose(fp);
    }
    printf("按任意键返回菜单,按N键退卡!\n");
    if(gg=getch()=='n')
    {system("cls");tuika(head,p);}
    else
    {system("cls");jiemian(head,p);}

}

void cunkuan(struct people *head,struct people *p)
{
    char gg;
    float a;
    struct people *f;
    FILE *fp=fopen("1.txt","w+");
    printf("请输入存款金额:");
    scanf("%f",&a);
        printf("成功存款%7.2f元\n",a);
        p->money=p->money+a;
            f=head;
            while(f!=NULL)
            {
                fprintf(fp,"%s\t%s\t%s\t%f\n",f->name,f->account,f->password,f->money);
                 f=f->next;
            }
            fclose(fp);
    printf("按任意键返回菜单,按N键退卡!\n");
    if(gg=getch()=='n')
    {system("cls");tuika(head,p);}
    else
    {system("cls");jiemian(head,p);}


}

void xiugai(struct people *head,struct people *p)
{
    char gg;
    char a[10],b[10],c[10];
    struct people *f;
    FILE *fp=fopen("1.txt","w+");
    printf("请输入原密码:");
    scanf("%s",a);
    if(strcmp(a,p->password)==0)
    {
        printf("请输入新密码:");
        scanf("%s",b);
        printf("请再次输入新密码:");
        scanf("%s",c);
        if(strcmp(b,c)==0)
        {
            printf("密码修改成功!\n");
            strcpy(p->password,b);
            
            f=head;
            while(f!=NULL)
            {
                fprintf(fp,"%s\t%s\t%s\t%f\n",f->name,f->account,f->password,f->money);
                f=f->next;
            }
            fclose(fp);
        }
        else
            printf("两次输入不同!\n");

    }
    else
    {
        printf("原密码输入错误!\n");
    }
    
    printf("按任意键返回菜单,按N键退卡!\n");
    if(gg=getch()=='n')
        {system("cls");tuika(head,p);}
    else
    {system("cls");jiemian(head,p);}
}

void tuika(struct people *head,struct people *p)
{
    int i ;
    printf("请取回您的磁卡");
    for(i=0;i<1000000000;i++);
    system("cls");
    main();
}

转载于:https://www.cnblogs.com/mzct123/p/4822895.html

#include #include using namespace std; class Consumer { private: long Accnumber; string conname; double Balance; long password; public: Consumer(); void login(); int Query(); int transfer(); int withdraw(); int update();//修改密码 void choose(); }; Consumer::Consumer() { Accnumber=1030070128; conname="林杰东"; Balance=10000.00; password=123456; } void Consumer::login() { long password0; int i=0; cout<<"**********欢迎登入林杰东银行**********"<<endl; cout<<endl; cout<<endl; cout<<endl; cout<<"请输入您的6位密码(错误输入不得超过3次):"; cout<<endl; cout<<endl; cout<<endl; cout<<endl; cout<<"**********欢迎登入林杰东银行**********"<<endl; while(i<3) { cout<>password0; i++; if(password0!=password) { cout<<"对不起,您的输入有误,请重新输入!!!"<<endl; if(i==3) { cout<<"您的错误输入已满3次,请取出您的银行卡,以免被吞卡!!!"<<endl; login(); break; } } else { cout<<"登入成功!!!"<<endl; break;} } } int Consumer::Query() { cout<<"您的用户名:"; cout<<conname<<endl; cout<<"您的账号:"; cout<<Accnumber<<endl; cout<<"您的当前余额:"; cout<<Balance<<endl; cout<<"密码:"; cout<<password<<endl; return 1; } int Consumer::transfer() { long Accnumber1,Accnumber2; double money; cout<>Accnumber1; if(Accnumber1==Accnumber) { cout<<"对不起,您要转入的账号是当前银行卡的账号,无法转账!!!请重新输入其他账号!!!"<<endl; return transfer(); } else { cout<>Accnumber2; if(Accnumber1==Accnumber2 ) { cout<>money; cout<=money) { Balance=Balance-money; cout<<"转账成功!!!"<<endl; cout<<"您的当前余额:"; return Balance; } else { cout<<"对不起,您当前余额不足,请重新转账!!!"<<endl; return transfer(); } } else { cout<<"您两次输入的账号有误,请重新输入!!!"<<endl; return transfer(); } } } int Consumer::update() { long password1; long password2; long password3; cout<>password1; if(password1!=password) { cout<<"对不起,您的输入有误,请重新输入!!!"<<endl; return update(); } else { cout<>password2; cout<>password3; if(password2==password3) { password=password3; cout<<"恭喜您,您的密码修改成功!!!"<<endl; cout<<"您的新密码:"; return password; } else { cout<<"对不起,您的两次输入有误,请重新输入!!!"<<endl; return update(); } } } int Consumer::withdraw() { double number; cout<>number; if(Balance<number) { cout<<"你的账号余额不足 "<<number<<"."<<endl; cout<<"取款失败!"<<endl; return withdraw(); } else { cout<<"取款成功!!!"<<endl; Balance=Balance-number; cout<<"您的当前账号余额为:"; return Balance; } } void Consumer::choose() { cout<<"1.查 询"<<endl; cout<<"2.转 账"<<endl; cout<<"3.修改密码"<<endl; cout<<"4.取 款"<<endl; cout<<"0.退出系统"<<endl; } class ATM { public: Consumer c; int menu(); }; int ATM::menu() { c.login(); int choice=0; while(choice!=5) { cout<<"**********欢迎登入林杰东银行**********"<<endl; c.choose(); cout<<"**********欢迎登入林杰东银行**********"<<endl; cout<>choice; switch(choice) { case 1: cout<<c.Query()<<endl; break; case 2: cout<<c.transfer()<<endl; break; case 3: cout<<c.update()<<endl; break; case 4: cout<<c.withdraw()<<endl; break; case 0: cout<<"请取出您的银行卡,欢迎下次使用!!!"<<endl; return 0; break; default: cout <<"输入错误!请重新输入!\n\n"; break; } } } int main() { ATM atm; atm.menu(); return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值