首页 > 编程知识 正文

atm存钱c语言,C语言ATM

时间:2024-03-25 09:49:57 阅读:332514 作者:ARPW

本文目录一览:

怎样用c语言编写ATM系统

真正的ATM系统不可能只是用C语言编写的,它应该是一套完整独立的系统,核心代码更机密,不会轻易的泄露。

C语言可以写一个类似于ATM系统的框架,用以模拟ATM机上的各种操作。

框架代码如下:

    #includeiostream.h  

    #includestdio.h  

       

    int main()   

    {  

        int choice =- 1;   

          

        while(1) {  

            printf("请选择n1.logint2.registn");  

                scanf("%d", choice);  

            switch(choice) {  

                case 1:  

                     login();  

                     break;  

                case 2:  

                     regist();  

                     break;  

                default:  

                     printf("输入有误,重新输入n");  

                     break;  

            }  

        }  

        return 0;

    }  

      

    void login() {  

        printf("IN LOGINn");  

        int flag = -1;  

        int X = -1;  

        printf("输入账户和密码n");  

        flag = search();  

        if(falg == 1) {  

            printf("存在,进入主页面n");  

            X = menu();  

            if(X == 1)  

                 return;  

        }  

        else if(flag == 0) {  

            printf("账户或密码错误n");  

            return;       

        }  

    }  

      

    int regist() {  

        printf("IN REGISTn");  

        return 1;  

    }  

      

    int menu() {  

        printf("IN MENUn");  

        int key = -1;  

        int N = -1;  

        while(1) {  

            printf("请选择业务:1.refert2.depositt3.withdrawt4.transfert5.resetPWt6.退出n");  

                scanf("%d", key);  

            switch(key) {  

                case 1:  

                    N = refer();  

                    break;  

                case 2:  

                    N = deposit();  

                    break;  

                case 3:  

                    N = withdraw();  

                    break;  

                case 4:  

                    N = transfer();  

                    break;  

                case 5:  

                    N = resetPW();  

                    break;  

                case 6:  

                    N = 6;  

                    return 1;  

                    break;  

                default:  

                    printf("输入有误,重新选择:n");   

                    break;  

            }  

            if(N%2 == 0) {  

                printf("Error!n");  

            }   

        }  

    }  

      

    int refer() {  

        printf("IN REFERn");  

        //输出余额   

        return 1;  

    }  

      

    int deposit() {  

        printf("IN DEPOSITn");  

        //存钱   

        return 3;  

    }  

      

    int withdraw() {  

        printf("IN WITHDRAWn");  

        //取钱   

        return 5;  

    }  

      

    int transfer() {  

        ptintf("IN TRANSFERn");  

        //转账   

        return 7;  

    }  

      

    int resetPW() {  

        prtintf("IN RESETPWn");  

        //重设密码   

        return 9;  

    }

编写一个关于“ATM系统”c语言程序。 要求,1功能:存钱,取钱,转账,修改密码,只要现实中有的都得有,

下面的是我自己写的一个, 里面很多细节都没有进行细致的处理, 只是粗略的实现了基本的功能

后面有我的测试数据, 希望能有帮助

#include stdio.h

#include stdlib.h

#include string.h

typedef struct _account

{

char * UID;

char * pwd;

int balance;

char * UName;

}ACCOUNT, * PACCOUNT;

void InitAccount(PACCOUNT pA); // 初始化账户

void showAccount(ACCOUNT A, bool flag); // 显示账户信息, flag表示是否显示全部信息. 如果是true则需要输入用户密码

bool deposite(PACCOUNT pA); // 存钱, 内部需要密码验证并输入金额

bool withDraw(PACCOUNT pA); // 取钱, 内部需要密码验证并输入金额

bool transfer(PACCOUNT pA, PACCOUNT pB); // 转账, 需要密码验证, 并输入金额

bool conduct(PACCOUNT pA, int chose, PACCOUNT pB); // 处理, 就是根据菜单项处理用户的操作选择

void modifyPwd(PACCOUNT pA); // 更改用户密码

bool Authentication(PACCOUNT pA); // 密码认证, 3次机会输入密码

void memFree(PACCOUNT pA, PACCOUNT pB); // 在堆上分配的内存的释放

int main(void)

