您现在的位置是:首页 > 编程 > 

图书管理系统

2025-07-20 07:30:56
图书管理系统 图书管理系统-python语言​简介:这个题的原题是需要C++来写的,然后C++的完整代码我放在了这个博客:图书目录管理系统(C++),然后我用python在模拟一个过程的,没有完全按照题目来做,比较简单,后面补加一个链接了数据库的版本。题目原型:请设计一个简单的图书目录管理系统(初级版)。图书目录信息包括:统一书号(不超过1字符) 书名(不超过0字符) 作者(不超过20字符)

图书管理系统

图书管理系统-python语言

简介

这个题的原题是需要C++来写的,然后C++的完整代码我放在了这个博客:图书目录管理系统(C++),然后我用python在模拟一个过程的,没有完全按照题目来做,比较简单,后面补加一个链接了数据库的版本。

题目原型

请设计一个简单的图书目录管理系统(初级版)。

图书目录信息包括:

统一书号(不超过1字符)

书名(不超过0字符)

作者(不超过20字符)

出版社(不超过0字符)

出版日期(包括:年、月、日)

价格(精确到分)

注意:为了保证运行窗口能正确地显示,请右击运行窗口,修改“属性”:

在“选项”选项卡中,选中“使用旧版本控制台”

在“字体”选项卡中,选择“8×16”“点阵字体”

在“布局”选项卡中,将屏幕窗口宽度均设为“120”。

具体需求如下:

显示如下的主菜单:

Append Find Remove Modify Show Quit > _

如果用户输入 A 或 a、F 或 f、R 或 r、M 或 m、S 或 s,则可完成相应的操作。如果用户输入其它字符,则显示错误信息。

程序将反复显示主菜单,让用户持续工作。如果用户输入 Q 或 q,则程序结束。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > Q
Thank you! Goodbye!

若用户输入其它字符,则显示错误信息。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > B
Incorrect choice!
Append Find Remove Modify Show Quit > 9
Incorrect choice!
Append Find Remove Modify Show Quit > +
Incorrect choice!

若用户输入 A 或 a,则可以输入新书的信息,将其添加到图书目录中。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > a
     ISB: 978049227148
    Title: The Call of the Wild
   Author: Jack London
Publisher: Scholastic Press
 Pub date: 2001/1/1
    Price: 9.4
Append Find Remove Modify Show Quit > A
     ISB: 9781772262902
    Title: Oliver Twist
   Author: Charles Dickens
Publisher: Engage Books
 Pub date: 2016/9/15
    Price: 648
Append Find Remove Modify Show Quit > a
     ISB: 9787515911076
    Title: The Call of the Wild
   Author: Jack London
Publisher: Aerospace Publishing House
 Pub date: 2016/5/1
    Price: 29.8

若用户输入的日期信息不正确,则显示错误信息,并要求用户重新输入。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > A
     ISB: 9787501592401
    Title: The Old Man and the Sea
   Author: Ernest Hemingway
Publisher: Knowledge Press
 Pub date: 2016/2/0
Incorrect date! Please reenter: 2016/6/1
Incorrect date! Please reenter: 2016/8/1
    Price: 25.8

若用户输入 S 或 s,则按书号升序排序,然后列表显示全部图书。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > S
ISB--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
978049227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    9.40
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80

若用户输入 F 或 f,则输入书名,然后显示该书名的图书。如果没有对应的图书,则显示错误信息。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > F
Title: The Call of the Wild
ISB--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
978049227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    9.40
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > f
Title: Gulliver's Travels
ot found!

说明:输出查结果时,不作排序操作。

若用户输入 R 或 r,则输入书号,然后将删除该书号的图书。如果没有对应的图书,则显示错误信息。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > r
ISB: 9781772262902
Remove(y/n)? n
Append Find Remove Modify Show Quit > S
ISB--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
978049227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    9.40
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > R
ISB: 978049227148
Remove(y/n)? Y
Append Find Remove Modify Show Quit > s
ISB--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > r
ISB: 9787515914145
ot found!
Append Find Remove Modify Show Quit > s
ISB--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80

要求:用户回答是否删除时,必须回答 Y 或 (大小写均可)。如果是其它字符,则显示错误信息,要求用户重新回答。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > R
ISB: 9781772262902
Remove(y/n)? k
Incorrect answer!
Remove(y/n)? $
Incorrect answer!
Remove(y/n)? 

