标签:
下面的4个用户是我宿舍的,当然我是钱最多的,呵呵!
#include<iostream>
#include<string>
using namespace std;
class consumer
{
public:
void int_consumer(string ,string ,string ,float ); //初始化
string get_name(); //读取姓名
string get_id(); //读取账号
string get_password(); //读取密码
float get_money(); //读取金额
void set_name(string N); //开用户名
void set_id(string I); //账户
void set_password(string P); //密码
void set_money(float M); //金额
void change_password(); //改密码
void transfer_money(); //转账
void show_me(); //显示账户信息
void withdraw_money(); //取款
void deposit_money(); //存款
private:
string name;
string id;
string password;
float money;
};
class bank
{
public:
void welcome(); //欢迎界面
void exit_system(); //退出系统
void menu(); //选择菜单
int seek(string); //查找卡号
void int_consumer(int i,string N,string I,string P,float M);
string get_name();
string get_id();
string get_password();
float get_money();
void change_password();
void show_me();
bool check();
void transfer_money();
void withdraw_money();
void deposit_money();
private:
int i;
string pass;
consumer cs[4];
};
void consumer::int_consumer(string N,string I,string P,float M)
{
name=N;
id=I;
password=P;
money=M;
}
void consumer::transfer_money()
{
cout<<"请输入对方账号"<<endl;
int a1;
cin>>a1;
cout<<"请输入转账金额"<<endl;
float a;
cin>>a;
if(money-a<0)
{
cout<<"对不起你的余额不足"<<endl;
}
else
{
money=money-a;
cout<<"转账成功"<<endl;
}
}
string consumer::get_name()
{
return name;
}
string consumer::get_id()
{
return id;
}
string consumer::get_password()
{
return password;
}
float consumer::get_money()
{
return money;
}
void consumer::change_password()
{
cout<<"*******欢迎进入更改密码界面*******"<<endl;
string p1;
cout<<"请输入原密码: ";
cin>>p1;
string p2,p3;
if(p1==password)
{
cout<<"请输入您的新密码: ";
cin>>p2;
cout<<"请再次输入您的新密码: ";
cin>>p3;
if(p2==p3)
{
password=p3;
cout<<"密码修改成功"<<endl;
}
else
cout<<"您两次输入的密码不一致,修改失败!"<<endl;
}
else
cout<<"您输入的密码错误!"<<endl;
}
void consumer::deposit_money()
{
float a=0.0;
cout<<"请输入存款金额:"<<endl;
cin>>a;
while(a<=0)
{
cout<<"输入金额有误,请重新输入"<<endl;
cin>>a;
}
cout<<"正在存钱......"<<endl;
money=money+a;
cout<<"交易成功"<<endl;
}
void consumer::withdraw_money()
{
float a=0.0;
cout<<"请输入取款金额:"<<endl;
cin>>a;
while(a<=0)
{
cout<<"输入金额有误,请重新输入"<<endl;
cin>>a;
}
if(money-a<0)
{
cout<<"对不起你的余额不足"<<endl;
cout<<"你可以透支3元,若要透支请按1"<<endl;
int b;
cin>>b;
if(b==1)
{
if(money-a<-3)
{
cout<<"余额不足"<<endl;
}
else
{
cout<<"正在取款中......"<<" 您的透支金额为"<<a-money<<endl;
money=money-a;
}
}
else
cout<<"交易取消"<<endl;
}
else
{
cout<<"正在取款中......"<<endl;
money=money-a;
cout<<"交易成功!"<<endl;
}
}
void consumer::show_me()
{
cout<<"**********************"<<endl;
cout<<"*****当前账号信息*****"<<endl;
cout<<"**用户姓名:"<<name<<endl;
cout<<"**银行卡号:"<<id<<endl;
cout<<"**卡内余额:"<<money<<endl;
cout<<"**********************"<<endl;
}
void bank::welcome()
{
cout<<"**********欢迎使用**********"<<endl;
cout<<"请输入卡号:"<<endl;
string id;
int flag=-1;
cin>>id;
flag=seek(id);
}
void bank::transfer_money()
{
cs[i].transfer_money();
}
void bank::exit_system()
{
cout<<"**********谢谢使用**********"<<endl;
cout<<"********请收好您的卡********"<<endl;
exit(0);
}
void bank::menu()
{
int n;
do
{
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;
while(n<1||n>6)
{
cout<<"操作错误,请重新输入!"<<endl;
cin>>n;
}
switch(n)
{
case 1: change_password();break;
case 2: withdraw_money();break;
case 3: show_me();break;
case 4: exit_system();break;
case 5: transfer_money();break;
case 6: deposit_money();break;
}
}while(true);
}
int bank::seek(string id)
{
for(int j=0;j<4;j++)
{
if(id==cs[j].get_id())
{
i=j;
break;
}
}
if(j>=4)
{
i=-1;
}
return i;
}
void bank::int_consumer(int i,string N,string I,string P,float M)
{
cs[i].int_consumer(N,I,P,M);
}
string bank::get_name()
{
return cs[i].get_name();
}
string bank::get_id()
{
return cs[i].get_id();
}
string bank::get_password()
{
return cs[i].get_password();
}
float bank::get_money()
{
return cs[i].get_money();
}
bool bank::check()
{
cout<<"请输入密码:"<<endl;
cin>>pass;
if(pass==cs[i].get_password())
return true;
else
return false;
}
void bank::show_me()
{
cs[i].show_me();
}
void bank::change_password()
{
cs[i].change_password();
}
void bank::withdraw_money()
{
cs[i].withdraw_money();
}
void bank::deposit_money()
{
cs[i].deposit_money();
}
int main()
{
bank b;
b.int_consumer(0,"王璐瑶","001","111111",1000);
b.int_consumer(1,"赵龙辉","002","222222",2000);
b.int_consumer(2,"刘晓伟","003","333333",3000);
b.int_consumer(3,"焦晓东","004","444444",4000);
b.welcome();
if(b.check())
{
cout<<"密码正确!"<<endl;
b.menu();
}
else
cout<<"密码错误!"<<endl;
return 0;
}
转载请说明出处,谢谢!!!
这是第二道题内容要求写一个银行的ATM系统 这个浪费了好长时间 ,遇到了许多问题,不过都解决了,上程序
标签:
原文地址:http://www.cnblogs.com/1521299249study/p/4416109.html