{

// 建立两个账户, 分别是操作账户和接受转账的账户

PACCOUNT pMainAcc = (PACCOUNT)malloc(sizeof(ACCOUNT));

PACCOUNT pAssistAcc = (PACCOUNT)malloc(sizeof(ACCOUNT));

// 初始化两个账户的信息

InitAccount(pMainAcc);

InitAccount(pAssistAcc);

// 进行菜单控制, 提供用户操作

int chose = -1;

while(chose != 0)

{

printf("n1. 存钱t2. 取钱t3. 转账t4. 更改密码t5. 显示账户信息t0.退出n");

scanf("%d", chose);

conduct(pMainAcc, chose, pAssistAcc);

}

return 0;

}

bool conduct(PACCOUNT pA, int chose, PACCOUNT pB)

{

bool rtnflag = true;

switch(chose)

{

case 1:

if(!deposite(pA))

printf("操作失败!");

else

printf("操作成功!");

break;

case 2:

if(!withDraw(pA))

printf("操作失败!");

else

printf("操作成功!");

break;

case 3:

if(!transfer(pA, pB))

printf("操作失败!");

else

printf("操作成功!");

break;

case 4:

modifyPwd(pA);

break;

case 5:

showAccount(*pA, true);

break;

case 0:

rtnflag = false;

memFree(pA, pB);

break;

}

return rtnflag;

}

void InitAccount(PACCOUNT pA)

{

printf("请初始化账户名, 密码, 姓名, 账户余额.n");

pA-UID = (char *)malloc(sizeof(char)*20);

pA-pwd = (char *)malloc(sizeof(char)*20);

pA-UName = (char *)malloc(sizeof(char)*20);

gets(pA-UID);

gets(pA-pwd);

gets(pA-UName);

scanf("%d", pA-balance);

getchar();

return ;

}

void showAccount(ACCOUNT A, bool flag)

{

if(flag)

{

int i = 0;

getchar();

char * tmpPwd = (char *)malloc(sizeof(char)*20);

while(strcmp(tmpPwd, A.pwd))

{

printf("请输入账户%s的密码:n", A.UID);

gets(tmpPwd);

if(++i 3)

{

printf("对不起, 密码输入错误!只能显示部分信息!n");

showAccount(A, false);

free(tmpPwd);

return ;

}

}

printf("账户信息如下:n账户名t账户密码t账户余额t姓名n");

printf("%6st%8s%8dt%8tsn", A.UID, A.pwd, A.balance, A.UName);

free(tmpPwd);

}

else

{

printf("账户信息如下:n账户名t账户余额t姓名n");

printf("%6st%8dt%4sn", A.UID, A.balance, A.UName);

}

return ;

}

bool deposite(PACCOUNT pA)

{

if(!Authentication(pA))

return false;

int val = 0;

printf("请输入金额:n");

scanf("%d", val);

pA-balance += val;

return true;

}

bool withDraw(PACCOUNT pA)

{

if(!Authentication(pA))

return false;

printf("请输入金额");

int val = 0;

scanf("%d", val);

if(pA-balance = val)

{

pA-balance -= val;

}

else

{

printf("对不起, 余额不足!");

return false;

}

return true;

}

bool transfer(PACCOUNT pA, PACCOUNT pB)

{

if(!Authentication(pA))

return false;

printf("请输入金额");

int val = 0;

scanf("%d", val);

if(pA-balance = val)

{

pA-balance -= val;

pB-balance += val;

}

else

{

printf("对不起, 余额不足!");

return false;

}

return true;

}

void modifyPwd(PACCOUNT pA)

{

if(Authentication(pA))

{

printf("请输入新的密码!");

free(pA-pwd);

pA-pwd = (char *)malloc(sizeof(char)*20);

gets(pA-pwd);

}

else

{

printf("对不起, 您没有权限进行密码修改!");

}

}

bool Authentication(PACCOUNT pA)

{

getchar();

int i = 0;

char * tmpPwd = (char *)malloc(sizeof(char)*20);

while(strcmp(tmpPwd, pA-pwd))

{

printf("请输入%s的密码, 3次机会:n", pA-UID);

gets(tmpPwd);

if(++i == 3)

{

return false;

}

}

return true;

}

void memFree(PACCOUNT pA, PACCOUNT pB)

{

free(pA);

free(pB);

return ;

}

