ATM业务模拟系统功能要求
客户端:
- 定义用户数据对象,并以此为参数生成用户操作对象;
- 存款操作:生成一条新的业务信息(业务对象),追加到交易记录中,并修改账号余额;
- 取款操作:判断取款数是否超过账号余额,超过显示错误信息,不做任何操作。否则,生成一条新的业务信息(业务对象),追加到交易记录中,并修改账号余额;
- 业务查询:包括余额查询、存/取款业务查询和指定日期、时间段内业务查询;
- 退出:将用户信息、交易记录更新到数据文件。
管理端:
- 增加用户:添加新用户信息并初始化(注意不重复添加,要判重);
- 注销账号:对用户进行临时冻结;
- 激活账号:对冻结的账号解封;
- 查看业务信息(查看所有用户/指定用户信息、查看指定时间段业务交易情况(取款、存款、全部);
- 退出:将用户信息写入数据文件;
ATM类设计要求
数据类:数据成员及get/set函数,成员函数构造函数、必要的运算符重载(含数据合法性检测);
操作类:必要的数据成员、构造函数,实现功能的成员函数。要使用继承、多态机制。
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
using namespace std;
//时间类
class date
{
int year;
int month;
int day;
friend ostream& operator<<(ostream& out, date& d);
friend istream& operator>>(istream& in, date& d);
public:
date(int year, int month, int day);
date();
date(int year)
{
this->year = year;
this->month = 0;
this->day = 0;
}
int GetYear() { return this->year; };
void SetYear(int year) { this->year = year; };
int GetMonth() { return this->month; };
void SetMonth(int month) { this->month = month; };
int GetDay() { return this->day; };
void SetDay(int day) { this->day = day; };
bool operator==(const date& d);
date& operator+(int day);
bool operator<=(date d);
bool operator>=(date d);
};
date::date(int year, int month, int day)
{
this->year = year;
this->month = month;
this->day = day;
}
date::date()
{
this->year = 0;
this->month = 0;
this->day = 0;
}
ostream& operator<<(ostream& out, date& d)
{
out << d.year<<"/" << d.month<<"/" << d.day;
return out;
}
istream &operator >>(istream &input,date &b)
{
int y, m, d, max_day;
bool temp = 0;
char op;
while(input >> y >> op >> m >> op >> d)
{
if(y % 4 == 0 && y % 100 != 0)
temp=1;
if(y % 400 == 0)
temp=1;
if (m >= 13 || m <= 0)
{
continue;
}
else
{
if (m == 2)
max_day = (temp ? 29 : 28);
if (m < 8)
max_day = (m & 1) ? 31 : 30;
else
max_day = (m & 1) ? 30 : 31;
}
if(d<=max_day)
{
b.year=y;
b.month=m;
b.day=d;
break;
}
}
return input;
}
bool date::operator==(const date& d)
{
if (d.day == this->day && d.month == this->month && d.year == this->year)
{
return true;
}
else return false;
}
bool date::operator<=(date d)
{
if (this->GetYear() == d.GetYear())
{
if (this->GetMonth() == d.GetMonth())
{
return this->GetDay() <= d.GetDay();
}
else
return this->GetMonth() <= d.GetMonth();
}
else
return this->GetYear() <= d.GetYear();
}
bool date::operator>=(date d)
{
if (this->GetYear() == d.GetYear())
{
if (this->GetMonth() == d.GetMonth())
{
return this->GetDay() >= d.GetDay();
}
else
return this->GetMonth() >= d.GetMonth();
}
else
return this->GetYear() >= d.GetYear();
}
//操作用户类
class user
{
friend ostream& operator<<(ostream& out, user& user);
friend istream& operator>>(istream& in, user& user);
public:
string UserName;//用户姓名
string UserSex;//用户性别
string UserID;//用户身份证
string UserPhone;//用户手机号
double UserBalance=0;//用户账号余额
int state;//状态:是否被冻结
user()
{
this->state=0;
};
user(string UserName,string UserSex,string UserID,string UserPhone,double UserBalance)
{
this->UserName=UserName;
this->UserSex=UserSex;
this->UserID=UserID;
this->UserPhone=UserPhone;
this->UserBalance=UserBalance;
this->state=0;
};
string GetUserName()
{
return this->UserName;
}
void SetUserName(string UserName01)
{
this->UserName=UserName01;
}
string GetUserSex()
{
return this->UserSex;
}
void SetUserSex(string UserSex01)
{
this->UserSex=UserSex01;
}
string GetUserID()
{
return this->UserID;
}
void SetUserID(string UserID01)
{
this->UserID=UserID01;
}
string GetUserPhone()
{
return this->UserPhone;
}
void SetUserPhone(string UserPhone01)
{
this->UserPhone=UserPhone01;
}
double GetUserBalance()
{
return this->UserBalance;
}
void SetUserBalance(double UserBalance01)
{
this->UserBalance=UserBalance01;
}
int GetSate()
{
return this->state;
}
void SetSate(int state01)
{
this->state=state01;
}
//身份证唯一识别用户
bool operator==(user user)
{
if (this->GetUserID()==user.GetUserID())
{
return true;
}
else return false;
};
bool JudgeUserSex(string UserSex)
{
if(UserSex=="男"||UserSex=="女")
{
return true;
}
else return false;
}
bool JudgeUserPhone(string UserPhone)
{
if(UserPhone.size()==11)
{
return true;
}
else return false;
}
bool JudgeUserID(string UserID)
{
if(UserID.size()==18)
{
return true;
}
else return false;
}
};
ostream& operator<<(ostream& out, user& user)
{
out<<user.UserName<<" "<<user.UserSex<<" "<<user.UserID<<" "<<user.UserPhone<<" "<<user.UserBalance<<" "<<user.state;
return out;
}
istream& operator>>(istream& in, user& user)
{
in>>user.UserName>>user.UserSex>>user.UserID>>user.UserPhone>>user.UserBalance>>user.state;
return in;
}
//业务信息类
class business:public user
{
date date01;
user user01;
string operation;//操作类型:取款,借款
double money;//操作钱数
friend ostream& operator<<(ostream& out, business& business);
friend istream& operator>>(istream& in, business& business);
public:
business(){};
business(user user01,date date01,string operation,double money)
{
this->date01=date01;
this->user01=user01;
this->operation=operation;
this->money=money;
};
date GetBusDate()
{
return this->date01;
}
void SetBusDate(date d)
{
this->date01=d;
}
user GetUser()
{
return this->user01;
}
void SetUser(user user02)
{
this->user01=user02;
}
string GetOperation()
{
return this->operation;
}
void SetOperation(string operation01)
{
this->operation=operation01;
}
double GetMoney()
{
return this->money;
}
void SetMoney(double money01)
{
this->money=money01;
}
};
ostream& operator<<(ostream& out, business& business)
{
out<<business.user01<<" "<<business.date01<<" "<<business.operation<<" "<<business.money;
return out;
}
istream& operator>>(istream& in, business& business)
{
in>>business.user01>>business.date01>>business.operation>>business.money;
return in;
}
//日期类按照日期升序排序
class comapreDate
{
public://仿函数
bool operator()(date a1, date a2)
{
if (a1.GetYear() == a2.GetYear())
{
if (a1.GetMonth() == a2.GetMonth())
{
return a1.GetDay() < a2.GetDay();
}
else return a1.GetMonth() < a2.GetMonth();
}
else return a1.GetYear() < a2.GetYear();
}
};
class comapreUser
{
public:
bool operator()(user user01,user user02)
{
return user01.GetUserBalance()<user02.GetUserBalance();
}
};
//客户端类
class client:public user
{
protected:
user user01;
date date01;
business business02;
multimap<date, int,comapreDate> mbr_date;
multimap<user, int,comapreUser> mbr_user;
public:
vector<business> vbr;
vector<user> vur;
~client()
{
ClientOsBUS();
ClientOsUser();
};
client()
{
ClientIsBUS();
ClientIsUser();
};
client(user user01,date date01)
{
this->user01=user01;
this->date01=date01;
ClientIsBUS();
ClientIsUser();
}
date GetDate()
{
return this->date01;
}
void SetDate(date d)
{
this->date01=d;
}
user GetUser()
{
return this->user01;
}
void SetUser(user user02)
{
this->user01=user02;
}
void ClientOsBUS();//业务文件读出
void ClientIsBUS();//业务文件写入
void ClientOsUser();//用户文件读出
void ClientIsUser();//用户文件写入
void deposit(double money);//存款操作
void withdraw(double money);//取款操作
void balance();//余额查询
void Business_query01(date date02);//指定日期业务查询
void Business_query02(date date03,date date04);//时间段业务查询
};
void client::ClientOsBUS()
{
ofstream ofs;
ofs.open("BusinessRecord.txt", ios::out);
for (vector<business>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
{
ofs << (*it) << endl;
}cout << endl;
ofs.close();
}
void client::ClientIsBUS()
{
user user01;
date date01;
string op="";
double money=0.0;
ifstream ifs;
ifs.open("BusinessRecord.txt", ios::in);
if (!ifs.is_open())
{
return;
}
char x;
while (ifs>>user01>>date01>>op>>money)
{
business business01(user01,date01,op,money);
vbr.push_back(business01);
mbr_date.insert(make_pair(business01.GetBusDate(), vbr.size() - 1));
mbr_user.insert(make_pair(business01.GetUser(), vbr.size() - 1));
}
ifs.close();
}
void client::ClientOsUser()
{
ofstream ofs;
ofs.open("User.txt", ios::out|ios::app);
for (vector<user>::iterator it = this->vur.begin(); it != this->vur.end(); it++)
{
ofs << (*it) << endl;
}cout << endl;
ofs.close();
}
void client::ClientIsUser()
{
user user01;
ifstream ifs;
ifs.open("User.txt", ios::in);
if (!ifs.is_open())
{
return;
}
while (ifs >> user01)
{
vur.push_back(user01);
}
ifs.close();
}
void client::deposit(double money)
{
business02.SetBusDate(date01);
business02.SetUser(user01);
business02.SetOperation("deposit");
business02.SetMoney(money);
for (vector<user>::iterator it = vur.begin(); it != vur.end(); it++)
{
if((*it).GetSate()==0&&(*it)==user01)
{
(*it).SetUserBalance(user01.GetUserBalance()+money);
user01.SetUserBalance(user01.GetUserBalance()+money);
break;
}
}
vbr.push_back(business02);
}
void client::withdraw(double money)
{
if(user01.GetUserBalance()>=money)
{
business02.SetBusDate(date01);
business02.SetUser(user01);
business02.SetOperation("withdraw");
business02.SetMoney(money);
for (vector<user>::iterator it = vur.begin(); it != vur.end(); it++)
{
if((*it).GetSate()==0&&(*it)==user01)
{
(*it).SetUserBalance(user01.GetUserBalance()-money);
user01.SetUserBalance(user01.GetUserBalance()-money);
break;
}
}
vbr.push_back(business02);
}
else
{
cout<<"Insufficient amount, withdrawal failed!"<<endl;
}
}
void client::balance()
{
cout<<user01.GetUserBalance()<<endl;
}
void client::Business_query01(date date02)
{
for (vector<business>::iterator it = vbr.begin(); it != vbr.end(); it++)
{
if((*it).GetBusDate()==date01)
{
cout<<(*it)<<endl;
}
}
}
void client::Business_query02(date date03,date date04)
{
for (vector<business>::iterator it = vbr.begin(); it != vbr.end(); it++)
{
if((*it).GetBusDate()>=date03&&(*it).GetBusDate()<=date04)
{
cout<<(*it)<<endl;
}
}
}
//管理端
class admin:public client
{
public:
~admin(){};
admin(){};
admin(user user01,date date01):client(user01,date01){};
void Add_user();//增加用户
void Freeze_user(user user01);//冻结用户
void Unfreeze_user(user user01);//解冻用户
void query_business01();//查看业务信息(所有用户)
void query_business02(user user01);//查看业务信息(指定用户)
void query_business03(date d1,date d2);//查看业务信息(指定时间段全部)
void query_business04(date d1,date d2);//查看业务信息(指定时间段存款)
void query_business05(date d1,date d2);//查看业务信息(指定时间段取款)
};
void admin::Add_user()
{
user user01;
string name,sex,id,phone;double balance=0;
cout<<"请输入用户姓名:"<<endl;
cin>>name;
cout<<"请输入用户性别:"<<endl;
cin>>sex;
if(user01.JudgeUserSex(sex))
{
cout<<"请输入用户身份证:"<<endl;
cin>>id;
if(user01.JudgeUserID(id))
{
cout<<"请输入用户手机号:"<<endl;
cin>>phone;
if(user01.JudgeUserPhone(phone))
{
cout<<"请输入用户余额:"<<endl;
cin>>balance;
user01.SetUserName(name);
user01.SetUserSex(sex);
user01.SetUserID(id);
user01.SetUserPhone(phone);
user01.SetUserBalance(balance);
user01.state=0;
int flag=0;
multimap<user, int,comapreUser>::iterator it=mbr_user.find(user01);
if (it == mbr_user.end())
{
flag=1;
}
if(flag==0)
{
vur.push_back(user01);
cout<<"添加用户成功!"<<endl;
}
else
{
cout<<"用户已存在!"<<endl;
}
}
else
{
cout<<"手机号填写错误!"<<endl;
}
}
else
{
cout<<"身份证填写错误!"<<endl;
}
}
else
{
cout<<"性别填写错误!"<<endl;
}
}
void admin::Freeze_user(user user01)
{
int flag=0;
for (vector<user>::iterator it = vur.begin(); it != vur.end(); it++)
{
if((*it)==user01&&(*it).GetSate()==0)
{
flag=1;
break;
}
}
user01.SetSate(1);
vur.push_back(user01);
}
void admin::Unfreeze_user(user user01)
{
int flag=0;
for (vector<user>::iterator it = vur.begin(); it != vur.end(); it++)
{
if((*it)==user01&&(*it).GetSate()==1)
{
flag=1;
break;
}
}
user01.SetSate(0);
vur.push_back(user01);
}
void admin::query_business01()
{
for (vector<business>::iterator it = vbr.begin(); it != vbr.end(); it++)
{
cout<<(*it)<<endl;
}
}
void admin::query_business02(user user01)
{
for (vector<business>::iterator it = vbr.begin(); it != vbr.end(); it++)
{
if((*it).GetUser().GetUserID()==user01.GetUserID()&&user01.GetSate()==0)
{
cout<<(*it)<<endl;
}
}
}
void admin::query_business03(date d1,date d2)
{
for (vector<business>::iterator it = vbr.begin(); it != vbr.end(); it++)
{
if((*it).GetBusDate()>=d1&&(*it).GetBusDate()<=d2)
{
cout<<(*it)<<endl;
}
}
}
void admin::query_business04(date d1,date d2)
{
for (vector<business>::iterator it = vbr.begin(); it != vbr.end(); it++)
{
if((*it).GetBusDate()>=d1&&(*it).GetBusDate()<=d2&&(*it).GetOperation()=="deposit")
{
cout<<(*it)<<endl;
}
}
}
void admin::query_business05(date d1,date d2)
{
for (vector<business>::iterator it = vbr.begin(); it != vbr.end(); it++)
{
if((*it).GetBusDate()>=d1&&(*it).GetBusDate()<=d2&&(*it).GetOperation()=="withdraw")
{
cout<<(*it)<<endl;
}
}
}
void testClient01()
{
user user01;
user01.SetUserName("李华");
user01.SetUserSex("男");
user01.SetUserID("310211200112811111");
user01.SetUserPhone("13069327777");
user01.SetUserBalance(3000);
date date01(2022,6,22);
date date02(2022,6,23);
client client01;
client01.SetDate(date01);
client01.SetUser(user01);
client01.deposit(100);
client01.withdraw(200);
client01.balance();
client01.Business_query01(date01);
//client01.Business_query02(date01,date02);
}
void testClient02()
{
user user01;
user01.SetUserName("张小花");
user01.SetUserSex("女");
user01.SetUserID("310211200112822222");
user01.SetUserPhone("13069328888");
user01.SetUserBalance(2000);
date date01(2022,6,24);
date date02(2022,6,25);
client client01;
client01.SetDate(date01);
client01.SetUser(user01);
client01.deposit(200);
client01.withdraw(10000);
client01.balance();
//client01.Business_query01(date01);
client01.Business_query02(date01,date02);
}
void testAdd_user()
{
admin admin01;
admin01.Add_user();
}
void testFreeze()
{
user user01;
user01.SetUserName("李元浩");
user01.SetUserSex("男");
user01.SetUserID("310211201102025555");
user01.SetUserPhone("13069327777");
user01.SetUserBalance(5000);
date date01(2022,6,25);
admin admin01(user01,date01);
admin01.Freeze_user(user01);
}
void testUnfreeze()
{
user user01;
user01.SetUserName("高圆圆");
user01.SetUserSex("女");
user01.SetUserID("310211201102024444");
user01.SetUserPhone("13069324444");
user01.SetUserBalance(3000);
date date01(2022,6,26);
admin admin01(user01,date01);
admin01.Unfreeze_user(user01);
}
void testAdmin()
{
user user01;
date date01(2022,6,22);
date date02(2022,6,23);
user01.SetUserName("李华");
user01.SetUserSex("男");
user01.SetUserID("310211200112811111");
user01.SetUserPhone("13069327777");
user01.SetUserBalance(3000);
admin admin01(user01,date01);
admin01.query_business01();
//admin01.query_business02(user01);
//admin01.query_business03(date01,date02);
//admin01.query_business04(date01,date02);
admin01.query_business05(date01,date02);
}
int main()
{
//testClient01();
//testClient02();
//testAdd_user();
//testFreeze();
//testUnfreeze();
testAdmin();
}
ATM业务模拟系统设计报告
目录
ATM业务模拟系统功能要求
ATM类设计要求
一、基础类组成
1.1时间类
1.2用户类
1.3业务信息类
二、操作类组成
2.1客户端类
2.2管理端类
一、基础类组成
1.1时间类
创建时间类date,类中有三个数据成员year,month,day,他们均为int类型,友元的输入输出函数,创建date有参(int year, int month, int day)构造函数及无参构造函数,创建各个数据成员的get及set函数,方便获得数据成员的值及修改数据。
date类中还具有重载函数,通过重载可以直接操作该类,其中重载的有输入输出函数,比较大小函数和判断全等符号函数。
1.2用户类
创建用户类user,类中有六个数据成员UserName,UserSex,UserID,UserPhone,UserBalance,state,其中前四个为string类型,balance为double类型,state为int类型并判断是否被冻结。友元的输入输出函数,创建无参和有参构造函数,创建各个数据成员的get及set函数,方便获得数据成员的值及修改数据。
类中还有重载函数,全等重载函数通过身份证id唯一识别用户。成员函数中还有判断数据是否准确函数,JudgeUserSex只有输入为男或女才输出true,JudgeUserPhone检验输入手机号数字个数,当数字size为11时输出true,JudgeUserID检验输入身份证数字个数,当数字size为18时输出true。
1.3业务信息类
创建业务信息类business,该类中有四个成员函数date,user,operation,money,date为date类型,user为user类型,operation为string类型,money为double类型。友元的输入输出函数,创建无参和有参构造函数,创建各个数据成员的get及set函数,方便获得数据成员的值及修改数据。
业务信息类中还有通过重载可以直接操作该类,其中重载的有输入输出函数,方便后续进行直接输入输出操作。
二、操作类组成
2.1客户端类
创建客户端类client,该类中有三个个成员函数user,date,business。具有两个map容器,分别存放date和user,方便后续查询操作。还具有两个vector容器,存放business和user向量。创建各个数据成员的get及set函数,方便获得数据成员的值及修改数据。
该类中有business文件输入输出函数ClientOsBUS()和ClientIsBUS(),user文件输入输出函数ClientOsUser()和ClientIsUser()。无参及有参构造函数中有上述文件is功能,将文件内容写入向量,析构函数有os功能,将向量内容写回文件。
该类中具有存款操作函数deposit(double money),通过输入存款金额,然后对该用户生成一条存款记录,并将其插入到business向量里面。
该类中具有取款操作函数withdraw(double money),通过输入取款金额,然后判断金额与余额大小,若金额小于余额,则在business插入一条记录,否则输出金额不足,取款失败的提示!
该类中具有余额查询操作函数balance(),查询该用户余额大小。该用户具有业务查询操作Business_query01(date date02)指定日期业务查询,Business_query02(date date03,date date04)时间段业务查询,查询该用户下所有业务。
2.2管理端类
创建管理端类admin,该类继承用户端类client,可以通过继承使用用户端的一些功能。创建构造函数时需要写入user和date对继承客户端赋初值,构造函数和析构函数也会自动调用用户端的输入输出文件函数。
该类中有添加用户函数Add_user(),依次输入姓名,性别,身份证,手机号,余额等,然后依次进行user中的输入判断。
若所有判断函数均通过,则将添加的用户加到user向量中,然后析构函数时,可将其插入到文件中去。
该类中还有冻结函数Freeze_user(user user01)和解冻函数Unfreeze_user(user user01),冻结可将用户user中的state由0变为1代表冻结不可操作,解冻将用户user中的state由1变为0。
该类还有业务查询函数,query_business01()查看业务信息(所有用户),query_business02(user user01)查看业务信息(指定用户),通过查询容器输出用户业务信息。还有几个按照时间查询函数,可以查询在不同时间的业务信息,如全部信息,存款取款等。
可以点个免费的赞吗!!!