设计一个书店管理系统,能完成书店的日常管理工作。 要求完成的基本功能: 1、进货入库记录。 2、销售出货记录。 3、图书信息查询:可通过书名、作者等途径查询某本图书的详细信息(含书名、作者、出版社、页数、最新入库时间、库存量、价格等)。 4、自动预警提示(当某图书的库存量为1时自动预警提示) 5、数据存储:以文件方式存储出入库记录 可自行补充其它功能。 说明与要求: 1、对象集合的管理可以使用STL中的相关容器类; 用c++语言给出代码

时间: 2023-07-04 17:05:16 浏览: 59
以下是一个简单的书店管理系统的代码,实现了基本功能: ```cpp #include <iostream> #include <string> #include <vector> #include <fstream> #include <ctime> using namespace std; // 图书信息 struct Book { string name; // 书名 string author; // 作者 string publisher; // 出版社 int pages; // 页数 time_t lastInTime; // 最新入库时间 int stock; // 库存量 double price; // 价格 }; // 进货记录 struct InRecord { string bookName; // 书名 int count; // 数量 time_t time; // 时间 }; // 出货记录 struct OutRecord { string bookName; // 书名 int count; // 数量 time_t time; // 时间 }; // 书店管理系统 class Bookstore { public: // 构造函数 Bookstore(); // 进货入库 void In(string name, int count, double price); // 销售出货 void Out(string name, int count); // 查询图书信息 void Query(string name); // 自动预警 void Warn(); // 显示所有图书信息 void ShowAll(); // 保存数据到文件 void SaveToFile(); // 从文件中读取数据 void LoadFromFile(); private: vector<Book> books; // 图书集合 vector<InRecord> inRecords; // 进货记录集合 vector<OutRecord> outRecords; // 出货记录集合 }; // 构造函数 Bookstore::Bookstore() { LoadFromFile(); } // 进货入库 void Bookstore::In(string name, int count, double price) { bool found = false; for (int i = 0; i < books.size(); i++) { if (books[i].name == name) { books[i].stock += count; books[i].price = price; books[i].lastInTime = time(NULL); found = true; break; } } if (!found) { Book book = {name, "", "", 0, time(NULL), count, price}; books.push_back(book); } InRecord inRecord = {name, count, time(NULL)}; inRecords.push_back(inRecord); SaveToFile(); } // 销售出货 void Bookstore::Out(string name, int count) { bool found = false; for (int i = 0; i < books.size(); i++) { if (books[i].name == name) { if (books[i].stock < count) { cout << "库存不足!" << endl; return; } books[i].stock -= count; found = true; break; } } if (!found) { cout << "图书不存在!" << endl; return; } OutRecord outRecord = {name, count, time(NULL)}; outRecords.push_back(outRecord); SaveToFile(); } // 查询图书信息 void Bookstore::Query(string name) { bool found = false; for (int i = 0; i < books.size(); i++) { if (books[i].name == name) { cout << "书名:" << books[i].name << endl; cout << "作者:" << books[i].author << endl; cout << "出版社:" << books[i].publisher << endl; cout << "页数:" << books[i].pages << endl; cout << "最新入库时间:" << asctime(localtime(&(books[i].lastInTime))); cout << "库存量:" << books[i].stock << endl; cout << "价格:" << books[i].price << endl; found = true; break; } } if (!found) { cout << "图书不存在!" << endl; } } // 自动预警 void Bookstore::Warn() { for (int i = 0; i < books.size(); i++) { if (books[i].stock == 1) { cout << "图书《" << books[i].name << "》库存不足,请及时进货!" << endl; } } } // 显示所有图书信息 void Bookstore::ShowAll() { for (int i = 0; i < books.size(); i++) { Query(books[i].name); } } // 保存数据到文件 void Bookstore::SaveToFile() { ofstream ofs("bookstore.dat"); ofs << books.size() << endl; for (int i = 0; i < books.size(); i++) { ofs << books[i].name << endl; ofs << books[i].author << endl; ofs << books[i].publisher << endl; ofs << books[i].pages << endl; ofs << books[i].lastInTime << endl; ofs << books[i].stock << endl; ofs << books[i].price << endl; } ofs << inRecords.size() << endl; for (int i = 0; i < inRecords.size(); i++) { ofs << inRecords[i].bookName << endl; ofs << inRecords[i].count << endl; ofs << inRecords[i].time << endl; } ofs << outRecords.size() << endl; for (int i = 0; i < outRecords.size(); i++) { ofs << outRecords[i].bookName << endl; ofs << outRecords[i].count << endl; ofs << outRecords[i].time << endl; } ofs.close(); } // 从文件中读取数据 void Bookstore::LoadFromFile() { ifstream ifs("bookstore.dat"); if (!ifs) { return; } int bookCount; ifs >> bookCount; books.resize(bookCount); for (int i = 0; i < bookCount; i++) { ifs >> books[i].name; ifs >> books[i].author; ifs >> books[i].publisher; ifs >> books[i].pages; ifs >> books[i].lastInTime; ifs >> books[i].stock; ifs >> books[i].price; } int inRecordCount; ifs >> inRecordCount; inRecords.resize(inRecordCount); for (int i = 0; i < inRecordCount; i++) { ifs >> inRecords[i].bookName; ifs >> inRecords[i].count; ifs >> inRecords[i].time; } int outRecordCount; ifs >> outRecordCount; outRecords.resize(outRecordCount); for (int i = 0; i < outRecordCount; i++) { ifs >> outRecords[i].bookName; ifs >> outRecords[i].count; ifs >> outRecords[i].time; } ifs.close(); } int main() { Bookstore bookstore; while (true) { cout << "1. 进货入库" << endl; cout << "2. 销售出货" << endl; cout << "3. 查询图书信息" << endl; cout << "4. 自动预警" << endl; cout << "5. 显示所有图书信息" << endl; cout << "0. 退出" << endl; int choice; cin >> choice; if (choice == 1) { string name; int count; double price; cout << "请输入书名:"; cin >> name; cout << "请输入数量:"; cin >> count; cout << "请输入价格:"; cin >> price; bookstore.In(name, count, price); } else if (choice == 2) { string name; int count; cout << "请输入书名:"; cin >> name; cout << "请输入数量:"; cin >> count; bookstore.Out(name, count); } else if (choice == 3) { string name; cout << "请输入书名:"; cin >> name; bookstore.Query(name); } else if (choice == 4) { bookstore.Warn(); } else if (choice == 5) { bookstore.ShowAll(); } else if (choice == 0) { break; } } return 0; } ``` 这个系统使用了 STL 中的 vector 容器类来管理图书、进货记录和出货记录。数据存储使用文件方式,每次操作后都会将数据保存到文件中,下次启动时会从文件中读取数据。

