ATM修改版


#include<bits/stdc++.h>
using namespace std;
class Time
{
    int month;
    int day;
    int hour;
    int minute;
    public:
    Time(int month1,int day1,int hour1,int minute1)
    {
        month=month1;
        day=day1;
        hour=hour1;
        minute=minute1;
    }
    Time(){month=day=hour=minute=0;}
    void setmonth(int month2){cin>>month2;month=month2;}
    void setday(int day2){cin>>day2;day=day2;}
    void sethour(int hour2){cin>>hour2;hour=hour2;}
    void setminute(int minute2){cin>>minute2;minute=minute2;}
    void settime()
    {
        int month2,day2,hour2,minute2;
        cin>>month2>>day2>>hour2>>minute2;
        month=month2;
        day=day2;
        hour=hour2;
        minute=minute2;
    }
    bool operator <(Time &t);
    bool operator ==(Time &t);
    bool operator <=(Time &d);
    int getmonth(){return month;}
    int getday(){return day;}
    int gethour(){return hour;}
    int getminute(){return minute;}
    void display()
    {
        cout<<month<<" "<<day<<" "<<hour<<" "<<minute<<" ";
    }
};
bool Time::operator <(Time &t)
{
    if(month<t.month)  //首先判断月;
    return true;
    else if(month==t.month)  //月相等就判断天;
    {
        if(day<t.day)
        return true;
    }
    return false;
}
bool Time::operator==(Time &d)        //隐含的this指针
{
    return this->month==d.month
        && this->day==d.day;
}
bool Time::operator<=(Time &d)
{
    return (*this<d)||(*this==d);
}
class Record
{
    int no;
    Time date;
    string type;
    int jiner;
    double yue;
    public:
    Record(int no1,Time &date1,string type1,int jiner1,double yue1);
    Record(){no=0;jiner=yue=0;}
    void setno(int no2){cin>>no2;no=no2;}
    int getno(){return no;}
    void setdate(Time &date1){date1.settime();date=date1;}
    Time getdate(){return date;}
    void settype(string type2){cin>>type2;type=type2;}
    string gettype(){return type;}
    void setjiner(int jiner2){cin>>jiner2;jiner=jiner2;}
    int getjiner(){return jiner;}
    void setyue(double yue2){yue=yue2;} //此时没有输入,则不要忘记在主函数中输入新值;
    double getyue(){return yue;}
    void display()
    {
        cout<<no<<" ";
        date.display();
        cout<<" "<<type;
        cout<<" "<<jiner<<" "<<yue<<endl;
    }
};
Record::Record(int no1,Time &date1,string type1,int jiner1,double yue1)
{
    no=no1; date=date1;type=type1; jiner=jiner1; yue=yue1;
}
class User
{
    int no;
    string name;
    string mima;
    double yue;
    vector<Record> v;
    vector<Record>::iterator it;
    multimap<string,int>m1; //按字符串查找;
    multimap<string,int>::iterator mit1;
    multimap<Time,int>m2;
    multimap<Time,int>::iterator mit2;
    int num;
    public:
    User(int no1,string name1,string mima1,double yue1):no(no1)
    {
        name=name1;mima=mima1;yue=yue1;num=0;
    }
    User(const User&yh):no(yh.no)
    {
        name=yh.name;mima=yh.mima;yue=yh.yue;num=yh.num;
        for(int i=0;i<num;i++)
        {
            v=yh.v;  //不要想得太过复杂;
        }
    }
    void setno(int no2){cin>>no2;no=no2;}
    int getno(){return no;}
    void setname(string name2){cin>>name2;name=name2;}
    string getname(){return name;}
    void setmima(string mima2){mima=mima2;}
    string getmima(){return mima;}
    void setyue(double yue2){yue=yue2;}
    double getyue(){return yue;}
    void add();
    void add(Record r);
    void dispRecord(int i);
    void dispAllRecord();
    int search1(Time t4);
    int search2(string type1);
    void queryByTime(Time t1,Time t2);
    void queryByType(string type1);
    void display()
    {
        cout<<no<<' '<<name<<' '<<mima<<' '<<yue<<endl;
        if(num!=0)
       {
        for(it=v.begin();it!=v.end();it++)
        cout<<*it;
       }
    }
};
void User::add(Record r)
{
    int i;
    v.push_back(r);
    i=v.size();
    m1.insert(make_pair(r.gettype(),i-1));
    m2.insert(make_pair(r.getdate(),i-1));
}
void Demo::add()
{
    Record r;
    int i;
    while(1)
    {
        cin>>r;
        if(r.gettype()=="end") break;
        v.push_back(r);
        i=v.size();
    m1.insert(make_pair(r.gettype(),i-1));
    m2.insert(make_pair(r.getdate(),i-1));
    }
}
void User::dispRecord(int i)
{
    r[i-1].display();
}
void User::dispAllRecord()
{
    for(int i=0;i<num;i++)
    r[i].display();
}
int User::search1(Time t4)
{
    mit2=m2.find(t4);
    if(mit2!=m2.end())
    return mit2->second;
    else
    return -1;
}
void User::queryByTime(Time t1,Time t2)
{
    Time t4;
    if(mit2->second<=t2&&t1<=mit2->second)
      v.display();
}
int User::queryByType(string type1)
{
    mit1=m1.find(type1);
    if(mit1!=m1.end())
    return mit1->second;
    else
    return -1;
}
class UserOp
{
    User usr;
    Time t;
    public:
    UserOp(int no3,string name3,string mima3,double yue3,int month3,int day3,int hour3,int minute3):usr(no3,name3,mima3,yue3),t(month3,day3,hour3,minute3)
    {}
    UserOp(User u1,Time t1):usr(u1),t(t1){}
    void withdraw()
    {
        int m;
        cin>>m;
        if(usr.getyue()>m)
        {
            usr.setyue(usr.getyue()-m);
        Record r1(usr.getno(),t,"qq",m,usr.getyue());
        usr.add(r1);
        }
        else
        cout<<"suoquqianshuchanguoyuer";
    }
    void deposit()
    {
        int c;
        cin>>c;
        usr.setyue(usr.getyue()+c);
        Record r2(usr.getno(),t,"cq",c,usr.getyue());
        usr.add(r2);
    }
    void queryByTime();
    void queryByType(string type);
    void displayall()
    {
        usr.display();
    }
};
void UserOp::queryByTime()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    Time t1(a,b,c,d);
    cin>>a>>b>>c>>d;
    Time t2(a,b,c,d);
    usr.queryByTime(t1,t2);
}
void UserOp::queryByType(string type)
{
    usr.queryByType(type);
}
int main()
{
   // freopen("in.dat","r",stdin);
   // freopen("out.dat","w",stdout);
    /*int month1,day1,hour1,minute1;
    cin>>month1>>day1>>hour1>>minute1;
    Time t1(month1,day1,hour1,minute1);
    Time t2;
    t2.settime();
    t1.display();
    t2.display();*/
    /*int no1;string type1;int jiner1;double yue1;
    Time t1(4,23,8,5);
    cin>>no1>>type1>>jiner1>>yue1;
    Record r1(no1,t1,type1,jiner1,yue1);
    r1.display();
    Record r2;
    r2.setno(no1); //定义一次变量,可以输入不同的值,只要声明了变量即可;
    r2.setdate(t1);
    r2.getdate();
    r2.settype(type1);
    r2.gettype();
    r2.setjiner(jiner1);
    cin>>yue1;
    r2.setyue(yue1);
    r2.getyue();
    r2.display();*/
      int no; string name,mima;
    double yue;
    cin>>no>>name>>mima>>yue;
    User u1(no,name,mima,yue);
    u1.display();
    u1.setmima("778899");
    u1.display();
    Time t1(4,22,8,10);
    Time t2(4,28,13,20);
    Record r1(no,t1,"qq",200,2000);
    Record r2(no,t2,"cq",400,2400);
    u1.add(r1);
    u1.add(r2);
    u1.dispRecord(2);
    Time t3(4,28,0,0);
    Time t4(4,29,0,0);
    u1.queryByTime(t3,t4);
    //u1.queryByType("cq");
    u1.dispAllRecord();
    u1.display();
    User u2(u1);
    u2.queryByType("cq");
    u2.display();
     /*int no3;string name3,mima3;double yue3;
     int month3,day3,hour3,minute3;
     cin>>no3>>name3>>mima3>>yue3;
     cin>>month3>>day3>>hour3>>minute3;
    UserOp uop1(no3,name3,mima3,yue3,month3,day3,hour3,minute3);
    uop1.displayall();
    uop1.deposit();
    uop1.withdraw();
    uop1.queryByType("cq");
    uop1.displayall();
    User u1(2,"wyy","321",2000);
    int m,d,h,f;
    cin>>m>>d>>h>>f;
    Time t2(m,d,h,f);
    UserOp uop2(u1,t2);
    uop2.withdraw();
    uop2.withdraw();
    uop2.queryByType("qq");
    uop2.deposit();
    uop2.displayall();*/
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页