21xrx.com
2024-12-22 21:46:23 Sunday
登录
文章检索 我的文章 写文章
C++图书馆管理系统——源代码
2023-07-10 14:44:34 深夜i     --     --
C++ 图书馆 管理系统 源代码

图书馆管理系统是一种常见的学术机构管理工具,可以有效地管理图书集合,以及借阅和还书流程。在这篇文章中,我们将提供一个使用C++编写的图书馆管理系统的源代码,以便读者参考和学习。该系统旨在通过简化日常管理任务,提高学术机构的效率和管理水平。以下是C++图书馆管理系统的源代码:

#include

#include

#include

#include

using namespace std;

class Date

{

  public:

    int day, month, year;

  public:

    friend istream& operator >> (istream& in, Date& date)

      cout << "Enter day: ";

      in >> date.day;

      cout << "Enter month: ";

      in >> date.month;

      cout << "Enter year: ";

      in >> date.year;

      return in;

    friend ostream& operator << (ostream& out, Date date)

      out << date.day << "/" << date.month << "/" << date.year;

      return out;

};

class Book

{

  public:

    int bookID;

    char bookName[50];

    char authorName[50];

    float bookPrice;

    int stock;

    Date purchaseDate;

    Date expiryDate;

  public:

    void inputBookInfo()

      cout << "Enter book ID: ";

      cin >> bookID;

      cout << "Enter book name: ";

      cin >> bookName;

      cout << "Enter author name: ";

      cin >> authorName;

      cout << "Enter book price: ";

      cin >> bookPrice;

      cout << "Enter stock: ";

      cin >> stock;

      cout << "Enter purchase date: " << endl;

      cin >> purchaseDate;

      cout << "Enter expiry date: " << endl;

      cin >> expiryDate;

    void outputBookInfo()

      cout << "Book ID: " << bookID << endl;

      cout << "Book name: " << bookName << endl;

      cout << "Author name: " << authorName << endl;

      cout << "Book price: " << bookPrice << endl;

      cout << "Stock: " << stock << endl;

      cout << "Purchase date: " << purchaseDate << endl;

      cout << "Expiry date: " << expiryDate << endl;

};

class Library

{

  public:

    int totalBooks;

    Book books[100];

  public:

    void addBook()

    {

      books[totalBooks].inputBookInfo();

      totalBooks++;

    }

    void displayBooks()

    {

      for(int i=0; i

      {

        books[i].outputBookInfo();

      }

    }

};

int main()

{

  Library library;

  int choice;

  while(true)

  {

    cout << "1. Add a book" << endl;

    cout << "2. Display books" << endl;

    cout << "3. Exit" << endl;

    cout << "Enter your choice: ";

    cin >> choice;

    switch(choice)

    {

      case 1:

        library.addBook();

        break;

      case 2:

        library.displayBooks();

        break;

      case 3:

        exit(0);

        break;

      default:

        cout << "Invalid choice. Try again." << endl;

        break;

    }

  }

  return 0;

}

以上是C++图书馆管理系统的源代码,其中包括三个类:日期类,书本类和图书馆类。每个类都有适当的成员函数和数据成员,以实现图书馆管理系统的核心功能。该系统允许用户添加、显示和退出功能,可以根据需要进行扩展和修改。

总之,这个图书馆管理系统源代码是一个很好的起点,让初学者和有经验的程序员都能了解C++编程的所有方面。希望你能够从这个例子中学到一些新东西,启发你创造出更多的程序。

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复