㈠ 在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]='