Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C++ to realize Library system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use C++ to implement a library system". The content is simple and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and learn this article "how to use C++ to implement a library system".

The details are as follows

1. Purpose

Implementation of Library system with C++ language

two。 Analysis.

The functions to be realized in the library system are: classified storage of books, different operations of personnel with different identities. In this program,

I divide books into two categories: novels and professional books, both of which have the same function, so set up a base class, which are different from each other.

Inherit the base class. There are two types of personnel: administrators and students, both of which have the same private data members, so set up a base class for personnel.

These two categories inherit the base class respectively. In the category of books, both novels and professional books should set up their own structural arrays to store the letters of books.

Information, at the same time, must have the function of adding books, deleting books, and searching books. The function of administrator class should have the function of adding all kinds of books and browsing all books.

Yes. Students should have the functions of searching, borrowing and returning books.

3. Code

/ / Library system # include#includeusing namespace std;typedef struct book / / basic information of structural definition books {string book_name; / / title of books / / author string kind; / / types of books} Book;class base / / Abstract classes {public: base (); virtual void deposit () = 0; / / Pure virtual function addition books virtual void display (string name) = 0 / / the pure virtual function displays the information of a book virtual void display () = 0; / / the pure virtual function displays the information of the book virtual int isauthor (string a) = 0; / / determines whether the author's book virtual bool isbookname (string b) = 0; / / determines whether the book exists by the title virtual void clearbook (string name) = 0;} Base::base () {} class novel:public base / / novel {public: novel (); / / constructor virtual void deposit (); / / add book virtual void display (); / / display book information virtual void display (string name); / / display information of a book virtual int isauthor (string a); / / determine whether the author's book virtual bool isbookname (string b) exists / / use the title to determine whether the book virtual void clearbook (string name) exists; / / delete a book private: int novelnumber; / / number of current books Book mynovel [50]; / / structural array containing information about fiction books Book * p; / / pointer of structural type}; novel::novel () {novelnumber = 0; p = mynovel; mynovel [0] .author = "1" Mynovel [0] .book _ name = "1"; mynovel [0] .kind = "novel"; novelnumber++; mynovel [1] .author = "2"; mynovel [1] .book _ name = "2"; mynovel [1] .kind = "novel"; novelnumber++; for (int I = 2witi)

< 50;i++) { mynovel[i].author = "0"; mynovel[i].book_name = "0"; } //初始化数组}void novel::clearbook(string name) //删除一本书{ Book* t; //结构类型指针 t = mynovel; //指向小说类的数组 while(t->

Book_name! = name) / / when the title of the book does not match, point to the next space {tcm;} if (t-> book_name = = name) / / when the book is found, clear {t-> author = "0"; t-> book_name = "0"; novelnumber-- / / Total number minus one}} void novel::deposit () / / books stored in fiction {Book* t; string temp_author; string temp_book_name; cout > temp_book_name; cout temp_author; / / record book information t = mynovel; while (t-> author! = "0") {tasking + } / / find empty storage space if (t-> author = = "0") {t-> author = temp_author; t-> book_name = temp_book_name; t-> kind = "novel"; novelnumber++;} / / if the storage space is empty, store the book information} void novel::display () / / display the book information {Book* t; int number = novelnumber Cout author = = "0") {t-> author = temp_author; t-> book_name = temp_book_name; t-> kind = "professional book"; pronumber++;}} void professional::display () / / displays this kind of book information {Book* t; int number = pronumber; 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report