atm機編程
Java編寫的模擬ATM取款機程序/*** @version 1.0
* @author Devil_Angel
* 該程序的功能為實現模擬銀行ATM自動取款機提款,查詢等功能.
*
*/import java.io.*;/*該類為實現客戶信息及部分功能*/
class Account {
private String code =null; //信用卡號
private String name =null; //客戶姓名
private String password=null; //客戶密碼
private double money =0.0; //卡里金額
/********************/
public Account(String code,String name,String password,double money)
{
this.code=code;
this.name=name;
this.password=password;
this.money=money;
}
protected String get_Code() {
return code;
}
protected String get_Name() {
return name;
}
protected String get_Password() {
return password;
}
public double get_Money() {
return money;
}
/*得到剩餘的錢的數目*/
protected void set_Balance(double mon) {
money -= mon;
}
}/**********實現具體取款機功能*********/
class ATM {
Account act;
// private String name;
// private String pwd;
public ATM() {
act=new Account("000000","Devil","123456",50000);
}
/***********歡迎界面***********/
protected void Welcome()
{
String str="---------------------------------";
System.out.print(str+"\n"+
"歡迎使用Angel模擬自動取款機程序.\n"+str+"\n");
System.out.print(" 1.>取款."+"\n"+
" 2.>查詢信息."+"\n"+
" 3.>密碼設置."+"\n"+
" 4.>退出系統."+"\n");
}
/**********登陸系統**********/
protected void Load_Sys() throws Exception
{
String card,pwd;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入您的信用卡號:");
card=br.readLine();
System.out.println("請輸入您的密碼:");
pwd=br.readLine();
if(!isRight(card,pwd))
{
System.out.println("您的卡號或密碼輸入有誤.");
counter++;
}
else
SysOpter();
}while(counter<3);
Lock_Sys();
}
/**********系統操作**********/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("請選擇您要操作的項目(1-4):");
num=br.read(); //num為ASICC碼轉換的整數
switch(num) {
case 49: BetBalance(); break;
case 50: Inqu_Info(); break;
case 51: Set_Password(); break;
case 52: Exit_Sys(); break;
}
System.exit(1);
}
/**********信息查詢**********/
protected void Inqu_Info() {
System.out.print("---------------------\n"+
act.get_Code()+"\n"+
act.get_Name()+"\n"+
act.get_Money()+"\n"+
"-----------------------");
}
/**********取款**********/
public void BetBalance() throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入您要取的數目:");
str=br.readLine();
str1=String.valueOf(act.get_Money());
if(str.compareTo(str1)>0) {
System.out.println("超過已有的錢數,請重新輸入您要取的數目:");
}
else {
/*操作成功*/
// act.set_Balance(str);
System.out.println("取款成功,請收好您的錢.");
Welcome();
SysOpter();
}
}while(true);
}
/**********判斷卡內是否有錢**********/
protected boolean isBalance() {
if(act.get_Money()<0) {
// System.out.println("對不起,您的錢數不夠或卡已透支.");
return false;
}
return true;
}
/********卡號密碼是否正確******/
protected boolean isRight(String card,String pwd)
{
if(act.get_Code().equals(card) && act.get_Password().equals(pwd))
return true;
else
return false;
}
/**********密碼修改**********/
protected void Set_Password() throws Exception
{
String pwd=null;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("請輸入舊密碼:");
pwd=br.readLine();
if(act.get_Password().equals(pwd))
{
do {
System.out.println("請輸入新密碼:");
String pwd1=br.readLine();
System.out.println("請再次輸入新密碼:");
String pwd2=br.readLine();
if(!pwd1.equals(pwd2))
{
System.out.println("兩次輸入不一致,請再次輸入.");
}
else
{
System.out.println("密碼修改成功,請使用新密碼.");
Welcome();
SysOpter();
}
}while(true);
}
}while(counter>3);
}
/**********鎖定機器**********/
protected void Lock_Sys() {
System.out.println("對不起,您的操作有誤,卡已被沒收.");
System.exit(1);
}
/**********結束系統**********/
protected void Exit_Sys() {
System.out.println("感謝您使用本系統,歡迎下次在來,再見!");
System.exit(1);
}
}public class Text
{
public static void main(String[] args) throws Exception
{
ATM atm=new ATM();
atm.Welcome();
atm.Load_Sys();
// atm.Exit_Sys();
}
} //模擬ATM取款機工作流程 import java.util.Scanner;public class Atm {
public Atm() {
}
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int password = 0;
int count = 0;
int choice = 0;
int type = 0;
int input = 0;
int acount = 1000;
boolean exit = false;
int flag = 0;
do{
System.out.println("請輸入您的密碼:");
password = sc.nextInt();
count++;
}while(password != 12345 && count<3);
if(password == 12345){
//密碼正確繼續後面的操作。
do{
System.out.println("請選擇您的操作,1.查詢 2.取款");
choice = sc.nextInt();
switch(choice){
case 1:
do{
System.out.println("請選擇帳戶類型:1. 美元 2. 人民幣");
type = sc.nextInt();
if(type == 1){
System.out.println("You have $"+acount+"!");
}else if(type == 2){
System.out.println("您有"+acount+"圓!");
}else{
System.out.println("類型選擇錯誤,請重新選擇!");
}
System.out.println("1.繼續 2.離開");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}while(type!=1 && type!=2);
break;
case 2: do{
System.out.println("請選擇帳戶類型:1. 美元 2. 人民幣");
if(type == 1){
System.out.println("Please input number of your money!");
input = sc.nextInt();
if(input > acount){
System.out.println("You have not enough money!");
}else{
System.out.println("You take care of your money!");
}
System.out.println("1.continue 2.exit");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else if(type == 2){
System.out.println("請輸入您要取的金額!");
input = sc.nextInt();
if(input > acount){
System.out.println("您的余額不足!");
}else{
System.out.println("請妥善保管您的錢!");
acount = acount - input;
}
System.out.println("1.繼續 2.離開");
flag = sc.nextInt();
if(flag == 1){
exit = false;
}else{
exit = true;
}
}else{
System.out.println("類型選擇錯誤,請重新選擇!");
}
}while(type!=1 && type!=2);
break;
default: System.out.println("類型選擇錯誤,請重新選擇!");
}
}while(choice!=1 && choice!=2 || exit == false);
}else{
//密碼錯誤,退出。
System.out.println("三次密碼錯誤,吞卡!");
}
}
}
B. 用c語言模擬ATM機工作流程編程
#include
"stdio.h"對ATM機器的模擬就是一個對隊列的模擬下面代碼在VC6環境下調試已經通過了其中有個缺陷就是因為代碼執行速度過快導致二次執行根據時間隨機出來的數字都是一樣的因此你可以自己加上一個延遲子程序部分功能已經注釋了#include
"stdlib.h"#include
"time.h"#define
OK
1#define
ERROR
0
typedef
struct
node{
int
number;
struct
node*
next;}*Lnode;
typedef
struct
list{
node
*head,*rear;}*Plist;
//模擬
ATM開業bool
ListInit(Plist
list){
Lnode
p;
p
=
(Lnode)malloc(sizeof(Lnode));
list->head
=
p;
list->rear
=
list->head;
list->head->next
=
NULL;
if(list->head!=NULL)
return
ERROR;
else
return
OK;}
//模擬
有客戶排隊bool
ListInsert(Plist
list,int
number){
Lnode
p;
p
=
(Lnode)malloc(sizeof(Lnode));
if(p==NULL)
return
ERROR;
else
{
p->number
=
number;
p->next
=
NULL;
list->rear->next
=
p;
list->rear
=
p;
return
OK;
}}
//模擬
客戶辦完事離開bool
ListDelete(Plist
list){
Lnode
p;
if(list->head
==list->rear)
return
ERROR;
else
{
p
=
list->head->next;
list->head->next
=
p->next;
list->rear
=
list->head;
//
free(p);
return
OK;
}}
void
sand(int*
gettime,int*
needtime){
srand(time(NULL))
;
*gettime
=
rand()%100;
srand(time(NULL))
;
*needtime
=rand()%100;}
//模擬客戶到達事件void
CustomerArrived(Plist
list,int
gettime,int
needtime,int
kehu,int
time){
int
nextgettime,nextneedtime;
sand(&nextgettime,&nextneedtime);
while(needtime>0
&&
nextgettime>0
&&
time>0)
{
needtime
--;
nextgettime
--;
time
--;
}
if(nextgettime
==
0
&&
needtime>0
&&time>0)
{
kehu++;
ListInsert(list,kehu);
while(needtime>0
&&
time>0)
{
needtime--;
time
--;
}
ListDelete(list);
CustomerArrived(list,nextgettime,nextneedtime,kehu,time);
}
if(needtime
==0
&&
nextgettime>0
&&
time>0)
{
ListDelete(list);
while(nextgettime>0
&&
time>0)
{
nextgettime--;
time
--;
}
kehu++;
ListInsert(list,kehu);
//未刪除
,list未傳遞進去
CustomerArrived(list,nextgettime,nextneedtime,kehu,time);
}
if(time
==0)
{
printf("ATM關門,請明天在來!\n");
return;
}}
main(){
list
list;
int
i
=
10000;
//ATM機器每天工作時間
int
kehu
=
0;
//客戶標號
int
gettime,needtime;
ListInit(&list);
//ATM開業
sand(&gettime,&needtime);
ListInsert(&list,kehu);
CustomerArrived(&list,gettime,needtime,kehu,i);
getchar();
}
C. 用C語言模擬ATM機工作流程編程
#include "stdio.h"對ATM機器的模擬就是一個對隊列的模擬下面代碼在VC6環境下調試已經通過了其中有個缺陷就是因為代碼執行速度過快導致二次執行根據時間隨機出來的數字都是一樣的因此你可以自己加上一個延遲子程序部分功能已經注釋了#include "stdlib.h"#include "time.h"#define OK 1#define ERROR 0 typedef struct node{ int number; struct node* next;}*Lnode; typedef struct list{ node *head,*rear;}*Plist; //模擬 ATM開業bool ListInit(Plist list){ Lnode p; p = (Lnode)malloc(sizeof(Lnode)); list->head = p; list->rear = list->head; list->head->next = NULL; if(list->head!=NULL) return ERROR; else return OK;} //模擬 有客戶排隊bool ListInsert(Plist list,int number){ Lnode p; p = (Lnode)malloc(sizeof(Lnode)); if(p==NULL) return ERROR; else { p->number = number; p->next = NULL; list->rear->next = p; list->rear = p; return OK; }} //模擬 客戶辦完事離開bool ListDelete(Plist list){ Lnode p; if(list->head ==list->rear) return ERROR; else { p = list->head->next; list->head->next = p->next; list->rear = list->head; // free(p); return OK; }} void sand(int* gettime,int* needtime){ srand(time(NULL)) ; *gettime = rand()%100; srand(time(NULL)) ; *needtime =rand()%100;} //模擬客戶到達事件void CustomerArrived(Plist list,int gettime,int needtime,int kehu,int time){ int nextgettime,nextneedtime; sand(&nextgettime,&nextneedtime); while(needtime>0 && nextgettime>0 && time>0) { needtime --; nextgettime --; time --; } if(nextgettime == 0 && needtime>0 &&time>0) { kehu++; ListInsert(list,kehu); while(needtime>0 && time>0) { needtime--; time --; } ListDelete(list); CustomerArrived(list,nextgettime,nextneedtime,kehu,time); } if(needtime ==0 && nextgettime>0 && time>0) { ListDelete(list); while(nextgettime>0 && time>0) { nextgettime--; time --; } kehu++; ListInsert(list,kehu); //未刪除 ,list未傳遞進去 CustomerArrived(list,nextgettime,nextneedtime,kehu,time); } if(time ==0) { printf("ATM關門,請明天在來!\n"); return; }} main(){ list list; int i = 10000; //ATM機器每天工作時間 int kehu = 0; //客戶標號 int gettime,needtime; ListInit(&list); //ATM開業 sand(&gettime,&needtime); ListInsert(&list,kehu); CustomerArrived(&list,gettime,needtime,kehu,i); getchar(); }
D. C語言編程,模擬銀行的ATM機
我也是初學者,剛做完這個。
輸入密碼能進入的功能你可以先建立個整型的數,然後你輸入的整型數字跟你之前建立好的數字進行比較,如果一致就執行下一步,如果不一致就輸入密碼錯誤,用if語句
取款,存款的更簡單了,加減法而已。
這個東西最後建立一個文件保存你輸入的數據,就是賬戶名,密碼什麼的,需要用的時候從文件里讀取,然後和你輸入的數據進行比較。
存取款的可以把文件里的數據進行讀取,然後進行相應的加減,然後用修改後的數據用「w」寫入文件,「w」有覆蓋功能以前的數據就會被覆蓋了
E. 怎麼用C語言編寫模擬ATM機
你可以加一個ini文件處理,就是每次開始程序是都到ini 或者 txr 文件中讀取你那個密碼 ,在更改時寫入你更改的密碼到ini 或者 txt 文件中 ,ini的編程很簡單 你上網查一下就明白了
F. c語言編程,幫忙編一個ATM取款機的程序,200分
學習C++有一段時間了,前兩天有個朋友要我幫她做個模擬ATM自動取款機的程序,於是花了一個晚上寫了出來,其實這個程序也很簡單,但是我覺得它對於剛學c++的人來說比較有用處,因為它可以幫助你更加深刻的理解面向對象程序設計的真諦-------以現實世界為模型編寫程序。學習c++的真正目的也就在於此,真正的理解面向對象程序設計!
// ************************************
// * *
// * function.h *
// * *
// ************************************
#include<iostream.h>
class consumer;
class ATM
// ATM取款機
{
public:
ATM(consumer& cn):cnsm(cn)
{
}
void welcome();
// 登陸界面
bool check_passwd(char n[],char pwd[]);
// 核對密碼
void change_passwd();
// 修改密碼
void fetchmoney();
// 取款
void information();
// 查詢信息
void exitATM();
// 退出系統
void functionshow();
// 功能界面
void lock();
// 鎖機
private:
int times;
// 記錄密碼輸入次數
consumer& cnsm;
};
class consumer
// 用戶
{
public:
friend class ATM;
consumer(char Name[],char Num[],
float Money,char PassWord[]);
protected:
char* get_name();
// 取得姓名
char* get_num();
// 取得卡號
char* get_passwd();
// 取得密碼
float get_money();
// 取得余額
void set_passwd(char pwd[]);
// 設置密碼
void set_money(float m);
// 取錢
private:
char passwd[8];
// 用戶密碼
char name[20];
// 用戶姓名
char num[20];
float money;
};
// ************************************
// * *
// * consumer類的成員函數 *
// * *
// ************************************
#include"function.h"
#include<string.h>
consumer::consumer(char Name[],
char Num[],float Money,char Password[])
{
strcpy(name,Name);
strcpy(num,Num);
money=Money;
strcpy(passwd,Password);
}
float consumer::get_money()
{
return money;
}
char* consumer::get_name()
{
return name;
}
char* consumer::get_num()
{
return num;
}
char* consumer::get_passwd()
{
return passwd;
}
void consumer::set_money(float m)
{
money-=m;
}
void consumer::set_passwd(char pwd[])
{
strcpy(passwd,pwd);
}
G. 怎樣用c語言編寫ATM系統
#include<stdio.h>
#include<string.h>
void print_welcome();
int main()
{
print_welcome();
char c[11]="1234567890",d[7]="123456";
char a[20],b[20];
char p,q;
int h=0,i=0,j=0,k,l=0;
do
{
printf("請輸入賬號:\n");
gets(a);
printf("請輸入密碼:\n");
gets(b);
if(strcmp(c,a)==0&&strcmp(d,b)==0)
{
printf("賬號正確 歡迎使用\n");
h++;
}
else
printf("賬號或密碼錯誤請重新輸入\n");
}while(h!=1);
do
{
print_welcome();
retrn:
printf("請選擇對應的字母\n");
printf(" a存款業務 \n");
printf(" b余額查詢\n");
printf(" c資金轉賬\n");
printf(" d取款業務\n");
printf(" e退卡\n");
printf("請選擇您要辦理的業務\n");
scanf("%c",&p);
getchar();
switch(p)
{
case'a':printf(" 存款業務\n");
printf("**本服務暫停 請重新選擇**\n");
break;
case'b':
printf(" 余額查詢\n");
printf("**您的余額為 ¥9999999\n請重新選擇**\n");
break;
case'c':
printf(" 資金轉賬\n");
printf("**您的銀行卡不支持該業務 請重新選擇**\n");
break;
case'd':
printf(" 取款業務\n");
do
{
printf("請選擇您要取款的金額\n**請輸入序號\n**請您注意每位用戶每天只能去20000 每次最多取2500\n");
printf(" r 100\n");
printf(" s 200\n");
printf(" t 500\n");
printf(" u 1000\n");
printf(" v 2000\n");
printf(" w 其他\n");
printf(" x 返回\n");
printf("請選擇要取的金額\n");
scanf("%c",&q);
getchar();
switch(q)
{
case'r':printf("**取款成功 金額為100元**");goto retrn;break;
case's':printf("**取款成功 金額為200元**");goto retrn;break;
case't':printf("**取款成功 金額為500元**");goto retrn;break;
case'u':printf("**取款成功 金額為1000元**");goto retrn;break;
case'v':printf("**取款成功 金額為2000元**");goto retrn;break;
case'w':printf("**請輸入你想取出的金額**\n**並保證是100的倍數\n");
while(l!=1)
{
scanf("%d",&k);
getchar();
if(k%100==0&&k>=0&&k<=2500)
{
printf("您取出的金額%d元\n",k);
l++;
goto retrn;
}
else
{
printf("您輸入的面額有誤請重新輸入\n");
printf("請您保證為100的倍數\n");
}
}
break;
case'x':goto retrn;break;
default:printf("**操作有誤請從新輸入**");
j++;
}
}while(j!=1);
break;
case'e':
printf("**歡迎您的使用 請勿忘取卡**\n");
i++;
break;
default:printf("**操作有誤請從新輸入**\n");
}
}while(i!=1);
print_welcome();
return 0;
}
void print_welcome()
{
printf(" **歡迎使用**\n");
}
H. 編程模仿銀行ATM自動取款機功能,要求能實現以下功能:
FOXBASE倒可以編,C編有點難
I. 用C語言模擬ATM機工作流程編程
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
//面值
const int mian[6]={100,50,20,10,5,1};
//密碼嘗試輸入次數
int try=5;
//正確密碼
const char password[]="2017817";
char inputpw[64]={'\0'};
//取款金額
int jine;
int i,zhsh;
do
{
printf("請輸入密碼:");
gets(inputpw);
try--;
if(!strcmp(password,inputpw))
{
break;
}
else if(try>0)
{
printf("密碼錯誤。你還有%d次機會,請重新輸入。\n",try);
}
else
{
printf("密碼不對,無法為你提供服務,請按任意鍵退出。\n");
system("PAUSE");
exit(0);
}
}while(try>0);
printf("請輸入取款金額:");
scanf("%d",&jine);
printf("請取款:");
for(i=0;i<6;i++)
{
zhsh=jine/mian[i];
jine-=zhsh*mian[i];
if(zhsh>0)
{
printf("%d元%d張 ",mian[i],zhsh);
}
}
printf("\n本次服務結束,謝謝你的使用。\n");
return 0;
}