实例介绍
【实例截图】
【核心代码】
#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;
}
标签: c++
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论