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;
}