用面向对象思想实现《图书借阅管理系统》的登录注册页面和用户信息维护页面和图书借阅管理页面
时间: 2024-05-09 20:15:24 浏览: 12
好的,下面是使用面向对象思想实现《图书借阅管理系统》的登录注册页面和用户信息维护页面和图书借阅管理页面的代码示例:
```python
# 用户类
class User:
def __init__(self, username, password):
self.username = username
self.password = password
def check_password(self, password):
return self.password == password
# 登录注册页面
class LoginRegisterPage:
def __init__(self):
self.users = []
def register(self, username, password):
for user in self.users:
if user.username == username:
print("该用户名已被注册")
return
self.users.append(User(username, password))
print("注册成功")
def login(self, username, password):
for user in self.users:
if user.username == username:
if user.check_password(password):
print("登录成功")
return user
else:
print("密码错误")
return
print("该用户不存在")
# 用户信息维护页面
class UserInfoPage:
def __init__(self, user):
self.user = user
def change_password(self, old_password, new_password):
if self.user.check_password(old_password):
self.user.password = new_password
print("修改密码成功")
else:
print("原密码错误")
# 图书借阅管理页面
class BookBorrowPage:
def __init__(self):
self.books = []
self.borrowed_books = {}
def add_book(self, book_name):
self.books.append(book_name)
print("添加图书成功")
def borrow_book(self, user, book_name):
if book_name in self.books:
self.books.remove(book_name)
self.borrowed_books[user.username] = book_name
print("借阅成功")
else:
print("该图书已被借走或不存在")
def return_book(self, user):
if user.username in self.borrowed_books:
book_name = self.borrowed_books[user.username]
self.books.append(book_name)
del self.borrowed_books[user.username]
print("归还成功")
else:
print("您没有借阅任何图书")
```
以上代码实现了用户类、登录注册页面类、用户信息维护页面类和图书借阅管理页面类,这些类可以组合成一个完整的图书借阅管理系统。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)