假设图书管的图书包含书名、编号、作者属性和出版社等属性读者包含姓名、ID和借书属性每位读者最多可以借6本书。编写程序列出某读者的借书情况用c++编写
#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
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;
原文地址: https://www.cveoy.top/t/topic/fiIy 著作权归作者所有。请勿转载和采集!