/*

运行环境: VC6.0

请初始化账户名, 密码, 姓名, 账户余额.

wed

qweasd

wednesday

800

请初始化账户名, 密码, 姓名, 账户余额.

hu

sad

huni

200

1. 存钱 2. 取钱 3. 转账 4. 更改密码 5. 显示账户信息 0.退出

1

请输入wed的密码, 3次机会:

qwe

请输入wed的密码, 3次机会:

qweasd

请输入金额:

54

操作成功!

1. 存钱 2. 取钱 3. 转账 4. 更改密码 5. 显示账户信息 0.退出

5

请输入账户wed的密码:

qwe

请输入账户wed的密码:

qweasd

账户信息如下:

账户名 账户密码 账户余额 姓名

wed qweasd 854 s

1. 存钱 2. 取钱 3. 转账 4. 更改密码 5. 显示账户信息 0.退出

4

请输入wed的密码, 3次机会:

123

请输入wed的密码, 3次机会:

qweasd

请输入新的密码!123qwe

1. 存钱 2. 取钱 3. 转账 4. 更改密码 5. 显示账户信息 0.退出

1

请输入wed的密码, 3次机会:

qweasd

请输入wed的密码, 3次机会:

123qwe

请输入金额:

43

操作成功!

1. 存钱 2. 取钱 3. 转账 4. 更改密码 5. 显示账户信息 0.退出

5

请输入账户wed的密码:

123qwe

账户信息如下:

账户名 账户密码 账户余额 姓名

wed 123qwe 897 s

1. 存钱 2. 取钱 3. 转账 4. 更改密码 5. 显示账户信息 0.退出

Press any key to continue

*/

用C语言编写一个自动存取款机模拟

给你个加强版:includeiostream.h

#includestdlib.h

#includestring.h

struct Bank

{

char name[6],num[8],password[6];

double money,o;

}b,q;

void tuichu();

void fuction();

void cunqian();

void queren();

void cin1()

{

b.money=0;

cinb.name;

cout"请输入您的卡号:"endl;

cinb.num;

cout"请输入您的密码:"endl;

cinb.password;

coutendl;

}

void error()

{

cout"您的输入错误,请再输入一遍!"endl;

}

void cout1()

{

cout"您的名字是:"b.nameendl"您的卡号是:"b.numendl"您的密码是:"b.passwordendl;

}

void one()

{

cout"请按‘1’存钱, 请按‘2’取钱!"endl"请按‘3’查钱, 请按‘4’退出!" endl;

}

void tishi()

{

char c;

cout"如果您想退出,请按 'Y' . 否则,请按'N' !";

cinc;

if(c=='y'||c=='Y') tuichu();

if(c=='n'||c=='Y') fuction();

else

{

error();

tishi();

};

}

void yue()

{

cout"您的余额为:"b.moneyendl;

tishi();

}

void cunqian()

{

b.o=b.money;

cout"您想存多少钱?"endl;

cinb.money;

if((b.money'0')(b.money'9'))

{

cout"请输入数字!"endl;

cunqian();

}

if((b.money=999999999)(b.money=(-999999999)))

{

b.money+=b.o;

yue();

}

else

{

error();

cunqian();

b.money=0;

}

}

void quqian()

{

double d;

cout"您想取多少钱?"endl;

cind;

if((d999999999)(d=0)(d=b.money+2000))

{

b.money-=d;

yue();

}

else

{

cout"您的透支余额超过2000元,操作失败!"endl;

quqian();

}

}

void chaqian()

{

yue();

}

void tuichu()

{

coutendl"欢迎下次光临欢迎进入C++工商银行!!"endl;

cout"请取回您的卡,再次感谢!"endl;

exit(0);

}

void fuction()

{

char x;

{

one();

cinx;

switch(x)

{

case '1': cunqian();break;

case '2': quqian();break;

case '3': chaqian();break;

case '4': tuichu();break;

default: cout"您的输入错误,请输入1到4按键,谢谢!"endl;fuction();

}

}

}

void cin2()

{

cout"请输入您的卡号:"endl;

cinq.num;

cout"请输入您的密码:"endl;

cinq.password;

coutendl;

}

void cout2()

{

cout"欢迎进入C++工商银行!"endl"请您先开户,谢谢!"endl"请输入您的名字:"endl;

cin1();

cout1();

queren();

}

void queren()

{

cout"请再次确认您的信息:"endl;

int e,f;

cin2();

e=strcmp(q.num,b.num);

f=strcmp(q.password,b.password);

if (e==0f==0) fuction();

else {

cout"您的信息有误,请重新输入:"endl;

cin2();

e=strcmp(q.num,b.num);

f=strcmp(q.password,b.password);

if (e==0f==0) fuction();

else

{

cout"您的信息有误,请重新输入:"endl;

cin2();

e=strcmp(q.num,b.num);

f=strcmp(q.password,b.password);

if(e==0f==0) fuction();

else {

cout"您的信息有误,请重新输入:"endl;

tuichu();

}

}

}

}

void main()

{

cout2();

}

用c语言编写ATM的程序,实现开户、存款、取款、查询余额、转账的业务逻辑。

#include stdio.h

