基本信息
源码名称:ATM(C++)取款/查询余额 入门级示例源码
源码大小:6.79KB
文件格式:.cpp
开发语言:C/C++
更新时间:2018-05-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
#include<iostream> using namespace std; #include<string> #include<stdlib.h> #define OK 1 #define ture 1 //class User;//定义全局类class typedef int Status; //--------User的存储结构的定义-------------------------- typedef struct { string ID; string key; double money; }User; //------User的操作函数实现----------------- void set_user(User &U) { cout<<"请初始化ID、key、money(账号、密码、初始金额)"<<endl; cin>>U.ID>>U.key>>U.money; } double get_money(User U) //获取余额函数 { return (U.money); } string get_ID(User U) //获取卡号 { return (U.ID); } string get_key(User U) //获取密码 { return (U.key); } Status revise_money(User &U,double Money) { U.money-=Money; return OK; } Status revise_key(User &U,string Key) { U.key=Key; return OK; } //------------ATM类--------------- class ATM { private: bool j; int time; User customer; public: ATM(string id,string Key,double Money) { j=ture; customer.ID=id; customer.key=Key; customer.money=Money; } void login(); //登陆界面 bool check_customer(string id,string Key); //核对用户信息 bool signlost(); //挂失 // bool check_deal_id(string id); //核对转入账号 void withdrawals(); //取款 void transfermoney(); //转账 Status query(); //查询 Status change_key(); //更改密码 void function(); //功能界面 void lockcard(); //锁卡 void quit(); //退出 }; //---------------ATM类的成员函数的实现------------- bool ATM::signlost() { char a; do { cout<<"是否确认挂失:(y/n) 继续请按y 退出请按n "<<endl; cin>>a; if(a=='y') { cout<<"您已挂失成功!"<<endl; exit(2); } else { cout<<"您已选择退出!"<<endl; function(); } } while(a=='y'); return (j=ture); } void ATM::transfermoney() { string id; double num; cout<<"请输入所转账号:"<<endl; cin>>id; cout<<"请输入所转钱数:"<<endl; cin>>num; if(customer.money>num) { customer.money-=num; cout<<"转账成功!"<<endl; cout<<"您的余额为:"<<customer.money<<endl; } else cout<<"余额不足!"<<endl; function(); } void ATM::login()//登陆界面 { time=0; string id; string Key; int i=0; do { cout<<" ◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇"<<endl; cout<<" ◆欢迎使用安阳师院计科班银行!◆"<<endl; cout<<" ◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇"<<endl<<endl; cout<<" 测试卡号为:123456"<<endl; cout<<" 测试密码为:123456"<<endl; cout<<" 测试卡号余额为:10000元"<<endl<<endl<<endl; cout<<" 请输入您的卡号 "<<endl; cout<<"卡号:"; cin>>id; cout<<endl<<" 请输入您的密码 "<<endl; cout<<"密码:"; cin>>Key; if(!check_customer(id,Key)) { cout<<"对不起,您的卡号或密码有误,请重新输入"<<endl; time ; } else { function(); } } while(time<3); lockcard(); } bool ATM::check_customer(string id,string Key) { if(customer.ID==id&&customer.key==Key) return true; else return false; } void ATM::function() { int n; cout<<endl<<endl<<endl; cout<<"★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆"<<endl; cout<<"☆请输入你想操作的序号: ★"<<endl; cout<<"★ 1)取款 ☆"<<endl; cout<<"☆ 2)查询余额 ★"<<endl; cout<<"★ 3)更改密码 ☆"<<endl; cout<<"☆ 4)挂失 ★"<<endl; cout<<"★ 5)转账 ☆"<<endl; cout<<"☆ 6)退出系统 ★"<<endl; cout<<"★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆"<<endl; cin>>n; if(n<0||n>6) { cout<<"您输入的序号不正确,请重新输入:"; cin>>n; } switch(n) { case 1:withdrawals();break; case 2:query();break; case 3:change_key();break; case 4:signlost();break; case 5:transfermoney();break; case 6:quit();break; } while(true); } void ATM::withdrawals() { double m; //m,money char ch; do { cout<<endl<<"输入您要取多少钱: "<<endl; cin>>m; while(m<=0) { cout<<"请输入正确的取款数:(100的倍数、每次最多2000元) "<<endl; cin>>m; } if(customer.money-m<0) { cout<<"对不起,您的余额不足!"<<endl; } else { if((int)m%100!=0) { cout<<"对不起,您的取款金额必须为100的倍数!"<<endl; } else { if(m>2000) { cout<<"对不起,您每次只能取2000元!"<<endl; } else { cout<<"操作成功,请稍后!!!"<<endl; revise_money(customer,m); } } } cout<<"请输入(y/n)确认是否取钱!"<<endl; cin>>ch; cout<<"您已取款成功!请收好钱!"; function(); while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n') { cin>>ch; } } while(ch=='y'||ch=='Y'); } Status ATM::query() { cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; cout<<" "<<endl; cout<<" 卡号:"<<get_ID(customer)<<endl; cout<<" 余额:"<<get_money(customer)<<"元"<<endl; cout<<" "<<endl; cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; function(); return OK; } int ATM::change_key() { string Key; string key1,key2; time=0; do { cout<<"请输入旧密码:"; cin>>Key; if(!check_customer(customer.ID,Key)) time ; else break; } while(time<3); if(time==3) lockcard(); int t=1; while (t==1) { cout<<"请输入新密码并牢记好新密码!"<<endl; cin>>key1; cout<<"请再次输入新密码并牢记好新密码!"<<endl; cin>>key2; if(key1==key2) t=0;//对新密码进行比较,如果相等,则返回0 if(t!=0) cout<<"您输入的密码不一致,请重新输入!"<<endl; } customer.key=key1; cout<<"密码修改成功,请您牢记!"<<endl; function(); return OK; } void ATM::lockcard() { cout<<"对不起,你输入的密码错误已达三次,您的卡已被没收!"<<endl; exit(0); } void ATM::quit() { cout<<"请取走您的卡,感谢您的使用,欢迎您下次再来!"<<endl; exit(0); } int main() { ATM a("123456","123456",10000); a.login(); a.function(); return 0; }