Current location - Training Enrollment Network - Books and materials - A management system for writing books in C language.
A management system for writing books in C language.
# include & ltiostream & gt

# include & ltiomanip & gt

# include & lt string & gt

# include & ltfstream & gt

# include & ltstdio.h & gt

Use namespace std

const int Maxb = 10000; //The most books

Classroom books//books

{

Int label; //Delete tag 1: Deleted 0: Not deleted.

Int number; //ISBN number

char name[20]; //Book title

Char author [10]; //editor-in-chief

char number 2[ 10]; //version

Character position [20]; //Press

Charging time [20]; //year of publication

Int price; //Pricing

Int onshelf// is on shelf 1: on shelf 0: borrowed?

Public:

Book() {}

char * getname(){ return name; }//Get the name

int get number(){ return number; }//Get ISBN number

int gettag(){ return tag; }//Get delete tag

char * get author(){ return author; }//Get Editor-in-Chief

char * get number 2(){ return number 2; }//Get the version number

char * get position(){ return position; }//get the publishing house

char * gettime(){ return time; }//Get the publication year

char getprice(){ return price; }//Get book pricing Void delbook () {tag =1; }//Delete books

Void addbook (int n, char * na, char * au, char * N2, char * da, char * ti, int pr)// Add books.

{

tag = 0;

Number = n;;

Price = pr

Strcpy (name, not applicable);

Strcpy (author, AU);

Strcpy (number 2, N2);

Strcpy (location, da);

Strcpy (time, ti);

on shelf = 1;

} void disp() // output books

{

cout & lt& ltsetw( 10)& lt; & lt number & lt setw (10) < & lt name & lt& ltsetw( 10)

& lt& ltsetw( 10)& lt; & lt Author & lt< setw (10) < & lt number & lt< setw (10) < & lt location & lt< setw (10) < & lt time & lt setw (10) < & lt price & lt& ltendl

}

}; Class b database//library class

{

Int top// book record pointer

book book[Maxb]; //Book records

Public:

The BDatabase() // constructor reads book.txt into book[].

{

Book b;

top =- 1;

The fstream file ("book.txt", IOs:: in);

while ( 1)

{

file . read((char *)& amp; b,sizeof(b));

If (! File) interrupt;

top++;

book[top]= b;

}

file . close();

}

Void clear() // Delete All

{

top =- 1;

}

Intaddbook (int n, char * na, char * au, char * N2, char * da, char * ti, int pr)// Add books.

{

book * p = search 1(n);

if (p==NULL)

{

top++;

Book [top]. addbook(n,na,au,n2,da,ti,pr);

Returns1;

}

Returns 0;

}

Book * search1(int bookmark)//Find books.

{

for(int I = 0; I<= topi++)

If (book [me]. getnumber()= = bookid & amp; & amp

Book [me]. gettag()==0)

Return to & book [i];

Returns NULL

} book * search2 (int bookmark, char * name)// Search books by title.

{

for(int I = 0; I<= topi++)

If(strcmp (book [i]). getname(),name)==0)

{bookid=book[i]。 get number(); & ltbr & gt returns & book [i]; & ltbr & gt}

Returns NULL

} book * search3 (int bookid, char * author)// press the editor to search for books.

{

for(int I = 0; I<= topi++)

If(strcmp (book [i]). getauthor(),author)==0)

{bookid=book[i]。 get number(); & ltbr & gt returns & book [i]; & ltbr & gt}

Returns NULL

} void book data(); //Library maintenance

Invalid display ()

{

cout & lt& ltsetw( 10)& lt; & lt "Book Number"

for(int I = 0; I<= topi++)

If (book [me]. gettag()==0)

Book [me]. disp();

}

~BDatabase() // destructor, and write book[] into the book.txt file.

{

The fstream file ("book.txt", IOs:: out);

for(int I = 0; I<= topi++)

If (book [me]. gettag()==0)

file . write((char *)& amp; book[i],sizeof(book[I]);

file . close();

}

}; void BDatabase::bookdata()