#include stdlib.h

#include conio.h

#include string.h

void regist();

void login();

void quite();

void inputpassword(char mima[]);

void service();

struct bank

{

char name[20];

char password[7];

int account;

double money;

}kehu;

int find;

int a[10];

struct bank one;

FILE *fp;

void main()

{

int i;

int t=1;

for(i=0;i100;i++)

{

printf("tttttt欢迎使用青软ATM系统n");

printf("tttttt正在进入主界面,请稍等");

int j;

for(j=1;jt;j++)

{

printf(".");

}

t++;

if(t==10)

{

t=1;

}

printf("ntttttt%d%%",i);

system("cls");

}

while(1)

{

printf("tttttt服务类型: n");

printf("tttttt[a]: 用户注册n");

printf("tttttt[b]: 用户登录n");

printf("tttttt[c]: 退出系统n");

printf("tttttt请选择服务: ");

fflush(stdin);

char xz;

scanf("%c",xz);

if(xz=='a'||xz=='A')

{

regist();

} else if (xz=='b'||xz=='B')

{

login();

} else if(xz=='c'||xz=='C')

{

quite();

} else

{

printf("输入有误,请重新输入");

}

getch();

system("cls");

}

}

void inputpassword(char mima[])

{

int i=0;

char ch;

while(1)

{

ch=getch();

if(ch!='r')

{

if(ch!='b'){

mima[i]=ch;

i++;

printf("*");

}else{

if(i0){

i--;

printf("b b");

}

}

}else{

break;

}

}

mima[i]='';

printf("n");

}

void regist()

{

fp=fopen("atm.txt","ab+");

if(fp==NULL)

{

printf("nttt文件打开失败!");

return;

}

system("cls");

printf("ttt现在执行的是注册函数的使用n");

printf("tt请输入用户名: ");

fflush(stdin);

gets(kehu.name);

char password1[7];

while(1)

{

while(1)

{

printf("nntt请输入密码:");

fflush(stdin);

inputpassword(kehu.password);

int n=strlen(kehu.password);

if(n==6)

{

break;

}else

{

printf("ntt密码必须为6位!");

}

}

printf("ntt请输入正确密码!: ");

fflush(stdin);

inputpassword(password1);

if(strcmp(kehu.password,password1)==0)

{

break;

}else{

printf("nntt两次密码必须相同!");

}

}

rewind(fp);

struct bank k;

if(fread(k,sizeof(struct bank),1,fp)==1)

{

fseek(fp,-sizeof(k),2);

fread(k,sizeof(k),1,fp);

kehu.account=k.account+1;

}else{

kehu.account=20170001;

}

kehu.money=0;

fseek(fp,0,2);

fwrite(kehu,sizeof(struct bank),1,fp);

fclose(fp);

printf("nntt开户成功! ");

printf("ntt您的账号为%d!",kehu.account);

printf("ntt现在请您重新登录!");

}

void searchmoney()

{

system("cls");

printf("您现在使用的是查询余额功能: n");

printf("nntt您的余额是%0.2lf",one.money);

}

void savemoney()

{

system("cls");

double inmoney;

printf("请您选择您要存款的金额 n");

scanf("%lf",inmoney);

int q;

int r=1;

for(q=0;q100;q++)

{

int w;

for(w=1;wr;w++)

{

printf(".");

}

r++;

if(r==10)

{

r=1;

}

printf("ntttttt正在存款%d%%",q);

system("cls");

}

one.money=one.money+inmoney;

fseek(fp,-sizeof(one),1);

fwrite(one,sizeof(one),1,fp);

printf("nntttttt您已存款成功!");

}

void withdrawalmoney()

{

system("cls");

double outputsomemoney;

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

scanf("%lf",outputsomemoney);

if(one.moneyoutputsomemoney){

printf("您的余额已不足,请您注意!");

}else {

int q;

int r=1;

for(q=0;q100;q++)

{

int w;

for(w=1;wr;w++)

{

printf(".");

}

r++;

if(r==10)

{

r=1;

}

printf("ntttttt正在取款%d%%",q);

system("cls");

}

one.money=one.money-outputsomemoney;

fseek(fp,-sizeof(one),1);

fwrite(one,sizeof(one),1,fp);

printf("nntttttt您已取款成功!请点清钞票!");

printf("nntttttt您现在的余额为%lf",one.money);

}

}

void transfermoney()