若用户输入 M 或 m,则可以修改图书信息。首先按书号查,然后重新输入该图书的信息。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > m
ISB: 9787515911076
Modify(y/n)? y
     ISB: 9787544724968
    Title: The House on Mango Street
   Author: Sandra Heathneros
Publisher: Yilin Press
 Pub date: 2012/1/1
    Price: 0
Append Find Remove Modify Show Quit > M
ISB: 9787501592401
Modify(y/n)? n
Append Find Remove Modify Show Quit > m
ISB: 9787515914145
ot found!
Append Find Remove Modify Show Quit > S
ISB--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787544724968 The House on Mango Street      Sandra Heathneros    Yilin Press                    2012/01/01    0.00

要求:用户回答是否修改时,必须回答 Y 或 (大小写均可)。如果是其它字符,则显示错误信息,要求用户重新回答。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > M
ISB: 9787544724968
Modify(y/n)? K
Incorrect answer!
Modify(y/n)? *
Incorrect answer!
Modify(y/n)? n

相关习题:图书目录管理系统(高级版)。

代码语言:javascript代码运行次数:0运行复制
Append Find Remove Modify Show Quit > Thank you! Goodbye!
q

完整代码

代码语言:javascript代码运行次数:0运行复制
class Book:
    def __init__(self, ISB, title, author, publisher, pubdate, price):
        self.ISB = ISB
         = title
        self.author = author
        self.publisher = publisher
        self.pubdate = pubdate
        self.price = price
    def Print(self):
        # 打印book的各个属性
        print(self.ISB + " " +  + " " + self.author + " " + self.publisher + " " + self.price)

class BookLibrary:
    def __init__(self):
        self.library = []
    def add(self):
        print("请输入你需要添加的书的信息:")
        # 创建Book对象
        book = Book(one, one, one, one, one, one)
        book.ISB = input("ISB:")
         = input("Title:")
        book.author = input("Author:")
        book.publisher = input("Publisher:")
        book.pubdate = input("Pubdate:")
        book.price = input("Price:")
        self.library.append(book)
    # 更新书本
    def update(self):
        ISB = input("请输入你需要更新的书本的ISB:")
        book = self.findByISB(ISB)
        if book == one:
            print("没有到这本书")
            return
        print("输入新的书本的信息:")
        book.ISB = input("ISB:")
         = input("Title:")
        book.author = input("Author:")
        book.publisher = input("Publisher:")
        book.pubdate = input("Pubdate:")
        book.price = input("Price:")
    def delete(self):
        ISB = input("请输入你需要删除的书本的ISB:")
        book = self.findByISB(ISB)
        if book == one:
            print("没有到这本书")
            return
        self.library.remove(book)
    def selectAll(self):
        print("ISB----------Title----------Author----------Publisher----------Price")
        for book in self.library:
            book.Print()
    # 按照ISB查询
    def findByISB(self, ISB):
        for book in self.library:
            if book.ISB == ISB:
                return book
        else: # 这是没有查询到的情况
            return one


if __name__=="__main__":
    # 创建一个图书馆
    booklirary = BookLibrary()
    # 测试添加
    booklirary.add()
    # 测试查询
    booklirary.selectAll()
    # 测试更新
    booklirary.update()
    booklirary.selectAll()
    # 测试删除
    booklirary.delete()
    booklirary.selectAll()
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:202-02-20,如有侵权请联系 cloudcommunity@tencent 删除findself测试pythonappend

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/biancheng/1145506.html

相关标签:无
上传时间: 2025-07-19 12:32:43
留言与评论(共有 9 条评论)
本站网友 穿越时空的思念
16分钟前 发表
Knowledge Press Pub date
本站网友 哪里整容好
20分钟前 发表
") book = self.findByISB(ISB) if book == one
本站网友 过劳肥
23分钟前 发表
要求用户重新回答
本站网友 文具行业
1分钟前 发表
") def delete(self)
本站网友 qisuu
22分钟前 发表
并要求用户重新输入
本站网友 shf
17分钟前 发表
9787515911076 Modify(y/n)? y ISB
本站网友 悦动报价
1分钟前 发表
R 或 r
本站网友 淘金王
14分钟前 发表
则显示错误信息