c++面向对象图书管理
时间: 2023-12-22 16:27:40 浏览: 24
这个C++面向对象图书管理系统的功能包括图书管理员和读者两个角色,其中管理员可以管理读者账户和图书,而读者可以查询图书信息和借阅图书。以下是该系统的一些功能和实现方法:
1. 管理员添加读者账户
```cpp
class Reader {
public:
string name;
string id;
string password;
// ...
};
class Admin {
public:
void addReader(vector<Reader>& readers, Reader reader) {
readers.push_back(reader);
}
// ...
};
```
2. 管理员管理图书
```cpp
class Book {
public:
string name;
string author;
string ISBN;
// ...
};
class Admin {
public:
void addBook(vector<Book>& books, Book book) {
books.push_back(book);
}
void deleteBook(vector<Book>& books, string ISBN) {
for (auto it = books.begin(); it != books.end(); ++it) {
if (it->ISBN == ISBN) {
books.erase(it);
break;
}
}
}
// ...
};
```
3. 读者查询图书信息
```cpp
class Book {
public:
string name;
string author;
string ISBN;
// ...
};
class Reader {
public:
void searchBook(vector<Book>& books, string keyword) {
for (auto book : books) {
if (book.name.find(keyword) != string::npos || book.author.find(keyword) != string::npos) {
cout << "Book name: " << book.name << endl;
cout << "Author: " << book.author << endl;
cout << "ISBN: " << book.ISBN << endl;
// ...
}
}
}
// ...
};
```
4. 读者借阅图书
```cpp
class Book {
public:
string name;
string author;
string ISBN;
bool borrowed;
// ...
};
class Reader {
public:
void borrowBook(vector<Book>& books, string ISBN) {
for (auto& book : books) {
if (book.ISBN == ISBN && !book.borrowed) {
book.borrowed = true;
cout << "Borrow book successfully!" << endl;
// ...
return;
}
}
cout << "Book not found or already borrowed!" << endl;
}
// ...
};
```