#include
#include
#include
#include
#include
using namespace std;
# define BOOK 100
//book information
Struct the Book
{int book_no.//book number
Char name [30].//title
Char author [20].//the author
Char press [20].//press
Char date [15].//date of publication: YYYY - MM - DD
Char kind [15].//book category
Double price.//book price
Int total;//number of books
};
//book
The class book
{
Private:
The Book bo_array [Book];//books array
Int booknum;//the current record books
Public:
The book ();
~ the book ();
Void menu ();
Int get_booknum ();//get the current record books
Void input ();
Void the search ();//find
void update();
Void the show ();
Void delete_ ();
Void the load_file ();
Void save_file ();
};
Book: the book ()
{
Booknum=0;
}
The book: : ~ the book ()
{
}
Int the book: : get_booknum ()
{
Return booknum;
}
Void book: : menu ()
{
Int choice;
system("cls");
Cout<& lt;" Books management system management system "& lt;
Cin> Choice;
If (choice>=0 & amp; & Choice<7)
{
The switch (choice)
{
Case 1:
The input ();
break;
Case 2:
Show ();
break;
Case 3:
Search ().
break;
Case 4:
The update ();
break;
Case 5:
Delete_ ();
break;
Case 6:
Save_file ();
Cout<& lt;" Thank you for your use, the system has quit, bye!"
The exit (0);
}
}
The else
{
Cout<& lt;" Input is wrong! Please input again!"
}
Int main ()
{
The book book1.
While (1)
{
Book1. Menu ();
}
return 0;
}
Void book: : input ()
{
The Book boo;
Get_booknum ();
While (1)
{
system("cls");
Cout<& lt;" Please enter the below (add) book information: "& lt;
If (boo. Book_no==0)
return;
Cin> Boo. Book_no & gt;> Boo. Name> Boo. Author> Boo. Press> Boo. Date;
Cout<& lt;" Please enter the book category, book price (unit: yuan), number of books: "& lt;
Bo_array [booknum]=boo;
Booknum++;
}
}
Void book: the load_file ()
{
The Book boo;
Ifstream infile.
Get_booknum ();
Infile. Open (" bookfile. TXT ", the ios: : in);
if(! Infile)
{
Cout<& lt;" No data file bookfile. TXT!" ;
Sleep (3000);
Booknum=0;
return;
}
while(! Infile. Eof ())
{
Infile> Boo. Book_no & gt;> Boo. Name> Boo. Author> Boo. Press> Boo. Date> Boo. Kind> Boo. Price> Boo. Total;
If (infile)
{
Bo_array [booknum]=boo;
Booknum++;
}
The else
break;
}
Infile. Close ();
return;
}
Void book: : save_file ()
{
Ofstream outfile;
Get_booknum ();
Outfile. Open (" bookfile. TXT ", the ios: : out);
if(! Outfile)
{
Cout<& lt;" Unable to save data to a file bookfile. TXT in!"
return;
}
for(int i=0; I
Outfile
Outfile. Close ();
Cout<& lt;" Already will "& lt;
return;
}
Void book: the search ()
{
The Book boo;
Int bo_no;
Bool judge=0;
Cout<& lt;" Please input to query book number: "& lt;
Cout<& lt;" Results: "& lt;
If (bo_array [I] book_no==bo_no)
{
Judge=1;
Cout<& lt;" Book number title authors publishing date book category book price collection quantity & lt;"
Next:c