# include & lt string & gt
Use namespace std
Class Book // Set the book collection category and seal the book information.
{
Public:
Book (string n, int N, string p) // Book class constructor.
{
name = n; //Set the title of the book
NO = N; //Set book inventory
publisher = p; //Set up a book publishing house
}
Void display() //display function displays book information.
{
Cout & lt& lt "Title:"
Cout & lt& lt "Current inventory:"
Cout & lt& lt "Book Publishing House:"
cout & lt& ltendl
}
//For the convenience of calling, the following data are defined as public.
String name; //Book title
Int number; //Book inventory
String publisher; //Book Publishing House
};
//Create a small database of library books, and the book serial number is equal to the subscript of the object array.
Book [6] =
{
Book (Introduction to C++, 3, People's Posts and Telecommunications Publishing House),
Book (Python Core Programming, 3, People's Posts and Telecommunications Publishing House),
Books (Writing Clean Codes, 3, Electronic Industry Press),
Book (Simplified Chinese Solaris 10 User Guide, 3, "Sun Microsystems"),
This book (C Programming Language Second Edition, Volume 3, Machinery Industry Press),
Book (Computer Programming Art, 3rd Edition, Volume 1: Basic Algorithms, Volume 3, National Defense Industry Press).
};
Void display_all() // Displays all the books in the library for readers' convenience.
{
int I;
Cout & lt& lt "This is all the books in the library"
for(I = 0; I<6; i++)
{
Cout & lt& lt "Book serial number:"
Cout & lt& lt "Title:"
Cout & lt& lt "Current inventory:"
Cout & lt& lt "Book Publishing House:"
cout & lt& ltendl
}
}
Class personage
{
Public:
People (String Nam, int num)// student constructor.
{
name = nam
number = num
}
void borrow(int); //Define the borrowing member function
void back(int); //Define the book return member function.
Private:
String name; //Sexual name
Int number; //Number of books borrowed from the library
};
//Student class, used to define student information.
Class students: public figures
{
Public:
Student (String Nam, Intnum, Intgra): people (Nam, num)// student constructor.
{
grade = gra
}
Private:
Int grade; //Student scores
};
//Teachers, teachers are students' derived classes.
Class teacher: public figure
{
Public:
Teacher (String Nam, Intnum, String T): people (Nam, num)// Derived class constructor.
{
title = t; //Teachers' titles
}
Private:
String title; //Teachers' titles
};
Void people :: borrow (int a) // Borrow a member function.
{
int i,j; //Define two integer variables so that the shirt can be used.
char k; //Defines the character variable for Y/N judgment.
void service(); //Declare a service function
if(number & gt; = a) // First of all, judge authority. If the number of books borrowed by the reader is not less than his authority, it will prompt other operations.
{
Cout & lt& lt "According to your authority, you can borrow the book at most" <<a<& lt "! You can't borrow books now. Please come again next time "< & ltendl"
Cout & lt& lt "Do you want to do something else? (Yes, please enter y, exit, please enter n) "
CIN & gt; & gtk;
If (k == 12 1)
service();
If (k == 12 1)
Return;
else if (k = 1 10)
Return;
cout & lt& ltendl
}
other
{
display _ all(); //Call the display_all function to output all books for readers to borrow.
Cout & lt& lt "Which book do you want to borrow? Please enter the book serial number 0-5 "
CIN & gt; & gt me;
While (book [i]. No = = 0 ||| I>5 || I & lt0) // Judge the legality of the inventory and input of books to be borrowed.
{
Cout & lt& lt "The book serial number you entered is wrong or the stock of borrowed books is insufficient. Please re-enter. Book serial number is 0-5 "< < endl
CIN & gt; & gt me;
//Prompt the reader whether to perform other operations.
Cout & lt& lt "Do you want to do something else? (Yes, please enter y to continue borrowing books, please enter n) "< <; endl
CIN & gt; & gtk;
If (k == 12 1)
service(); //If the reader wants to do other operations, reference the service function to restart the reader.
If (k == 12 1)
Return; //After other operations, jump out of the borrowing function directly.
other
Continue; //If readers choose to keep borrowing books, they will jump out of this cycle and enter the next cycle.
}
Cout & lt& ltendl// For the beauty of man-machine interface, it's ok here.
Cout & lt& lt "Here is the information about the book you want to borrow."
Book [me]. Display ();
Cout & lt& lt "How many books do you want to borrow?" & lt& ltendl
CIN & gt; & gtj;
//Judge the reader's authority, inventory and legality of input.
While ((a number)<j || book [i]. No<j | | j<0 | | j>3)
{
Cout & lt& lt "Because you don't have enough rights, the quantity is entered incorrectly or the library is out of stock,";
Cout & lt& lt "You can't borrow so many books at present! Please enter a suitable number. < & ltendl
CIN & gt; & gtj;
//Prompt the reader whether to perform other operations.
Cout & lt& lt "Do you want to do something else? (Yes, please enter y to continue borrowing books, please enter n) "< <; endl
CIN & gt; & gtk;
If (k == 12 1)
service();
If (k == 12 1)
Return;
other
Continue;
cout & lt& ltendl
}
Book [me]. NO = book[i]。 NO-j; //Reorganize the small database of the library after borrowing books.
number = number+j; //After borrowing books, the readers' borrowing times should be added to the current borrowing times.
cout & lt& ltendl
Cout & lt& lt "You can also borrow it from the library" <<a number & lt& lt "This book"
Cout & lt& lt《》& lt& lt book [me]. Name < ""< "Current surplus"
}
}//End of borrowing function
Void people::back (int a) // returns the book member function.
{
int n,m;
char k;
void service();
Cout & lt& lt "Which book do you want to return" < & ltendl
CIN & gt; & gtn;
While (book [n]. NO = 3) // Judging that the library stock is full, then no one borrows this kind of book from here and no one returns it.
{
Cout & lt& lt "Have you borrowed this book? Please re-enter the book serial number. " < & ltendl
CIN & gt; & gtn;
Cout & lt& lt "Do you want to do something else? (Yes, please enter y to continue returning the book, please enter n) "< <; endl
CIN & gt; & gtk;
If (k == 12 1)
service();
If (k == 12 1)
Return;
other
Continue;
cout & lt& ltendl
}
while(n & gt; 5 | | n & lt0) // Judge whether the books borrowed by readers exist.
{
Cout & lt& lt "The book serial number you entered is wrong, please re-enter. The book serial number is 0-5. " < & ltendl
CIN & gt; & gtn;
Cout & lt& lt "Do you want to do something else? (Yes, please enter y to continue returning the book, please enter n) "< <; endl
CIN & gt; & gtk;
If (k == 12 1)
service();
If (k == 12 1)
Return;
other
Continue;
cout & lt& ltendl
}
Cout & lt& ltendl// The line break here is for the beauty of man-machine interface.
Cout & lt& lt "Here is the information about the book you want to borrow."
Books. Display ();
Cout & lt& lt "How many books do you want to return" < & ltendl
CIN & gt; & gtm;
//Judge whether the stock of this kind of books in the library is less than the number of books that the reader wants to return, and whether the reader's input is legal.
While ((3-book[n]. No)<m | | m>3)
{
Cout & lt& lt "Have you borrowed so many books? Please re-enter it. "
CIN & gt; & gtm;
Cout & lt& lt "Do you want to do something else? (Yes, please enter y to continue borrowing books, please enter n) "< <; endl
CIN & gt; & gtk;
If (k == 12 1)
service();
If (k == 12 1)
Return;
else if (k = 1 10)
Continue;
cout & lt& ltendl
}
Books. NO+= m; //Organize the library database in time after returning the books.
Number-= m; //Readers borrowed books to reduce the number of books returned now.
//Here are some tips for readers.
Cout & lt& lt "Congratulations! You returned the book successfully! " & lt& ltendl
Cout & lt& lt "You can still borrow it"
}//End of back function
Void service()// service function, which completes the service and query function for readers.
{
int a;
int b;
Student Stud (Ming, 0, 2007); //Define the object stu of the student class and initialize it.
Teacher tea ("Li", 0, "Assistant"); //Define the teacher class object tea and initialize it.
//Ask the reader's identity and give options.
Cout & lt& lt "Welcome to the library. May I ask your identity: (please enter the first number) "< & ltendl"
Cout & lt& lt" 1. Teacher "
Cout & lt& lt"2. Students "
CIN & gt; & gta;
And (a! = 1。 & Answer! = 2) // Remind the reader of the input error.
{
Cout & lt& lt "Please enter the correct option:"
CIN & gt; & gta;
}
cout & lt& ltendl
Cout & lt& lt "What do you want: (Please enter the first number)" < & ltendl// Ask the reader what he wants to do and give the options.
Cout & lt& lt" 1. Borrow books "
Cout & lt& lt"2. Return the book "
Cout & lt& lt"3. Leave the borrowing desk "
CIN & gt; & gtb;
And (b! = 1。 & ampb! = 2 & amp& ampb! = 3) // Remind the reader of the input error.
{
Cout & lt& lt "Please enter the correct option"
CIN & gt; & gtb;
}
cout & lt& ltendl
If (a == 1) // If the reader is a teacher, please do the following.
{
if (b == 1)
{
tea . borrow(6); //Call the book borrowing function
}
else if (b == 2)
{
tea . back(6); //Call the book return function
}
other
{
Cout & lt< "= _ = Thank you for coming! \ n "<& ltendl// Exit
}
}
Else if (a == 2) // If the reader is a student, do the following.
{
if (b == 1)
{
stud . borrow(4);
}
else if (b == 2)
{
Shoe stud back (4);
}
other
{
Cout & lt< "= _ = Thank you for coming! \ n " & lt& ltendl
Return;
}
}
cout & lt& ltendl
}//End of service function
//main function
int main()
{
char k;
service();
While (1)/After the operation, the reader is prompted whether to perform other operations.
{
Cout & lt& lt "Do you want to continue with other operations?" ;
Cout & lt& lt "(Please enter Y for other operations and N for exit)"
CIN & gt; & gtk;
cout & lt& ltendl
If (k == 12 1)
service();
other
Cout & lt< "= _ = Thank you for coming! \ n " & lt& ltendl
Break;
}
Returns 0;
}