千家信息网

怎么用C++代码实现图书馆管理系统

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,这篇"怎么用C++代码实现图书馆管理系统"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇
千家信息网最后更新 2025年01月21日怎么用C++代码实现图书馆管理系统

这篇"怎么用C++代码实现图书馆管理系统"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"怎么用C++代码实现图书馆管理系统"文章吧。

一.代码

#includeusing namespace std;class Date{    int year,month,day;public:    Date(int x,int y,int z):year(x),month(y),day(z){}    Date(){year=month=day=0;}    void setDate(int x,int y,int z){year=x;month=y;day=z;}    void setYear(int x){year=x;}    void setMonth(int x){month=x;}    void setDay(int x){day=x;}      int getYear(){return year;}    int getMonth(){return month;}    int getDay(){return day;}    friend ostream& operator<<(ostream &out,Date &t );    friend istream& operator>>(istream &in,Date &t);    bool operator<(const Date &t);};ostream& operator<<(ostream &out,Date &t ){    out<>(istream &in,Date &t){    in>>t.year>>t.month>>t.day;    return in;}bool Date::operator<(const Date &t){    return year!=t.year?year>(istream &in,Record &r);    void display();};void Record::setE(){    int i,j,k;    i=end.getYear();    j=end.getMonth();    k=end.getDay();    if(j+2<=12)    {        end.setDate(i,j+2,k);    }    else  end.setDate(i+1,j+2-12,k);}ostream& operator<<(ostream &out,Record &r){    out<>(istream &in,Record &r){    in>>r.uid>>r.bid>>r.start>>r.end>>r.xj>>r.sy;    return in;}void Record::display(){    cout<<"借阅人:"<v1;    vector::iterator it1;    multimapm1;//根据借阅人的学号建立    multimap::iterator mit1;    Book(int a,string b,string c,Date d,int e,int f):id(a),name(b),press(c),pd(d),sum(e),ln(f){i=v1.size();}    Book(){}    int getId(){return id;}    string getName(){return name;}    string getPress(){return press;}    Date getPd(){return pd;}      int getSum(){return sum;}    int getLn(){return ln;}      void setSum(int x){sum=x;}    void setLn(int x){ln=x;}      void addRecord(Record r);    void dispRecord();    int search(int x);//根据借阅人的学号查询    void display();    void display1();    friend istream& operator>>(istream &in,Book &b);    friend ostream& operator<<(ostream &out,Book &b);};istream& operator>>(istream &in,Book &b){    in>>b.id>>b.name>>b.press>>b.pd>>b.sum>>b.ln>>b.i;    int s=0;    if(b.i!=0)    {        while(s!=b.i)        {            in>>b.v1[s];s++;        }    }    return in;}ostream& operator<<(ostream &out,Book &b){    out<second;//返回的是这本书存储的关于借阅人x的借阅记录的下标值    }    else return -1;}void Book::display(){    cout<<"书号:"<v2;    vector::iterator it2;    multimapm2;//根据所借书的书号建立    multimap::iterator mit2;    User(int a,string b,string c):id(a),name(b),major(c)    {        mb=10;nb=0;wj=0;i=v2.size();    }    User(){i=v2.size();}    int getId(){return id;}    string getName(){return name;}    string getMajor(){return major;}      int getmb(){return mb;}    int getnb(){return nb;}    int getwj(){return wj;}      void setmb(int x){mb=x;}    void setnb(int x){nb=x;}    void setwj(){wj=1;mb=0;}      void addRecord(Record r);    void dispRecord();    int search(int no);//通过书号查找    void display();      bool operator ==( User &u)    {        if(this->id==u.getId())        return 1;        else return 0;    }    User & operator =(User &u)    {        id=u.id;        name=u.name;        major=u.major;        mb=u.mb;        nb=u.nb;        wj=u.wj;        v2=u.v2;        m2=u.m2;    }    friend ostream& operator<<(ostream &out,User &u);    friend istream& operator>>(istream &in,User &u);};ostream& operator<<(ostream &out,User &u){    out<>(istream &in,User &u){      in>>u.id>>u.name>>u.major>>u.mb>>u.nb>>u.wj>>u.i;    int s=0;    if(u.i!=0)    {        while(s!=u.i)        {            in>>u.v2[s];s++;        }    }    return in;}void User::addRecord(Record r){    int i;    v2.push_back(r);    i=v2.size();    m2.insert(make_pair(r.getBid(),i-1));}void User::dispRecord(){    for(int i=0;isecond;    }    else return -1;}void User::display(){    cout<<"学号:"<v3;    vector::iterator it3;    multimapm3;    multimap::iterator mit3;      vectorv;    vector::iterator it;    multimapm;    multimap::iterator mit;public:    Client(int x)    {        load1();         load2(x);    }    ~Client()    {        save1();         save2();    }    void load1();    void save1();    void load2(int x);    void save2();    void queryBook(int x);    void borrow(int x,Date t);    void back(int x);    void displayu(){u.display();}    void displayb(int x){mit3=m3.find(x); v3[mit3->second].display();}};void Client::load1(){    Book b;    int i;    ifstream infile("d:\\20171750book.txt",ios::in);    if(!infile) return;    while(infile>>b)    {        v3.push_back(b);        i=v3.size();        m3.insert(make_pair(b.getId(),i-1));    }    infile.close();}void Client::save1(){    ofstream outfile("d:\\20171750book.txt",ios::out);    if(!outfile) return;    for(int i=0;i>u)    {        v.push_back(u);        i=v.size();        m.insert(make_pair(u.getId(),i-1));        if(x==u.getId())        {            this->u=u;        }    }    infile.close();}void Client::save2(){    ofstream outfile("d:\\20171750stu.txt",ios::out);    if(!outfile) return ;    for(it=v.begin();it!=v.end();it++)    {        outfile<<*it;        outfile<second].display1();    }    else        cout<<"未找到该书!"<second;    j=v3[i].getLn();    k=v3[i].getSum();    if(u.getwj()==0&&jsecond].addRecord(r);        v3[i].addRecord(r);        u.setnb(u.getnb()+1);                       v[mit->second].setnb(u.getnb());        v3[i].setLn(j+1);    }    else       cout<<"借书失败!"<second;    int j=v3[i].getLn();    if(s!=0)    {        for(int i=0;isecond].setnb(u.getnb());        v3[i].setLn(j-1);        v3[i].mit1=v3[i].m1.find(u.getId());  v3[i].v1[v3[i].mit1->second].setsy(1);        u.mit2=u.m2.find(x);                  u.v2[u.mit2->second].setsy(1);        int k=mit->second;        v[k].mit2=v[k].m2.find(x);  v[k].v2[v[k].mit2->second].setsy(1);    }    else        cout<<"还书失败!"<v4;   vector::iterator it4;   multimapm4;   multimap::iterator mit4;     vectorv5;   vector::iterator it5;   multimapm5;   multimap::iterator mit5;public:   Manger()   {       load1();       load2();   }   ~Manger()   {       save1();       save2();   }   void load1();   void load2();   void save1();   void save2();   void addUser(User u);   void addBook(Book b);   void displayU(int x);   void displayB(int x);};void Manger::load1(){    User u;    int i;    ifstream infile("d:\\20171750stu.txt",ios::in);    if(!infile) return;    v4.clear(); m4.clear();    i=0;    while(infile>>u)    {        v4.push_back(u);        m4.insert(make_pair(u.getId(),i));        i++;    }    infile.close();}void Manger::load2(){    Book b;    int i;    ifstream infile("d:\\20171750book.txt",ios::in);    if(!infile)  return;    v5.clear();m5.clear();    i=0;    while(infile>>b)    {        v5.push_back(b);        m5.insert(make_pair(b.getId(),i));        i++;    }    infile.close();}void Manger::save1(){    ofstream outfile("d:\\20171750stu.txt",ios::out);    if(!outfile)  return;    for(it4=v4.begin();it4!=v4.end();it4++)    {        outfile<<*it4;        outfile<second].display();}void Manger::displayB(int x){    mit5=m5.find(x);    v5[mit5->second].display();}int main(){  //时间类测试/*  Date a(1999,4,27);  Date b(2000,4,27);  cout<

以上就是关于"怎么用C++代码实现图书馆管理系统"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。

0