新聞中心
編寫一個(gè)C語言程序模擬銀行ATM機(jī)的賬戶管理功能,系統(tǒng)主要實(shí)現(xiàn)以下功能
按照你的愿意把空都填好了,VC++ 6.0下編譯能通過,有警告信息,運(yùn)行基本上能用,不過個(gè)人認(rèn)為這個(gè)系統(tǒng)有很大的不足,比如輸入賬號(hào)的時(shí)候沒有輸出反饋信息,以及沒有對(duì)誤操作的處理等等。需要的話可以幫你改改!
創(chuàng)新互聯(lián)公司是專業(yè)的雙塔網(wǎng)站建設(shè)公司,雙塔接單;提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行雙塔網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
#include stdio.h
#include conio.h
#include stdlib.h
#include string.h
#define AN 9 //表示賬號(hào)8位
#define PN 7 //表示密碼6位
#define ASN 3 //表示系統(tǒng)中共有3個(gè)賬戶信息
struct Account
{
char accountnumber[AN]; //表示賬號(hào)信息
char password[PN]; //表示賬戶的密碼信息
double balance; //表示賬戶的余額
};
struct Account ats[ASN]={{"00000001","123456",100},{"00000002","123456",200},{"00000003","123456",300}};
//ats數(shù)組用于存儲(chǔ)系統(tǒng)中三個(gè)賬戶的信息
int isCorrect(char *an,char *psd)
{
int i;
for(i=0;iASN;i++)
if(strcmp(ats[i].accountnumber,an)==0 strcmp(psd,ats[i].password)==0)
return 1;
return 0;
}
double getBalance(char *an)
{
int i;
for(i=0;iASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
return ats[i].balance;
}
void deposit(char *an,int amount)
{
int i;
for(i=0;iASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
ats[i].balance+=amount;
}
int withdraw(char *an,int amount)
{
int i;
for(i=0;iASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
return ats[i].balance-=amount;
}
void main()
{
char AccountNumber[AN]={'\0'};
char psd[PN]={'\0'};
int i,errorcount=0;
while(1)
{
printf("\n請(qǐng)輸入8位賬號(hào):");
for(i=0;i8;i++)
AccountNumber[i]=getch();
printf("\n請(qǐng)輸入6為密碼:");
for(i=0;i6;i++)
{
psd[i]=getch();
putchar('*');
}
if(isCorrect(AccountNumber,psd)==1)
{
int tag,amount;
while(1)
{
printf("\n歡迎登錄銀行賬戶管理系統(tǒng),請(qǐng)選擇您要的服務(wù):1、查詢余額;2、存款操作;3、取款操作;4、退出系統(tǒng)\n");
scanf("%d",tag);
switch(tag)
{
case 1:
printf("您現(xiàn)在的余額為%f元\n",getBalance(AccountNumber));
break;
case 2:
printf("請(qǐng)輸入您的存款金額:");
scanf("%d",amount);
deposit(AccountNumber,amount);
printf("存款成功!您的當(dāng)前余額為:%f元\n",getBalance(AccountNumber));
break;
case 3:
printf("請(qǐng)輸入您的取款金額:");
scanf("%d",amount);
if(amount=getBalance(AccountNumber))
printf("取款成功!您的當(dāng)前余額為:%f元\n",withdraw(AccountNumber,amount));
else
printf("取款失敗!\n");
break;
case 4:
break;
}
if(tag==4)
break;
}
}
else
{
errorcount++;
if(errorcount==3)
{
printf("您已經(jīng)連續(xù)三次輸入錯(cuò)誤,系統(tǒng)將自動(dòng)關(guān)閉\n");
break;
}
}
}
}
在C語言中ATM自動(dòng)取款機(jī)的功能程序怎么寫???
#includestdio.h
void main()
{
char SelectKey,CreditMoney,DebitMoney;
while(1)
{
do{
clrscr();
puts("Please select key:");
puts("1.Quary");
puts("2.Credit");
puts("3.Debit");
puts("4.Return");
SelectKey=getch();
}while(SelectKey!='1'SelectKey!='2'SelectKey!='3'SelectKey!='4');
switch(SelectKey)
{
case'1':
clrscr();
puts("Your balance is $1000");
getch();
break;
case'2':
do{
clrscr();
puts("Please select Credit money:");
puts("1.$50");
puts("2.$100");
puts("3.Return");
CreditMoney=getch();
}while(CreditMoney!='1'CreditMoney!='2'CreditMoney!='3');
switch(CreditMoney)
{
case'1':
clrscr();
puts("Your Credit money is $50,Thank you!");
getch();
break;
case'2':
clrscr();
puts("Your Credit money is $100,Thank you!");
getch();
break;
case'3':
break;
}
break;
case'3':
do{
clrscr();
puts("Please select Debit money:");
puts("1.$50");
puts("2.$100");
puts("3.$500");
puts("4.$1000");
puts("5.Return");
DebitMoney=getch();
}while(DebitMoney!='1'DebitMoney!='2'DebitMoney!='3'DebitMoney!='4'DebitMoney!='5');
switch(DebitMoney)
{
case'1':
clrscr();
puts("Your Debit money is $50,Thank you!");
getch();
break;
case'2':
clrscr();
puts("Your Debit money is $100,Thank you!");
getch();
break;
case'3':
clrscr();
puts("Your Debit money is $500,Thank you!");
getch();
break;
case'4':
clrscr();
puts("Your Debit money is $1000,Thank you!");
getch();
break;
case'5':
break;
}
break;
case'4':
return;
}
}
}
幾個(gè)小錯(cuò)誤而已...比如忘了寫雙撇號(hào),switch寫錯(cuò)了...還有!= 忘了寫! 等等.. 以上程序可以運(yùn)行了
用c語言編寫ATM的程序,實(shí)現(xiàn)開戶、存款、取款、查詢余額、轉(zhuǎn)賬的業(yè)務(wù)邏輯。
#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("\t\t\t\t\t\t歡迎使用青軟ATM系統(tǒng)\n");
printf("\t\t\t\t\t\t正在進(jìn)入主界面,請(qǐng)稍等");
int j;
for(j=1;jt;j++)
{
printf(".");
}
t++;
if(t==10)
{
t=1;
}
printf("\n\t\t\t\t\t\t%d%%",i);
system("cls");
}
while(1)
{
printf("\t\t\t\t\t\t服務(wù)類型: \n");
printf("\t\t\t\t\t\t[a]: 用戶注冊(cè)\n");
printf("\t\t\t\t\t\t[b]: 用戶登錄\n");
printf("\t\t\t\t\t\t[c]: 退出系統(tǒng)\n");
printf("\t\t\t\t\t\t請(qǐng)選擇服務(wù): ");
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("輸入有誤,請(qǐng)重新輸入");
}
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]='\0';
printf("\n");
}
void regist()
{
fp=fopen("atm.txt","ab+");
if(fp==NULL)
{
printf("\n\t\t\t文件打開失敗!");
return;
}
system("cls");
printf("\t\t\t現(xiàn)在執(zhí)行的是注冊(cè)函數(shù)的使用\n");
printf("\t\t請(qǐng)輸入用戶名: ");
fflush(stdin);
gets(kehu.name);
char password1[7];
while(1)
{
while(1)
{
printf("\n\n\t\t請(qǐng)輸入密碼:");
fflush(stdin);
inputpassword(kehu.password);
int n=strlen(kehu.password);
if(n==6)
{
break;
}else
{
printf("\n\t\t密碼必須為6位!");
}
}
printf("\n\t\t請(qǐng)輸入正確密碼!: ");
fflush(stdin);
inputpassword(password1);
if(strcmp(kehu.password,password1)==0)
{
break;
}else{
printf("\n\n\t\t兩次密碼必須相同!");
}
}
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("\n\n\t\t開戶成功! ");
printf("\n\t\t您的賬號(hào)為%d!",kehu.account);
printf("\n\t\t現(xiàn)在請(qǐng)您重新登錄!");
}
void searchmoney()
{
system("cls");
printf("您現(xiàn)在使用的是查詢余額功能: \n");
printf("\n\n\t\t您的余額是%0.2lf",one.money);
}
void savemoney()
{
system("cls");
double inmoney;
printf("請(qǐng)您選擇您要存款的金額 \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("\n\t\t\t\t\t\t正在存款%d%%",q);
system("cls");
}
one.money=one.money+inmoney;
fseek(fp,-sizeof(one),1);
fwrite(one,sizeof(one),1,fp);
printf("\n\n\t\t\t\t\t\t您已存款成功!");
}
void withdrawalmoney()
{
system("cls");
double outputsomemoney;
printf("請(qǐng)您選擇您要取款的金額 \n");
scanf("%lf",outputsomemoney);
if(one.moneyoutputsomemoney){
printf("您的余額已不足,請(qǐng)您注意!");
}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("\n\t\t\t\t\t\t正在取款%d%%",q);
system("cls");
}
one.money=one.money-outputsomemoney;
fseek(fp,-sizeof(one),1);
fwrite(one,sizeof(one),1,fp);
printf("\n\n\t\t\t\t\t\t您已取款成功!請(qǐng)點(diǎn)清鈔票!");
printf("\n\n\t\t\t\t\t\t您現(xiàn)在的余額為%lf",one.money);
}
}
void transfermoney()
{
system("cls");
int duifang;
int qian;
fflush(stdin);
printf("\n\n\n\t\t您現(xiàn)在使用的是轉(zhuǎn)賬功能");
printf("\n\t\t\t請(qǐng)輸入您要轉(zhuǎn)賬的賬戶:");
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("請(qǐng)輸入轉(zhuǎn)賬金額:");
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("\n\t\t\t\t\t\t正在轉(zhuǎn)賬,請(qǐng)稍后!%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("\n\t\t\t\t轉(zhuǎn)賬成功!");
}else{
printf("\n\t\t\t\t您的余額已不足!");
}
}
}
void xiugai(){
system("cls");
printf("\n\n\t\t 現(xiàn)在進(jìn)行的是修改密碼功能\n");
char oldpassword[7];
char newpassword[7];
char newpassword1[7];
int i;
for(i=0;i3;i++){
printf("\n\t\t\t 請(qǐng)輸入舊密碼:\n");
inputpassword(oldpassword);
if(strcmp(oldpassword,one.password)==0){
printf("\n\t\t\t 輸入成功!\n");
break;
}else{
printf("\n\t\t\t 密碼輸入有誤,請(qǐng)重新輸入!\n");
}
}
if(i3){
while(1){
printf("\n\t\t\t 請(qǐng)輸入您的新密碼:\n");
inputpassword(newpassword);
printf("\n\t\t\t 請(qǐng)輸入您的確認(rèn)密碼:\n ");
inputpassword(newpassword1);
if(strcmp(newpassword,newpassword1)==0){
strcpy(one.password,newpassword);
fseek(fp,-sizeof(one),1);
fwrite(one,sizeof(one),1,fp);
printf("\n\t\t\t 密碼修改成功!");
break;
}else{
printf("\n\t\t\t 兩次密碼輸入不一致!");
}
}
}else{
printf("\n\t\t\t 密碼輸入錯(cuò)誤!");
}
}
int zhuxiaozhanghao()
{
system("cls");
int zhuxiaoxitong;
char sf;
printf("你要注銷的賬號(hào)是%d",one.account);
printf("你是否要對(duì)此賬號(hào)進(jìn)行注銷?\n\n\t\t請(qǐng)您選擇:注銷(Y)or不注銷(N):");
fflush(stdin);
scanf("%c",sf);
if(sf=='y'||sf=='Y')
{
printf("正在為您注銷!\n",one.account);
zhuxiaoxitong=1;
}else{
printf("不注銷系統(tǒng)!\n",one.account);
}
return zhuxiaoxitong;
}
void service()
{
while(1){
system("cls");
printf("\n\n\n\t\t\t\t\t\t現(xiàn)在是服務(wù)系統(tǒng),本系統(tǒng)有以下服務(wù)");
printf("\n\t\t\t\t\t\t[a] 查詢余額\n");
printf("\n\t\t\t\t\t\t[b] 存款服務(wù)\n");
printf("\n\t\t\t\t\t\t[c] 轉(zhuǎn)賬服務(wù)\n");
printf("\n\t\t\t\t\t\t[d] 取款服務(wù)\n");
printf("\n\t\t\t\t\t\t[e] 修改密碼\n");
printf("\n\t\t\t\t\t\t[f] 注銷 \n");
printf("\n\t\t\t\t\t\t[g] 退出系統(tǒng)\n");
char e;
printf("\n\t\t\t\t\t\t您要選擇的服務(wù)是:");
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("\n\n\n\t\t\t\t按任意鍵繼續(xù)......\n");
getch();
}
}
void login()
{
fp=fopen("atm.txt","rb+");
if(fp==NULL)
{
printf("\n\n\n\t\t\t\t文件打開失敗!");
return;
}
system("cls");
printf("\n\t\t\t\t\t\t現(xiàn)在執(zhí)行的是登錄函數(shù)的使用\n");
int zhanghao;
printf("\n\t\t\t\t\t\t請(qǐng)輸入賬號(hào):");
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("\n\t\t\t\t\t\t請(qǐng)輸入密碼:");
fflush(stdin);
inputpassword(password2);
if(strcmp(password2,one.password)==0)
{
printf("\n\t\t\t\t\t\t登陸成功!");
service();
break;
}else{
printf("密碼不正確!");
}
}
if(h==3){
printf("\n\t\t\t您的密碼三次輸入有誤,返回");
}
}else{
printf("無此賬號(hào)!");
}
fclose(fp);
}
void quite()
{
system("cls");
printf("\t\t\t現(xiàn)在執(zhí)行的是退出函數(shù)的使用\n");
exit(0);
}
文章名稱:c語言atm機(jī)登錄函數(shù) c語言atm機(jī)輸入密碼c語言
文章來源:http://fisionsoft.com.cn/article/dojsico.html