In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to realize a simple library management system with C++". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to implement a simple library management system with C++" can help you solve the problem.
The functions are as follows:
1, add books
2. Delete books (you can delete books that have not been borrowed yet)
3. Readers borrow books.
4, the reader returns the book
5, check the information by the book entry number (the book entry number of each book is unique, if there are 5 books with the same title, there are 5 different book entry numbers)
6. Query the information of all books (you can directly view the surplus and lending of the same book in the library)
7. Check the details of the books borrowed by the designated readers
8. Register new readers
9, view all book information (can be detailed to each login number and the borrowing status of this login number: for example, who borrowed it, the date of borrowing)
In the client and server mode, the server receives the client, enables the thread once it is received, and then responds to different requests from the client
Server end
ServerHead.h
# ifndef SERVERHEAD#define SERVERHEAD#include # pragma comment (lib, "ws2_32.lib") struct infoData {int flag; / / various commands int borFlag; / / loan situation 1 indicates loan, 0 indicates that char enterName [20] is not lent; / / Book entry number, one char bookName [50] / / Book title char bookNum [20]; / / Book number char bookWriter [50]; / / author int remainBook; / / original inventory char readerName [50]; / / borrower char readerNum [50]; / / Library Card char borrowTime [30]; / / Book borrowing time int remain / / the number of books left in the library int lend; / / the number of books borrowed from the library}; class Book_mysql {public: Book_mysql (); bool connectAndCreate (); / / Link to create database and table bool selectWhetherEmpty (); / / check whether it is an empty table bool testTheBookWhetherExist (const infoData& Data) / / judging the existence of bool insertTo (infoData & Data); / / inserting the book int deleteFrom (infoData & Data); / / deleting the corresponding book bool readerBorrowBook (infoData & Data); / / the reader borrowing int readerReturnBook (infoData & Data); / / returning the book bool whetherSurpass (infoData & Data) / to determine whether the borrowing limit is exceeded (a maximum of two books can be borrowed) bool selectBookByEntername (infoData & Data); / / query the book void displayInformation (infoData & Data, const SOCKET& sClient) through the book login number; / / print (general) void showTheReaderBook (infoData & Data, SOCKET& sClient); / / print void DISPLAY (infoData & Data, SOCKET& sClient) / / print (detailed) private: char user [30]; / / login name char pswd [10]; / / password char host [20]; / / indicates local database unsigned int port; / / port MYSQL myCont; MYSQL_RES * result MYSQL_ROW sql_row; int res;}; class Reader_mysql {public: Reader_mysql (); bool connectAndCreate (); bool testTheReaderWhetherExist (infoData & Data); / / check whether the reader already exists void insertTo (infoData & Data); / / register bool readerBorrowBook (); / / borrow book bool readerReturnBook (); / / return book private: char user [30] / / login name char pswd [10]; / / password char host [20]; / / indicates local database unsigned int port; MYSQL myCont; MYSQL_RES * result; MYSQL_ROW sql_row; int res;}; class serverSocket {public: serverSocket (int port); ~ serverSocket (); SOCKET serverAccpetSocket () / / blocking acceptprivate: WSADATA wsd; SOCKET sServer; / / client sockets are used to listen for std::list listScli; / / client sockets are received by linked lists, receive and send one by one and put a SOCKET temp; / / server address} to store the intermediate value SOCKADDR_IN addrServ; / / server address}; void addBook (infoData& Data, const SOCKET& sClient, Book_mysql & book_mysql) Void deleteBook (infoData& Data, const SOCKET& sClient, Book_mysql & book_mysql); void borrowBook (infoData& Data, const SOCKET& sClient, Book_mysql & book_mysql, Reader_mysql & reader_mysql); void returnBook (infoData& Data, SOCKET& sClient, Book_mysql & book_mysql, Reader_mysql & reader_mysql); void searchBook (infoData& Data, const SOCKET& sClient, Book_mysql & book_mysql); void displayAllBook (infoData& Data, SOCKET& sClient, Book_mysql & book_mysql) Void DISPLAY (infoData& Data, SOCKET& sClient, Book_mysql & book_mysql); void showTheReaderBook (infoData& Data, SOCKET& sClient, Book_mysql & book_mysql, Reader_mysql & reader_mysql); void setNewReader (infoData& Data, const SOCKET& sClient, Reader_mysql & reader_mysql); void clientSocketThreadFunction (SOCKET sClient); # endif
Implementation of socket class
ServerSocket.cpp
# include "serverHead.h" serverSocket::serverSocket (int port) {/ / initialize socket dynamic library if (WSAStartup (MAKEWORD (2,2), & wsd)! = 0) {std::cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.