㈠ 在c语言中ATM自动取款机的功能程序怎么写啊
#include<stdio.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;
}
}
}
几个小错误而已...比如忘了写双撇号,switch写错了...还有!= 忘了写! 等等.. 以上程序可以运行了
㈡ 用c语言编写ATM自动取款机 不要c++的
既然是银行类,那么C++也可以吧。
今天写了一个,时间少,写的比较粗糙,但基本功能都有。
写了一个Account(帐户)类,实现创建帐户,对存款进行操作,保存帐户和打开帐户等。
Account类的头文件
//Account.h
#ifndef ACCOUNT_H_
#define ACCOUNT_H_
#include <string>
using std::string;
class Account
{
private:
string name; //帐户名
string password; //密码
int deposit; //存款
bool modify; //帐户是否被修改
public:
Account();
Account(string na, string psw, int dps);
~Account();
bool openAccount(string accName); //从文件打开帐户
bool saveAccount(); //将帐户保存到文件
bool land(string psw); //帐户登录
bool saving(int money); //存款
bool fetch(int money); //取款
void showBalance(); //显示余额
};
#endif
Account类的实现,在Account.cpp文件中
//Account.cpp
#include <iostream>
#include <fstream>
#include <string>
#include "Account.h"
using namespace std;
Account::Account()
{
name = "";
password = "";
deposit = 0;
}
Account::Account(string na, string psw, int dps)
{
name = na;
password = psw;
deposit = dps;
}
Account::~Account()
{
}
bool Account::openAccount(string accName)
{
ifstream fin(accName.c_str(), ios_base::in);
if(!fin.is_open())
{
std::cout<<"打开帐户错误,请检查是否有该帐户!"<<std::endl;
return false;
}
fin>>name;
fin>>password;
fin>>deposit;
fin.close();
return true;
}
bool Account::saveAccount()
{
if(modify == false)
return true;
ofstream fout;
fout.open(name.c_str(), ios_base::out);
if(!fout.is_open())
{
std::cout<<"保存帐户错误,不能创建文件!"<<std::endl;
return false;
}
if(name=="")
{
std::cout<<"帐户为空,不能保存!"<<std::endl;
return false;
}
fout<<name<<std::endl;
fout<<password<<std::endl;
fout<<deposit<<std::endl;
fout.close();
return true;
}
bool Account::land(string psw)
{
if(psw == password)
return true;
else
return false;
}
bool Account::saving(int money)
{
if(money<=0)
{
std::cout<<"错误!存入款额不能小于等于0!"<<std::endl;
return false;
}
deposit += money;
modify = true;
return true;
}
bool Account::fetch(int money)
{
if(money<=0)
{
std::cout<<"错误!取出款额不能小于等于0!"<<std::endl;
return false;
}
else if(money<=deposit)
{
deposit -= money;
modify = true;
return true;
}
else if((money - deposit)<=2000)
{
deposit -= money;
std::cout<<"您的帐户已透支,透支额为:"<<-deposit<<"元"<<std::endl;
modify = true;
return true;
}
else
{
std::cout<<"错误!取款超过允许透支额!"<<std::endl;
return false;
}
}
void Account::showBalance()
{
std::cout<<"您目前的帐户存款余额为 "<<deposit<<" 元"<<std::endl;
}
说明:
bool saveAccount()以帐户名为文件名,以文本格式,保存帐户名、密码、存款信息,保存的文件没有扩展名,但可以用记事本打开。
至于主程序文件,由于网络限制,不能贴出来,我用网络的消息发送给你。
㈢ 用C语言编写一个自动存取款机模拟
给你个加强版:include<iostream.h>
#include<stdlib.h>
#include<string.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;
cin>>b.name;
cout<<"请输入您的卡号:"<<endl;
cin>>b.num;
cout<<"请输入您的密码:"<<endl;
cin>>b.password;
cout<<endl;
}
void error()
{
cout<<"您的输入错误,请再输入一遍!"<<endl;
}
void cout1()
{
cout<<"您的名字是:"<<b.name<<endl<<"您的卡号是:"<<b.num<<endl<<"您的密码是:"<<b.password<<endl;
}
void one()
{
cout<<"请按‘1’存钱, 请按‘2’取钱!"<<endl<<"请按‘3’查钱, 请按‘4’退出!" <<endl;
}
void tishi()
{
char c;
cout<<"如果您想退出,请按 'Y' . 否则,请按'N' !";
cin>>c;
if(c=='y'||c=='Y') tuichu();
if(c=='n'||c=='Y') fuction();
else
{
error();
tishi();
};
}
void yue()
{
cout<<"您的余额为:"<<b.money<<endl;
tishi();
}
void cunqian()
{
b.o=b.money;
cout<<"您想存多少钱?"<<endl;
cin>>b.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;
cin>>d;
if((d<999999999)&&(d>=0)&&(d<=b.money+2000))
{
b.money-=d;
yue();
}
else
{
cout<<"您的透支余额超过2000元,操作失败!"<<endl;
quqian();
}
}
void chaqian()
{
yue();
}
void tuichu()
{
cout<<endl<<"欢迎下次光临欢迎进入C++工商银行!!"<<endl;
cout<<"请取回您的卡,再次感谢!"<<endl;
exit(0);
}
void fuction()
{
char x;
{
one();
cin>>x;
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;
cin>>q.num;
cout<<"请输入您的密码:"<<endl;
cin>>q.password;
cout<<endl;
}
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==0&&f==0) fuction();
else {
cout<<"您的信息有误,请重新输入:"<<endl;
cin2();
e=strcmp(q.num,b.num);
f=strcmp(q.password,b.password);
if (e==0&&f==0) fuction();
else
{
cout<<"您的信息有误,请重新输入:"<<endl;
cin2();
e=strcmp(q.num,b.num);
f=strcmp(q.password,b.password);
if(e==0&&f==0) fuction();
else {
cout<<"您的信息有误,请重新输入:"<<endl;
tuichu();
}
}
}
}
void main()
{
cout2();
}
㈣ 有谁学过C语言的可以帮我设计一个模拟ATM自动取款机的程序吗不用太复杂,谢谢。
/*初始密码和账号都为:123456*/
#include<stdio.h>
intchaxun(inta3)
{
intb;
b=a3;
printf("你的余额为:%d ",b);
}
intqukuan(inta3)
{
inta,b;
printf("请输入您要提取的现金: ");
scanf("%d",&a);
b=a3-a;
if(b<0)
printf("对不起,你的余额不足 ");
else
{
printf("请收好您的%d元现金 ",a);
a3=a3-a;
}
return(a3);
}
intgaini(inta2)
{
inta,b,c=1,d,e=1;
while(e)
{
printf("请输入你的旧密码: ");
scanf("%d",&d);
if(d==a2)
e=0;
else
{
e=1;
printf("你输入的密码错误,请重新输入: ");
}
}
while(c)
{
printf("请输入您的六位数新密码 ");
scanf("%d",&a2);
printf("请确认您的六位数新密码 ");
scanf("%d",&b);
if(a2==b)
{
if(b>100000&&b<999999&&b/(b/100000)!=111111)
{
c=0;
printf("密码修改成功 ");
}
else
{
printf("您输入的密码不符合要求,请从新输入 ");
c=1;
}
}
else
{
c=1;
printf("您两次输入的密码不一致,请重新输入: ");
}
}
returna2;
}
intquka()
{
printf(" 梦若保保提醒您 ");
printf("请收好您的卡片,谢谢,再见 ");
}
intcunkuan(inta3)
{
inti,j,k;
printf("请输入你要存的金额 ");
scanf("%d",&k);
if(k<0)
{
printf("对不起,没有负存款 ");
}
else
{
printf(" 您好,您已经存进去了%d元 ",k);
a3=a3+k;
}
returna3;
}
main()
{
inti,j,b=1,c,k,l,m,n;
inta1=123456,a2=123456,a3=1000;
printf("欢迎使用自动柜员机: ");
while(b==1)
{
printf("请输入您的账号: ");
scanf("%d",&k);
printf("请输入您的密码: ");
scanf("%d",&l);
if(k==a1&&l==a2)
{
b=0;
printf("您的账户余额为:%d ",a3);
}
else
{
b=1;
printf("对不起,您输入的账号或者密码有误,请重新输入: ");
}
}
do
{
printf(" 请选择您要的服务项目: ");
printf("1.查询余额 ");
printf("2.取款 ");
printf("3.修改密码 ");
printf("4.取卡 ");
printf("5.存款 ");
scanf("%d",&c);
switch(c)
{
case1:
chaxun(a3);
break;
case2:
a3=qukuan(a3);
break;
case3:
a2=gaini(a2);
break;
case4:
quka();
break;
case5:
a3=cunkuan(a3);
break;
}
}while(c!=4);
}
完全符合你的要求啦,请插入磁卡…^_^
哈哈,不然你自己写一个算法吧。其实想纠正一下,这个程序代码是上弦的芭蕉也就是楼主他写的,他写好后给我而我呢仅仅是做了一下辅助修改,其实要我写呢,我自己应该写不出来,你如果有其他的问题还是通过回答楼主问题的方式来问一下楼主吧,就是上弦的芭蕉这家伙,悄悄的告诉你:他代码程序真的很强,我只是打了一下酱油、酱紫而已;而如果您要引用呢,也先问一下源代码主人楼主他的意思先哈^_^
㈤ C++编写ATM自动取款机的模拟
lassconsumer;
classATM//ATM取款机
{
public:
ATM(consumer&cn):cnsm(cn){}
voidwelcome();//登陆界面
boolcheck_passwd(charn[],charpwd[]);//核对密码
voidchange_passwd();//修改密码
voidfetchmoney();//取款
voidinformation();//查询信息
voidexitATM();//退出系统
voidfunctionshow();//功能界面
voidlock();//锁机
private:
inttimes;//记录密码输入次数
consumer&cnsm;
};
classconsumer//用户
{
public:
friendclassATM;
consumer(charName[],charNum[],floatMoney,charPassword[]);
protected:
char*get_name();//取得姓名
char*get_num();//取得卡号
char*get_passwd();//取得密码
floatget_money();//取得余额
voidset_passwd(charpwd[]);//设置密码
voidset_money(floatm);//取钱
private:
charpasswd[8];//用户密码
charname[20];//用户姓名
charnum[20];
floatmoney;
};
//************************************
//**
//*consumer类的成员函数*
//**
//************************************
#include"function.h"
#include
consumer::consumer(charName[],charNum[],floatMoney,charPassword[])
{
strcpy(name,Name);
strcpy(num,Num);
money=Money;
strcpy(passwd,Password);
}
floatconsumer::get_money()
{
returnmoney;
}
char*consumer::get_name()
{
returnname;
}
char*consumer::get_num()
{
returnnum;
}
char*consumer::get_passwd()
{
returnpasswd;
}
voidconsumer::set_money(floatm)
{
money-=m;
}
voidconsumer::set_passwd(charpwd[])
{
strcpy(passwd,pwd);
}
//************************************
//**
//*ATM类的成员函数*
//**
//************************************
#include"function.h"
#include
#include
voidATM::welcome()
{
times=0;
cout<<"$欢迎使用若雪银行ATM自动取款机!~!"<<P>
charpwd[8],num[20],ch;
inti=0;
do
{
i=0;
cout<<"请输入卡号:";
do
{
cin.get(ch);
num[i++]=ch;
}while(ch!=' ');
num[i-1]='