相关推荐

最新推荐

recommend-type

图书管理系统课程设计说明书.doc

数据结构课程设计设计一个计算机管理系统完成图书管理基本业务。设计内容如下: (1) 每种书的登记内容包括书号、书名、著作者、现存量和库存量; (2) 读者信息包括读者编号、姓名、借阅记录; (3) 对书号建立索引...
recommend-type

基于RFID的智能仓储管理系统的设计与实现

传统的仓储管理系统使用的是人工记录单据的方式,这种方式不但费时费力,还容易造成人为损失,而且劳动力成本高。针对以上问题,采用基于RFID技术的智能仓储系统的架构方案,设计了一套智能仓储系统。通过管理系统与...
recommend-type

数据库仓库管理系统课程设计

1.1 功能需求 该系统主要分为三大功能: 管理员功能、信息安全功能、一般用户...(4) 由于计算机能存贮大量的数据,而且数据只要一次存入,便可多次重复使用,所以管理数据达到完整,统一,原始记录能保证及时,准确。
recommend-type

VB.net书店管理系统

本系统具有书店管理系统的基本功能,如图书管理﹑入库管理﹑销售管理﹑综合查询﹑系统管理等。
recommend-type

计算机专业毕业设计软件销售管理系统

1.3软件销售管理系统的意义 3 2 可行性研究 4 2.1 可行性研究目的 4 2.2 经济可行性 4 2.3 技术可行性 4 2.4 运行可行性 5 2.5 法律可行性 5 3 需求分析 6 3.1 需求分析的意义 6 3.2 需求分析的具体任务 6 3.2.1 ...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

可见光定位LED及其供电硬件具体型号,广角镜头和探测器,实验设计具体流程步骤,

1. 可见光定位LED型号:一般可使用5mm或3mm的普通白色LED,也可以选择专门用于定位的LED,例如OSRAM公司的SFH 4715AS或Vishay公司的VLMU3500-385-120。 2. 供电硬件型号:可以使用常见的直流电源供电,也可以选择专门的LED驱动器,例如Meanwell公司的ELG-75-C或ELG-150-C系列。 3. 广角镜头和探测器型号:一般可采用广角透镜和CMOS摄像头或光电二极管探测器,例如Omron公司的B5W-LA或Murata公司的IRS-B210ST01。 4. 实验设计流程步骤: 1)确定实验目的和研究对象,例如车辆或机器人的定位和导航。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。