{

system("cls");

int duifang;

int qian;

fflush(stdin);

printf("nnntt您现在使用的是转账功能");

printf("nttt请输入您要转账的账户:");

scanf("%d",duifang);

int n=ftell(fp);

rewind(fp);

int flag=0;

struct bank temp;

while(fread(temp,sizeof(temp),1,fp)==1)

{

if(temp.account==duifang)

{

flag=1;

break;

}

}

if(flag==1)

{

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

scanf("%d",qian);

if(one.money=qian)

{

int q;

int r=1;

for(q=0;q100;q++)

{

int w;

for(w=1;wr;w++)

{

printf(".");

}

r++;

if(r==10)

{

r=1;

}

printf("ntttttt正在转账,请稍后!%d%%",q);

system("cls");

}

temp.money=temp.money+qian;

fseek(fp,-sizeof(temp),1);

fwrite(temp,sizeof(temp),1,fp);

one.money=one.money-qian;

fseek(fp,n-sizeof(one),0);

fwrite(one,sizeof(one),1,fp);

printf("ntttt转账成功!");

}else{

printf("ntttt您的余额已不足!");

}

}

}

void xiugai(){

system("cls");

printf("nntt 现在进行的是修改密码功能n");

char oldpassword[7];

char newpassword[7];

char newpassword1[7];

int i;

for(i=0;i3;i++){

printf("nttt 请输入旧密码:n");

inputpassword(oldpassword);

if(strcmp(oldpassword,one.password)==0){

printf("nttt 输入成功!n");

break;

}else{

printf("nttt 密码输入有误,请重新输入!n");

}

}

if(i3){

while(1){

printf("nttt 请输入您的新密码:n");

inputpassword(newpassword);

printf("nttt 请输入您的确认密码:n ");

inputpassword(newpassword1);

if(strcmp(newpassword,newpassword1)==0){

strcpy(one.password,newpassword);

fseek(fp,-sizeof(one),1);

fwrite(one,sizeof(one),1,fp);

printf("nttt 密码修改成功!");

break;

}else{

printf("nttt 两次密码输入不一致!");

}

}

}else{

printf("nttt 密码输入错误!");

}

}

int zhuxiaozhanghao()

{

system("cls");

int zhuxiaoxitong;

char sf;

printf("你要注销的账号是%d",one.account);

printf("你是否要对此账号进行注销?nntt请您选择:注销(Y)or不注销(N):");

fflush(stdin);

scanf("%c",sf);

if(sf=='y'||sf=='Y')

{

printf("正在为您注销!n",one.account);

zhuxiaoxitong=1;

}else{

printf("不注销系统!n",one.account);

}

return zhuxiaoxitong;

}

void service()

{

while(1){

system("cls");

printf("nnntttttt现在是服务系统,本系统有以下服务");

printf("ntttttt[a] 查询余额n");

printf("ntttttt[b] 存款服务n");

printf("ntttttt[c] 转账服务n");

printf("ntttttt[d] 取款服务n");

printf("ntttttt[e] 修改密码n");

printf("ntttttt[f] 注销 n");

printf("ntttttt[g] 退出系统n");

char e;

printf("ntttttt您要选择的服务是:");

fflush(stdin);

scanf("%c",e);

switch(e)

{ case'A':

case'a': searchmoney() ;break;

case'B':

case'b': savemoney() ;break;

case'C':

case'c': transfermoney() ;break;

case'D':

case'd': withdrawalmoney() ;break;

case'E':

case'e': xiugai() ;break;

case'F':

case'f': {int zhuxiaoxitong=zhuxiaozhanghao();{if(zhuxiaoxitong==1) return;}break;}

case'G':

case'g': quite();break;

}

printf("nnntttt按任意键继续......n");

getch();

}

}

void login()

{

fp=fopen("atm.txt","rb+");

if(fp==NULL)

{

printf("nnntttt文件打开失败!");

return;

}

system("cls");

printf("ntttttt现在执行的是登录函数的使用n");

int zhanghao;

printf("ntttttt请输入账号:");

scanf("%d",zhanghao);

int flag=0;

while(fread(one,sizeof(one),1,fp)==1)

{

if(zhanghao==one.account){

flag=1;

break;

}

}

char password2[7];

if(flag==1){

int h;

for(h=0;h3;h++){

printf("ntttttt请输入密码:");

fflush(stdin);

inputpassword(password2);

if(strcmp(password2,one.password)==0)

{

printf("ntttttt登陆成功!");

service();

break;

}else{

printf("密码不正确!");

}

}

if(h==3){

printf("nttt您的密码三次输入有误,返回");

}

}else{

printf("无此账号!");

}

fclose(fp);

}

void quite()

{

system("cls");

printf("ttt现在执行的是退出函数的使用n");

exit(0);

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。