#include #include #include

using namespace std;

// 书籍类 class Book { public: Book(string title, int id, string author, string publisher) { this->title = title; this->id = id; this->author = author; this->publisher = publisher; } string getTitle() { return title; } int getId() { return id; } string getAuthor() { return author; } string getPublisher() { return publisher; } private: string title; int id; string author; string publisher; };

// 读者类 class Reader { public: Reader(string name, int id) { this->name = name; this->id = id; } string getName() { return name; } int getId() { return id; } vector getBooks() { return books; } void borrowBook(Book book) { if (books.size() < 6) { books.push_back(book); } else { cout << '借书数量已达上限,不能继续借书。' << endl; } } void printBorrowedBooks() { cout << '借书情况:' << endl; for (int i = 0; i < books.size(); i++) { cout << i + 1 << '. ' << books[i].getTitle() << '(' << books[i].getAuthor() << ' 著,' << books[i].getPublisher() << ' 出版)' << endl; } } private: string name; int id; vector books; };

int main() { // 创建书籍和读者对象 Book book1('C++程序设计', 1001, '谭浩强', '清华大学出版社'); Book book2('Java程序设计', 1002, '李刚', '人民邮电出版社'); Book book3('Python程序设计', 1003, 'Guido van Rossum', '机械工业出版社'); Reader reader('张三', 2001);

// 借书
reader.borrowBook(book1);
reader.borrowBook(book2);
reader.borrowBook(book3);

// 输出借书情况
reader.printBorrowedBooks();

return 0;
C++实现图书馆借书管理系统:列出读者借书情况

原文地址: https://www.cveoy.top/t/topic/oakZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录