# include & ltstdlib.h & gt
# include & ltstring.h & gt
# include & ltconio.h & gt
Int count;
Structural book
{
Character number [11];
char bname[2 1];
char wname[9];
char pubname[2 1];
char pub time[7];
Floating price;
} books [100];
// -
Invalid input ()
{
int x;
System ("CLS");
Printf ("\ n \ n \ tEnter book information! Book information includes book number, title, author, publisher, price and publication time \ n \ n ");
do
{
printf(" \ t ISBN:");
Scanf("%s ",books [count]. num);
printf(" \ n \ t title:");
Scanf("%s ",books [count]. bname);
printf(" \ n \ t author:");
Scanf("%s ",books [count]. wname);
printf(" \ n \ t Press:");
Scanf("%s ",books [count]. pubname);
Printf ("\ n \ tPublication date:");
Scanf("%s ",books [count]. pub time);
printf(" \ n \ t price:");
Scanf("%f ",& books [count]. Price);
Printf ("\ n \ tPress 0 to end the input and 1 to continue: \ n");
scanf("%d ",& ampx);
count++;
} while(x);
Printf ("\ nEnd of input! \ n ");
}
// -
Invalid output ()
{
int j;
System ("CLS");
Printf ("ISBN \ ttitle \ tpublished house \ tpublished time and price \ n");
for(j = 0; J< counting; j++)
{
Printf ("%-10s%-8s%-8s%-2.1f \ n", books[j].num, books [j]. bname,books[j]。 wname,books[j]。 Pubname, books [j]. Pubtime, books [j]. Price);
}
getchar();
}
// -
Invalid save ()
{
int j;
FILE * fp
System ("CLS");
Printf ("\ nYou can view the book information in books.dat \ n");
if((fp=fopen("books.dat "," a+")= = NULL)
{
Printf ("Disk Full \ n");
Exit (0);
}
Fprintf(fp, "The following data are: ISBN, title, author, publication time, price \ n");
for(j = 0; J< counting; j++)
{
fprintf(fp," %-8s %- 10s %-8s %-8s %-8. 1f \ n ",books[j]。 Num, books [j]. bname,books[j]。 wname,books[j]。 Pubname, books [j]. Pubtime, books [j]. Price);
}
fclose(FP);
Printf ("Book information saved \ n");
}
// -
void readfile()
{
FILE * fp
char ch
System ("CLS");
Printf ("\ nView book information in books.dat \ n");
fp=fopen("books.dat "," r ");
If (fp = = null) printf ("\ nFile not found! \ n ");
other
while ((ch=fgetc(fp))! =EOF)
putchar(ch);
fclose(FP);
}
// -
void add()
{
int x;
System ("CLS");
Printf ("\ n \ n \ tAdd book information! Book information includes book number, title, author, publisher, price and publication time \ n \ n ");
while(x)
{
printf(" \ t ISBN:");
Scanf("%s ",books [count]. num);
printf(" \ n \ t title:");
Scanf("%s ",books [count]. bname);
printf(" \ n \ t author:");
Scanf("%s ",books [count]. wname);
printf(" \ n \ t Press:");
Scanf("%s ",books [count]. pubname);
Printf ("\ n \ tPublication date:");
Scanf("%s ",books [count]. pub time);
printf(" \ n \ t price:");
Scanf("%f ",& books [count]. Price);
Printf ("\ n \ tPress 0 to finish adding, press 1 to continue: \ n");
scanf("%d ",& ampx);
count++;
}
Printf ("\ nEnd of adding! \ n ");
}
// -
void num _ del();
void bname _ del();
void wname _ del();
void pubname _ del();
void pub time _ del();
void price _ del();
void del()
{ char a;
getchar();
do
{
System ("CLS");
Printf("\n\t 1: press ISBN to delete ");
Printf("\t2: delete by title \ n ");
Printf("\t3: delete by book author ");
Printf("\t4: deleted by book publishing house \ n ");
Printf("\t5: delete by book publishing time ");
Printf("\t6: delete by book price \ n ");
Printf("\t0: exit deletion \ n ");
Do {
Printf ("\ n \ tPlease select the input option1\ \ 2 \ 3 \ \ 4 \ 5 \ \ 6 \ 0: _");
a = getchar(); getchar();
} and (a! = ' 1 ' & amp; & Answer! =' 2' & Answer! =' 3' & Answer! =' 4' & Answer! =' 5' & Answer! =' 6' & Answer! ='0');
Switch (a) // Judge the input number.
{
case“ 1”:num _ del(); Break; //If it is 1, delete it according to the book number.
Case "2": bname _ del (); Break; //If it is 2, deletion by book author will be performed.
Case "3": wname _ del (); Break; //If 3, delete by title.
Case "4": pub name _ del (); Break; //If it is 4, it will be deleted by the book publishing house.
Case "5": pub time _ del (); Break; //If it is 5, delete it according to the publication time of the book.
Case 6: price _ del (); Break; //If it is 6, delete it according to the book price.
Case' 0': System ('CLS'); Break; //0 returns to the login interface.
}
Printf ("\ n \ tPress any key to return to the main menu: _");
getchar();
System ("CLS");
} while(0);
}
/* Press ISBN to delete */
void num_del()
{
int k,n;
Character number [11];
Printf ("Please enter the ISBN to be deleted: \ n");
gets(num);
for(k = 0; k & lt 100; k++)
{if(strcmp(books[k])。 Number, number) ==0)
{ for(n = k; n & lt99; n++)
Books. num,books[n+ 1]。 num);
Books. Pubtime, books [n+ 1]. pub time);
Books. Price = books [n+ 1]. Price;
Books. bname,books[n+ 1]。 bname);
Books. wname,books[n+ 1]。 wname);
Books. pubname,books[n+ 1]。 pubname);
} Count-; k-; }; }
Printf ("There is no such book. \ n ");
getchar();
}
/* Delete by title */
void bname_del()
{
int k,n;
char bname[2 1];
Printf ("Please enter a title to delete: \ n");
gets(bname);
for(k = 0; k & lt 100; k++)
{if(strcmp(books[k])。 bname,bname)==0)
{ for(n = k; n & lt99; n++)
Books. num,books[n+ 1]。 num);
Books. Pubtime, books [n+ 1]. pub time);
Books. Price = books [n+ 1]. Price;
Books. bname,books[n+ 1]。 bname);
Books. wname,books[n+ 1]。 wname);
Books. pubname,books[n+ 1]。 pubname);
} Count-; k-; }; }
Printf ("There is no such book. \ n ");
getchar();
}
/* deleted by the author of the book */
void wname_del()
{
int k,n;
char wname[9];
Printf ("Please enter the author of the book you want to delete: \ n");
gets(wname);
for(k = 0; k & lt 100; k++)
{if(strcmp(books[k])。 wname,wname)==0)
{ for(n = k; n & lt99; n++)
Books. num,books[n+ 1]。 num);
Books. Pubtime, books [n+ 1]. pub time);
Books. Price = books [n+ 1]. Price;
Books. bname,books[n+ 1]。 bname);
Books. wname,books[n+ 1]。 wname);
Books. pubname,books[n+ 1]。 pubname);
} Count-; k-; }}
Printf ("There is no such book. \ n ");
getchar();
}
/* Deleted by Book Publishing House */
void pubname_del()
{
int k,n;
char pubname[2 1];
Printf ("Please enter the book publisher you want to delete: \ n");
Get (pub name);
for(k = 0; k & lt 100; k++)
{if(strcmp(books[k])。 pubname,pubname)==0)
{ for(n = k; n & lt99; n++)
Books. num,books[n+ 1]。 num);
Books. Pubtime, books [n+ 1]. pub time);
Books. Price = books [n+ 1]. Price;
Books. bname,books[n+ 1]。 bname);
Books. wname,books[n+ 1]。 wname);
Books. pubname,books[n+ 1]。 pubname);
} Count-; k-; }; }
Printf ("There is no such book. \ n ");
getchar();
}
/* Delete by book publishing time */
void pubtime_del()
{
int k,n;
char pub time[7];
Printf ("Please enter the publication time of the book you want to delete: \ n");
gets(pub time);
for(k = 0; k & lt 100; k++)
{if(strcpy(books[k])。 pubtime,pubtime)==0)
{ for(n = k; n & lt99; n++)
Books. num,books[n+ 1]。 num);
Books. Pubtime, books [n+ 1]. pub time);
Books. Price = books [n+ 1]. Price;
Books. bname,books[n+ 1]。 bname);
Books. wname,books[n+ 1]。 wname);
Books. pubname,books[n+ 1]。 pubname);
} Count-; k-; }; }
Printf ("There is no such book. \ n ");
getchar();
}
/* Delete by book price */
void price_del()
{
int k,n;
Floating m;
Printf ("Please enter the book price: \ n");
scanf("%f ",& ampm);
for(k = 0; k & lt 100; k++)
{If (book [k]. Price ==m)
{ for(n = k; n & lt99; n++)
Books. num,books[n+ 1]。 num);
Books. Pubtime, books [n+ 1]. pub time);
Books. Price = books [n+ 1]. Price;
Books. bname,books[n+ 1]。 bname);
Books. wname,books[n+ 1]。 wname);
Books. pubname,books[n+ 1]。 pubname);
} Count-; k-; }; }
Printf ("There is no such book. \ n ");
getchar();
}
// -
void num _ revise();
void bname _ revise();
void wname _ revise();
void pubname _ revise();
void pub time _ revise();
void price _ revise();
Invalid revision ()
{
char c;
getchar();
do
{
System ("CLS");
Printf("\n\t 1: change book number ");
Printf("\t\t2: modify the title \ n ");
Printf("\t3: modify book author ");
Printf("\t\t4: modify book publishing house \ n ");
Printf("\t5: modify book publishing time ");
Printf("\t6: modify book price \ n ");
Printf("\t0: exit modification \ n ");
Do {
Printf ("\ n \ tPlease select the input option1\ \ 2 \ 3 \ \ 4 \ 5 \ \ 6 \ 0: _");
c = getchar(); getchar();
}while(c! = ' 1 ' & amp; & ampc! = ' 2 ' & amp& ampc! = ' 3 ' & amp& ampc! = ' 4 ' & amp& ampc! = ' 5 ' & amp& ampc! = ' 6 ' & amp& ampc! ='0');
Switch (c) // Judge the input number.
{
Case "1":num _ revise (); Break;
Case "2": bname _ revise (); Break;
Case "3": wname _ revise (); Break;
Case "4": pub name _ revise (); Break;
Case "5": pub time _ revise (); Break;
Case "6": price _ revise (); Break;
Case' 0': System ('CLS'); Break;
}
Printf ("\ n \ tPress any key to return to the main menu: _");
getchar();
System ("CLS");
} while(0);
}
/* Modified by ISBN */
Invalid Number _ Revision ()
{
int n;
Character number [11];
Printf ("Please enter the number of lines of the book you want to modify: \ n");
scanf("%d ",& ampn);
Printf ("Please enter the ISBN you want to change: \ n");
Scanf("%s ",number);
Strcpy (book [n- 1]). num,num);
getchar();
}
/* Author's modification */
void wname_revise()
{
int n;
char wname[9];
Printf ("Please enter the number of lines of the book you want to modify: \ n");
scanf("%d ",& ampn);
Printf ("Please enter the author of the book you want to change: \ n");
scanf("%s ",wname);
Strcpy (book [n- 1]). wname,wname);
getchar();
}
/* Modify by title */
void bname_revise()
{
int n;
char bname[2 1];
Printf ("Please enter the number of books you want to modify: \ n");
scanf("%d ",& ampn);
Printf ("Please enter the title of the book to be modified: \ n");
scanf("%s ",bname);
Strcpy (book [n- 1]). bname,bname);
getchar();
}
/* According to the book price */
Invalid Price _ Revision ()
{
int n;
Floating price;
Printf ("Please enter the number of books you want to modify: \ n");
scanf("%d ",& ampn);
Printf ("Please enter the book price you want to change: \ n");
Scanf("%f ",& price);
Books [n- 1]. Price = price;
getchar();
}
/* Revised by Book Publishing House */
void pubname_revise()
{
int n;
char pubname[2 1];
Printf ("Please enter the number of books you want to modify: \ n");
scanf("%d ",& ampn);
Printf ("Please enter the book publisher you want to change: \ n");
scanf("%s ",pubname);
Strcpy (book [n- 1]). pubname,pubname);
getchar();
}
/* According to the publication time of the book */
void pubtime_revise()
{
int n;
char pub time[7];
Printf ("Please enter the number of publishing lines to modify: \ n");
scanf("%d ",& ampn);
Printf ("Please enter the publication time of the book you want to change: \ n");
scanf("%s ",pub time);
Strcpy (book [n- 1]). pubtime,pub time);
getchar();
}
// -
void num _ search();
void bname _ search();
void wname _ search();
void pubname _ search();
void pub time _ search();
void price _ search();
Invalid search ()
{
char a;
getchar();
do
{
System ("CLS");
Printf("\n\t 1: query by ISBN ");
Printf("\t2: query by title \ n ");
Printf("\t3: query by book author ");
Printf("\t4: book publishing house query \ n ");
Printf("\t5: query by book publishing time ");
Printf("\t6: query by book price \ n ");
Printf("\t0: Exit query \ n ");
Do {
Printf ("\ n \ tPlease select the input option1\ \ 2 \ 3 \ \ 4 \ 5 \ \ 6 \ 0: _");
a = getchar(); getchar();
} and (a! = ' 1 ' & amp; & Answer! =' 2' & Answer! =' 3' & Answer! =' 4' & Answer! =' 5' & Answer! =' 6' & Answer! ='0');
Switch (a) // Judge the input number.
{
Case "1":num _ search (); Break; //If it is 1, query by book number will be executed.
Case "2": bname _ search (); Break; //If it is 2, query by book author will be executed.
Case "3": wname _ search (); Break; //If it is 3, query by title will be executed.
Case "4": pub name _ search (); Break; //If it is 4, the query of book publishing house will be executed.
Case "5": pub time _ search (); Break; //If it is 5, query by book publishing time will be executed.
Case "6": price _ search (); Break; //If it is 6, query by book price will be executed.
Case' 0': System ('CLS'); //0 returns to the login interface.
}
Printf ("\ n \ tPress any key to return to the main menu: _");
getchar();
System ("CLS");
} while(0);
}
/* query by ISBN */
Void number _ search ()
{
Character number [11];
int n;
System ("CLS");
Printf ("\ n \ n \ n \ tPlease enter the ISBN you want to query: _";
gets(num);
for(n = 0; N< count; n++)
{
Printf ("Book number, title, author, publication date and price \ n");
if(strcmp(num,books[n])。 num)==0)
{
printf(" %-8s %- 10s %-8s %-8s %-8. 1f \ n ",books[n]。 Num, books [n] Bname, books [n]. Wname, books [n] Pubname, books [n] Public time, books. Price);
}
Elseprintf ("\ n \ tThe book you are looking for cannot be found! \ n ");
}
}
/* Query by author */
void wname_search()
{
char wname[9];
int n;
System ("CLS");
Printf ("\ n \ n \ n \ tPlease enter the author of the book you want to query: _";
gets(wname); //Enter the book number to query.
Printf ("Book number, title, author, publication date and price \ n");
for(n = 0; N< count; n++)
{
if(strcmp(wname,books[n])。 wname)==0)
{
printf(" %-8s %- 10s %-8s %-8s %-8. 1f \ n ",books[n]。 Num, books [n] Bname, books [n]. Wname, books [n] Pubname, books [n] Public time, books. Price);
}
Elseprintf ("\ n \ tThe book you are looking for cannot be found! \ n ");
}
}
/* Query by Title */
void bname_search()
{
char bname[2 1];
int n;
System ("CLS");
Printf ("\ n \ n \ n \ tPlease enter the title of the book you want to query: _");
gets(bname); //Enter the book number to query.
Printf ("Book number, title, author, publication date and price \ n");
for(n = 0; N< count; n++)
{
if(strcmp(bname,books[n])。 bname)==0)
{
printf(" %-8s %- 10s %-8s %-8s %-8. 1f \ n ",books[n]。 Num, books [n] Bname, books [n]. Wname, books [n] Pubname, books [n] Public time, books. Price);
}
Elseprintf ("\ n \ tThe book you are looking for cannot be found! \ n ");
}
}
/* Query by book price */
Invalid Price _ Search ()
{
int n;
Floating price;
FILE * fp
System ("CLS");
Printf ("\ n \ n \ n \ tPlease enter the price of the book you want to query: _";
Scanf("%f ",& price); //Enter the book price to query.
fp=fopen("books.dat "," a+"); //Read the file
Printf ("Book number, title, author, publication date and price \ n");
for(n = 0; N< count; n++)
{
if(price==books[n]。 Price)
{
printf(" %-8s %- 10s %-8s %-8s %-8. 1f \ n ",books[n]。 Num, books [n] Bname, books [n]. Wname, books [n] Pubname, books [n] Public time, books. Price);
}
Elseprintf ("\ n \ n \ tThe book you are looking for cannot be found! \ n ");
}
getchar();
fclose(FP);
}
/* According to book publishing house */
void pubname_search()
{
char pubname[2 1];
int n;
System ("CLS");
Printf ("\ n \ n \ n \ tPlease enter the book publishing house you want to query: _";
Get (pub name);
Printf ("Book number, title, author, publication date and price \ n");
for(n = 0; N< count; n++)
{
if(strcmp(pubname,books[n])。 pubname)==0)
{
printf(" %-8s %- 10s %-8s %-8s %-8. 1f \ n ",books[n]。 Num, books [n] Bname, books [n]. Wname, books [n] Pubname, books [n] Public time, books. Price);
}
Elseprintf ("\ n \ tThe book you are looking for cannot be found! \ n ");
}
}
/* Query by book publishing time */
void pubtime_search()
{
char pub time[7];
int n;
System ("CLS");
Printf ("\ n \ n \ n \ tPlease enter the publication time of the book you want to query: _";
gets(pub time);
Printf ("Book number, title, author, publication date and price \ n");
for(n = 0; N< count; n++)
{
if(strcmp(pubtime,books[n])。 Release time) ==0)
{
printf(" %-8s %- 10s %-8s %-8s %-8. 1f \ n ",books[n]。 Num, books [n] Bname, books [n]. Wname, books [n] Pubname, books [n] Public time, books. Price);
}
Elseprintf ("\ n \ n \ tThe book you are looking for cannot be found! \ n ");
}
}
// -
void main()
{
char c;
Printf(" \ n \ n \ n \ n \ n \ t * * * * * * * * * Welcome to the library management system * * * * * * * \ n \ n \ n ");
Printf ("\ t \ t \ tproducer June 2009 \ n \ n");
Printf ("\ t \ t \ tPress Enter to enter the main menu:");
getchar();
do
{
System ("CLS");
printf(" \ n \ t \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf ("\ n \ t \ t \ t \ tMain menu \ n");
printf(" \ n \ t \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf("\t\t 1: Enter book information ");
Printf("\t\t2: add book information \ n ");
Printf("\t\t 3: Delete book information ");
Printf("\t\t4: modify book information \ n ");
Printf("\t\t 5: find book information ");
Printf("\t\t6: Save the book information to a file \ n ");
Printf("\t\t 7: output book information ");
Printf("\t\t8: output book file information \ n ");
Printf("\t\t 0: Exit the system \ n "); ;
Do {
Printf(" \ n \ t \ t tPlease select the input option1\ \ 2 \ 3 \ \ 4 \ 5 \ \ 6 \ \ 7 \ 8 \ 0: _ ");
c = getchar(); getchar();
}while(c! = ' 1 ' & amp; & ampc! = ' 2 ' & amp& ampc! = ' 3 ' & amp& ampc! = ' 4 ' & amp& ampc! = ' 5 ' & amp& ampc! = ' 6 ' & amp& ampc! = ' 7 ' & amp& ampc! = ' 8 ' & amp& ampc! ='0');
Switch (c)
{
case“ 1”:input(); Break;
Case "2": add (); Break;
Case "3": del (); Break;
Case "4": revise (); Break;
Case "5": search (); Break;
Case "6": save (); Break;
Case "7": output (); Break;
Case "8": readfile (); Break;
Case' 0': System ('CLS'); Exit (0);
}
Printf ("\ nPress any key to return to the main menu: _");
getchar();
System ("CLS");
} while( 1);
}
I wrote this myself. It's a little long, but I should be able to understand it. I looked it up on the internet when I was programming, but I couldn't understand it. Fortunately, I insisted on making it up myself, but I still made it up!