c++之ATM

c++之ATM(一)


#include<bits/stdc++.h>

using namespace std;
class Time
{
int month;
int day;
int hour;
int minute;
public:
Time(int m,int d,int h,int mi)
{
month=m;
day=d;
hour=h;
minute=mi;
}
Time(){};
void setTime(int m,int d,int h,int mi)
{
month=m;
day=d;
hour=h;
minute=mi;
}
int getMonth(){return month;}
int getDay(){return day;}
int getHour(){return hour;}
int getMinute(){return minute;}
void displayTime()
{
cout<<month<<" "<<day<<" "<<hour<<" "<<minute<<" ";
}
};
class Record
{
int no;
Time date;
string type;
int trade_money;
int remaining_money;
public:
Record(int x,string y,int z,int w)
{
no=x;
type=y;
trade_money=z;
remaining_money=w;
}
Record(){};
void setTime(int m,int d,int h,int mi)
{
date.setTime(m,d,h,mi);
}
void setRecord(int x,string y,int z,int w)
{
no=x;
type=y;
trade_money=z;
remaining_money=w;
}
int getNo(){return no;}
Time getDate(){return date;}
string getType(){return type;}
int getTrade_money(){return trade_money;}
int getRemaining_money(){return remaining_money;}
void displayRecord()
{
cout<<no<<" ";
date.displayTime();
cout<<type<<" "<<trade_money<<" "<<remaining_money<<endl;
}
};
class User
{
int no;
string name;
string code;
double remaining_money;
Record r[200];
int num;
public:
User(int No,string na,string co,double re):no(No),name(na),code(co),remaining_money(re)
{
num=0;
}
void add(Record x);
void dispRecord(int i);
void dispUser();
void dispAllRecord();
void queryByTime(Time t1,Time t2);
bool judgeTime(Time t1,Time t2,Time t3);
void queryByType(string type);
void changeCode(string x);
void setTime(Time t);
void setCode(string x);
int getNo(){return no;}
string getName(){return name;}
string getCode(){return code;}
double getRemaining_money(){return remaining_money;}
void changeRemaining_money(int x,string y);
};
void User::setCode(string x)
{
code=x;
}
void User::dispUser()
{
cout<<no<<" "<<name<<" "<<code<<" "<<remaining_money;
}
void User::add(Record x)
{
num++;
r[num]=x;
}
void User::dispRecord(int i)
{
r[i].displayRecord();
}
void User::dispAllRecord()
{
for(int i=1;i<=num;i++)
r[i].displayRecord();
}
void User::queryByTime(Time t1,Time t2)
{
bool flag=1;
for(int i=1;i<=num;i++)
if(judgeTime(t1,t2,r[i].getDate()))
{
r[i].displayRecord();
flag=0;
}
}
bool User::judgeTime(Time t1,Time t2,Time t3)
{
int x=t1.getMonth()+t1.getDay();
int y=t2.getMonth()+t2.getDay();
int z=t3.getMonth()+t3.getDay();
int a=t1.getHour();
int b=t2.getHour();
int c=t3.getHour();
int e=t1.getMinute();
int f=t2.getMinute();
int g=t3.getMinute();
if((z>=x&&z<=y)&&(c>=a&&c<=b))
{
if(g>=e&&g<=f) return true;
}
else return false;
}
void User::queryByType(string type)
{
for(int i=1;i<=num;i++)
{
if(r[i].getType()==type)
{
r[i].displayRecord();
}
}
}
void User::changeCode(string x)
{
code=x;
}
void User::setTime(Time t)
{
r[num].setTime(t.getMonth(),t.getDay(),t.getHour(),t.getMinute());
}
void User::changeRemaining_money(int x,string y)
{
if(y=="+") remaining_money+=x;else remaining_money-=x;
}
class UserOp
{
User usr;
Time t;
public:
UserOp(User u,Time t1):usr(u),t(t1){};
void withdraw();
void deposit();
void queryByTime();
void displayUsr();
void queryByType(string type);
void display1();
void display2();
};
void UserOp::withdraw()
{
int x;
cin>>x;
if(usr.getRemaining_money()>=x)
{
usr.changeRemaining_money(x,"-");
Record r1(usr.getNo(),"qq",x,usr.getRemaining_money());
usr.add(r1);
usr.setTime(t);
}
else cout<<"所取钱数超过账户余额"<<endl;
}
void UserOp::deposit()
{
int x;
cin>>x;
usr.changeRemaining_money(x,"+");
Record r1(usr.getNo(),"cq",x,usr.getRemaining_money());
usr.add(r1);
usr.setTime(t);
}
void UserOp::queryByTime()
{
int x,y,z,b,x1,y1,z1,b1;
cin>>x>>y>>z>>b>>x1>>y1>>z1>>b1;
Time t1(x,y,z,b);
Time t2(x1,y1,z1,b1);
usr.queryByTime(t1,t2);
}
void UserOp::queryByType(string type)
{
usr.queryByType(type);
}
void UserOp::display1()
{
usr.dispUser();
}
void UserOp::display2()
{
usr.dispAllRecord();
}
int main()
{
freopen("in.dat","r",stdin);
freopen("out.dat","w",stdout);
int no;
string na,co;
double re;
cin>>no;
cin>>na>>co>>re;
User u(no,na,co,re);
int m,d,h,mi;
cin>>m>>d>>h>>mi;
Time t(m,d,h,mi);
UserOp uop1(u,t);
uop1.deposit();
uop1.display1();
uop1.display2();
uop1.withdraw();
uop1.display1();
uop1.queryByType("cq");
uop1.display2();
User u1(2,"wyy","321",2000);
int m1,d1,h1,mi1;
cin>>m1>>d1>>h1>>mi1;
Time t2(m1,d1,h1,mi1);
UserOp uop2(u1,t2);
uop2.display1();
uop2.withdraw();
uop2.withdraw();
uop2.queryByType("cq");
uop2.deposit();
uop2.display2();}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值