{

int choice = 1;

int choice 2 = 1;

int choice 3 = 1;

int choice4

char bname[40];

A character editor [40];

char banci[40];

Charging position [40];

char year[40];

Int value;

int bookid

Book * b;;

And (choose! =0)

{

cout & lt& ltendl & lt& ltendl

cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *”& lt; & ltendl

Cout & lt< "* *1add a book * * * * *”& lt;; & ltendl

Cout & lt< "* * * Three Delete Books * * *"

Cout & lt< "* * * 4 book query * * *"

Cout & lt< "* * * 5 shows this book * * *"

Cout & lt< "* * * 6 Delete all * * * * *”& lt;; & ltendl

Cout & lt< "* * * 7 Borrowing books * * *"

Cout & lt< "* * * 8 Return the book * * *"

Cout & lt< "* * * 0 exits * * * * *”& lt;; & ltendl

cout & lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *”& lt; & ltendl & lt& ltendl

Cout & lt& ltendl & lt& lt "Please press the key to select the operation you need:";

CIN & gt; & gt selection;

And (choose! = 1。 & choose! = 2 & choose! = 3&& choose! = 4 & choose! = 5 & choose! = 6 & choose! =0){

The number you entered does not exist in cout & lt& ltendl & lt& lt“* * menu, please re-enter * * *”& lt;; & lt\ a ' & lt& ltendl & lt& ltendl

Cout & lt& lt "Please select the operation you need:";

CIN & gt; & gt selection;

}

Switch (selection)

{

Case 1:

Cout & lt& lt "Enter ISBN (it must be a number, otherwise it will be abnormal):";

CIN & gt; & gtbookid

Cout & lt& lt "Enter a title:";

CIN & gt; & gtbname

Cout & lt& lt "input editor:";

CIN & gt; & gt Editor;

Cout & lt& lt "Enter the version (it must be a number, otherwise it will be abnormal):";

CIN & gt; & gt Banchi;

Cout < < "Enter the publisher:";

CIN & gt; & gt location;

Cout & lt& lt "Enter the publication year (it must be a number, otherwise it will be abnormal)";

CIN & gt; & gt year;

Cout & lt& lt "Enter the price (it must be a number, otherwise it will be abnormal):";

CIN & gt; & gt value;

addbook(bookid,bname,editor,banci,position,year,value);

Cout & lt< "ISBN" < & ltbookid & lt "added successfully. If you want to return to the main menu, press 1 to exit the system, press 0 (be sure to enter a number)";

CIN & gt; & gt Select 4;

While (choose 4! = 0 & choose 4! = 1)

{

Cout & lt& lt is entered incorrectly, please re-enter.

CIN & gt; & gt Select 4; }

Switch (option 4)

{

Case 1:

choice = 1;

Break;

Case 0:

choice = 0;

Break; } broken;

Case 3:

Cout < < "Enter ISBN:";

CIN & gt; & gtbookid

b = search 1(bookid);

if (b==NULL)

{

Cout & lt& lt "This book doesn't exist"

Break;

}

b-& gt; del book();

Break;

Case 4:

Cout & lt& lt "Search method:"

CIN & gt; & gt option 3;

Switch (option 3)

{

Case 1:

{cout & lt& lt "Enter ISBN:"; //query by ISBN number < br & gtCIN & gt;; & gtbookid& ltbr & gtb = search 1(bookid); & ltbr & gtif(b = = NULL)& lt; Br>{ & ltbr & gtcout & lt& lt "This book doesn't exist"

b-& gt; disp();

}

Break;

Case 2:

{

Cout & lt& lt Please enter a title: ";

CIN & gt; & gtbname

b=search2(bookid,bname);

if(b==NULL)

{

Cout & lt& lt "This book doesn't exist!" & lt& ltendl

Break;

}

b-& gt; disp();

}

Break;

Case 3:

{

Cout & lt& lt "Please enter editor in chief:";

CIN & gt; & gt Editor;

b=search3(bookid,editor);

if(b==NULL)

{

Cout & lt& lt "The editor-in-chief does not exist!" & lt& ltendl

Break;

}

b-& gt; disp();

}

Break;

}

Break;

Case 5:

disp();

Break;

Case 6:

clear();

Break;

} }

Cout & lt& ltendl & lt& lt“* * * * * Go slow * * * * "< < endl & lt& ltendl & lt& ltendl

};

int main()

{

B database BookDB

cout & lt& ltendl & lt& ltendl & lt& ltendl

Cout & lt& lt "Welcome to SCU Library" & ltendl

Cout & lt& lt "Welcome to Sichuan University Library" < & ltendl

Cout & lt& ltendl & lt& ltendl & lt& lt "Please enter 0 to enter the library"

int w;

CIN & gt; & gtw;

If (w==0)

bookdb . book data();

System ("suspended");

Returns 0;

}