AUT10 可以查找修改记录\找透明表

ST05 也可以有这种功能。但对于修改记录新值来找表,这个AUT10更直接。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
这是一道比较典型的数据库应用题目,需要使用文件读写和基本的数据操作知识。下面是一个简单的实现思路: 1. 读取user.txt文件中的用户信息,存储到一个字典中,用于登录验证和修改密码。 2. 读取book.txt文件中的图书信息,存储到一个列中。 3. 实现登录验证功能,最多可以尝试3次,如果用户名或密码不正确则提示用户重新输入。 4. 登录成功后显示主菜单,根据用户的角色(role)显示不同的选项。 5. 如果用户角色是管理员,则可以进行图书信息的添加、修改和删除操作。如果是普通用户,则只能进行借书和还书操作。 6. 图书信息的添加、修改和删除操作需要对book.txt文件进行读写。可以使用csv模块来实现,也可以使用普通的文本文件读写。 7. 借书和还书操作需要对一个借阅记录文件进行读写,可以使用csv模块来实现。借阅记录文件的格式为:用户名,图书编号,图书名,作者,借阅时间。 8. 修改密码功能需要对user.txt文件进行读写。 9. 导出图书信息功能需要将book.txt文件的内容输出到一个新的文件中,可以使用csv模块来实现。 10. 程序退出前需要保存所有的数据到相应的文件中。 下面是一个简单的Python代码示例,仅供参考: ```python import csv def read_users(filename): users = {} with open(filename, 'r') as f: reader = csv.reader(f) for row in reader: username, password, name, role = row users[username] = {'password': password, 'name': name, 'role': role} return users def write_users(filename, users): with open(filename, 'w') as f: writer = csv.writer(f) for username, info in users.items(): password = info['password'] name = info['name'] role = info['role'] writer.writerow([username, password, name, role]) def read_books(filename): books = [] with open(filename, 'r') as f: reader = csv.reader(f) for row in reader: bid, bname, author = row books.append({'bid': bid, 'bname': bname, 'author': author}) return books def write_books(filename, books): with open(filename, 'w') as f: writer = csv.writer(f) for book in books: bid = book['bid'] bname = book['bname'] author = book['author'] writer.writerow([bid, bname, author]) def read_records(filename): records = [] with open(filename, 'r') as f: reader = csv.reader(f) for row in reader: username, bid, bname, author, date = row records.append({'username': username, 'bid': bid, 'bname': bname, 'author': author, 'date': date}) return records def write_records(filename, records): with open(filename, 'w') as f: writer = csv.writer(f) for record in records: username = record['username'] bid = record['bid'] bname = record['bname'] author = record['author'] date = record['date'] writer.writerow([username, bid, bname, author, date]) def login(users): for i in range(3): username = input('请输入用户名:') password = input('请输入密码:') if username in users and users[username]['password'] == password: print('登录成功!') return username, users[username]['role'] else: print('用户名或密码不正确,请重新输入。') print('登录失败!') return None, None def add_book(books): bid = input('请输入图书编号:') bname = input('请输入图书名称:') author = input('请输入作者名称:') books.append({'bid': bid, 'bname': bname, 'author': author}) print('添加图书成功!') def modify_book(books): bid = input('请输入要修改的图书编号:') for book in books: if book['bid'] == bid: book['bname'] = input('请输入新的图书名称:') book['author'] = input('请输入新的作者名称:') print('修改图书成功!') return print('没有到该图书编号!') def delete_book(books): bid = input('请输入要删除的图书编号:') for book in books: if book['bid'] == bid: books.remove(book) print('删除图书成功!') return print('没有到该图书编号!') def borrow_book(username, books, records): bid = input('请输入要借阅的图书编号:') for book in books: if book['bid'] == bid: bname = book['bname'] author = book['author'] records.append({'username': username, 'bid': bid, 'bname': bname, 'author': author, 'date': '借阅时间'}) print('借阅图书成功!') return print('没有到该图书编号!') def return_book(username, records): bid = input('请输入要归还的图书编号:') for record in records: if record['username'] == username and record['bid'] == bid: record['date'] = '归还时间' print('归还图书成功!') return print('没有到该图书编号或您没有借阅过该图书!') def modify_record(username, records): bid = input('请输入要修改的图书编号:') for record in records: if record['username'] == username and record['bid'] == bid: record['date'] = input('请输入新的借阅时间或归还时间:') print('修改借阅记录成功!') return print('没有到该图书编号或您没有借阅过该图书!') def search_record(username, records): for record in records: if record['username'] == username: print(record) def main(): users = read_users('user.txt') books = read_books('book.txt') records = read_records('record.csv') username, role = login(users) if username is None: return while True: print('====图书借阅管理系统====') print('1.读取图书信息') if role == '管理员': print('2.添加图书信息') print('3.修改图书信息') print('4.删除图书信息') elif role == '用户': print('5.借阅图书') print('6.归还图书') print('7.修改借阅记录') print('8.查找借阅记录') print('9.显示借阅记录') print('10.修改登录密码') print('11.导出图书信息') print('12.退出') choice = input('请选择(1-12):') if choice == '1': for book in books: print(book) elif choice == '2' and role == '管理员': add_book(books) elif choice == '3' and role == '管理员': modify_book(books) elif choice == '4' and role == '管理员': delete_book(books) elif choice == '5' and role == '用户': borrow_book(username, books, records) elif choice == '6' and role == '用户': return_book(username, records) elif choice == '7' and role == '用户': modify_record(username, records) elif choice == '8' and role == '用户': search_record(username, records) elif choice == '9' and role == '用户': for record in records: if record['username'] == username: print(record) elif choice == '10': new_password = input('请输入新的密码:') users[username]['password'] = new_password write_users('user.txt', users) print('修改密码成功!') elif choice == '11': write_books('book_out.csv', books) print('导出图书信息成功!') elif choice == '12': write_users('user.txt', users) write_books('book.txt', books) write_records('record.csv', records) print('程序退出!') break if __name__ == '__main__': main() ``` 注意:上述代码仅供参考,还有很多细节和错误处理需要完善。实际应用中,还需要考虑并发访问、数据安全、备份恢复等问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SAP路人甲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值