Design a book information management system. Book information includes: book number, title, author's name, publication time, price, etc.
1, the system works in menu mode and logs in with password.
2. Book information input function (adding data).
3. Delete book information (delete data).
4. The browsing function of book information (looking for information).
5. Delete book information (modify data).
6. Calculate and sort the book information. Calculate the total price and average price of all books (aver, single precision, output one decimal place), and print out the array elements containing all data in the order of high price to low price.
# include & ltstdio.h & gt
# include & ltstring.h & gt
# include & ltconio.h & gt
# include & ltstdlib.h & gt
# include & ltctype.h & gt
#define STACK_INIT_SIZE 10
# Define OK 1
# Define true 1
# Define false 0
# Definition error 0
The structure student/* defines the student type, which is used to store the lent books */
{
int carnum
char lend book[ 10];
} students [1000];
Structure employee/* Define employee type */
{
int employnum
char employ name[ 15];
int employage
char employex[2];
char employ leve[ 10];
long int employtage
} employment [50];
Struct book /* defines the type of book */
{
int booknum
char bookname[ 10];
char book creat[ 10];
Int turefalse/* Conditions for book lending and returning module to judge whether books are lent or not */
} book[ 1000];
Struct car /* data type of library card */
{
int carnum
char student name[ 10];
int studentclass
} car [100];
Huanbook() /* Return function */
{
FILE *fp, * fp2/* defines two file pointers. Fp2 is used to create temporary files when modifying data to prevent data from being destroyed */
int i,n;
int carnum
char lend book[ 10];
Printf ("Please enter your card number \ n");
scanf("%d ",& ampcarnum);
fp=fopen("car.txt "," r "); /* Read the card number record */
for(I = 0; Fred (&car [i], sizeof(struct car), 1, fp)! =0; I++) /*for loop to determine whether the card number exists */
{
If (the car [me]. Carnum==carnum) /* Card number exists, next cycle */
{
n = I;
fclose(FP);
Printf ("Please enter the name of the book you want to return \ n");
scanf("%s ",lend book);
fp=fopen("record.txt "," r ");
for(I = 0; Fred (& student [i], sizeof (structural student), 1, fp)! =0; I++) /* Judge whether the entered book is borrowed */
{
If (strcmp (student [I])。 Lendbook) = = 0)/* Borrow a book and enter the next cycle, otherwise an error will be displayed */
{
fclose(FP);
fp=fopen("record.txt "," r ");
fp2=fopen("bookl.txt "," w ");
for(I = 0; Fred (& student [i], sizeof (structural student), 1, fp)! =0; i++)
{
if(strcmp(student[i])。 lendbook,lendbook)==0)
{
Continue; /* Delete the borrowing record of returned books */
}
fwrite(& amp; student[i],sizeof(struct student), 1,fp2); /* Write down the records of books that have not been returned */
}
fclose(FP);
fclose(fp2);
fp=fopen("record.txt "," w ");
fp2=fopen("bookl.txt "," r ");
for(I = 0; Fred (& student [i], sizeof (structural student), 1, fp2)! =0; i++)
{
fwrite(& amp; Student [i], sizeof (structural student), 1, FP); /* Write back the book borrowing record information */
}
fclose(FP);
fclose(fp2);
fopen("bookl.txt "," w "); /* Clear the records of temporary files */
fclose(fp2);
fp=fopen("book.txt "," r ");
fp2=fopen("bookl.txt "," w ");
for(I = 0; Fred (& book [i], sizeof (structural book), 1, fp)! =0; I++) /* Write the record of the book into a temporary file to prevent the previous record from being destroyed by the modification information */
{
If (i==n)
{
Book [me]. ture false = 1;
fwrite(& amp; book[i],sizeof(struct book), 1,fp2); /* Set the original status of the returned book to no one to borrow */
Continue;
}
fwrite(& amp; book[i],sizeof(struct book), 1,fp2);
}
fclose(FP);
fclose(fp2);
fp=fopen("book.txt "," w ");
fp2=fopen("bookl.txt "," r ");
for(I = 0; Fred (& book [i], sizeof (structural book), 1, fp2)! =0; i++)
{
fwrite(& amp; book[i],sizeof(struct book), 1,FP); /* Write the temporary file back to */
}
fclose(FP);
fclose(fp2);
fopen("bookl.txt "," w "); /* Clear temporary documents */
fclose(fp2);
Printf ("Return the book, press any key to return \ n");
getch();
Returns1;
}
}
Printf ("You didn't borrow such a book, press any key to return \ n"); /* Error prompt */
fclose(FP);
getch();
Returns 0;
}
}
Printf ("This card is not available in the system, please contact the administrator and press any key to return \ n"); /* Error prompt */
fclose(FP);
getch();
}
findbook()
{
FILE * fp
char bookname[ 10];
Int ture, me;
fp=fopen("book.txt "," r ");
Printf ("Please enter the title of the book you are looking for \ n");
Scanf("%s ",book name);
for(I = 0; Fred (& book [i], sizeof (structural book), 1, fp)! =0; i++)
{
if(strcmp(bookname,book[i])。 Book name) ==0)
{
If (book [me]. turefalse== 1)
{
Printf ("The details of this book are: %d %s %s This book has not been borrowed \ nPress any key to return \ n", Book [i]. Booknum,Book [i]。 Book title, book [i]. bookcreat);
}
Else {printf ("This book has been lent out \ n"); fclose(FP); Returns 0; }
fclose(FP);
Returns FALSE
}
}
Printf ("No book you want to query \ n");
fclose(FP);
Returns FALSE
}
findbook 1()
{
FILE * fp
char book creat[ 10];
Int ture, me;
fp=fopen("book.txt "," r ");
Printf ("Please enter the name of the author you are looking for \ n");
scanf("%s ",bookcreat);
for(I = 0; Fred (& book [i], sizeof (structural book), 1, fp)! =0; i++)
{
if(strcmp(bookcreat,book[i])。 bookcreat)==0)
{
If (book [me]. turefalse== 1)
{
Printf ("The details of this book are: %d %s %s This book has not been borrowed \ nPress any key to return \ n", Book [i]. Booknum,Book [i]。 Book title, book [i]. bookcreat);
}
Else {printf ("This book has been lent out \ n"); fclose(FP); Returns 0; }
fclose(FP);
Returns FALSE
}
}
Printf ("No book you want to query \ n");
fclose(FP);
Returns FALSE
}
lendcount()
{
FILE * fp
int i,n = 0;
fp=fopen("record.txt "," r ");
for(I = 0; Fred (& student [i], sizeof (structural student), 1, fp)! =0; i++)
{
Printf ("Book with card number %d:% s \ n", student [i]. Kanum, student [me]. lend book);
n = n+ 1;
}
fclose(FP);
Printf ("* * has lent out %d books \n ",n);
Printf ("Press any key \ n");
getch();
Returns n;
}
Chabuke ()
{
char ch5
do
{
Printf ("-Welcome to the book inquiry system! -\ n ");
printf(" 1:& lt; Search by title > \ n ");
printf(" 2:& lt; Search by author > \ n ");
printf(" 0:& lt; Return to > \ n ");
Printf ("Please enter 0-2, other inputs are illegal! \ n ");
scanf("%s ",& ampch5);
Switch (ch5)
{
case ' 1 ':find book(); getch(); Break;
Case "2": findbook1(); getch(); Break;
Case "0": break;
Default value: printf ("No such operation \ n"); getch(); Break;
}
}while(ch5! ='0');
Returns FALSE
}
lendbook()
{
FILE *fp,* fp2
int i,n;
int carnum
Printf ("Please enter your card number \ n");
scanf("%d ",& ampcarnum);
fp=fopen("car.txt "," r ");
for(I = 0; Fred (&car [i], sizeof(struct car), 1, fp)! =0; i++)
{
If (the car [me]. Card number = = card number)
{
n = I;
fclose(FP);
Printf ("Please enter the name of the book you want to borrow \ n");
Scanf("%s ",student [n]. lend book);
fp=fopen("book.txt "," r ");
for(I = 0; Fred (& book [i], sizeof (structural book), 1, fp)! =0; i++)
{
If(strcmp (book [i]). Book title, student [n]. lendbook)==0)
{
If (book [me]. True false = = 0){ printf ("Sorry, this book has been lent out, please borrow another book \ n"); fclose(FP); getch(); Return; }
other
fclose(FP);
fp=fopen("record.txt "," a+");
student carnum = carnum
fwrite(& amp; Student [n], sizeof (structural student), 1, FP);
fclose(FP);
fp=fopen("book.txt "," r ");
fp2=fopen("bookl.txt "," w ");
for(I = 0; Fred (& book [i], sizeof (structural book), 1, fp)! =0; i++)
{
If(strcmp (book [i]). Book title, student [n]. lendbook)==0)
{
Book [me]. ture false = 0;
fwrite(& amp; book[i],sizeof(struct book), 1,fp2);
Continue;
}
fwrite(& amp; book[i],sizeof(struct book), 1,fp2);
}
fclose(FP);
fclose(fp2);
fp=fopen("book.txt "," w ");
fp2=fopen("bookl.txt "," r ");
for(I = 0; Fred (& book [i], sizeof (structural book), 1, fp2)! =0; i++)
{
fwrite(& amp; book[i],sizeof(struct book), 1,FP);
}
fclose(FP);
fclose(fp2);
fopen("bookl.txt "," w ");
fclose(fp2);
Printf ("Press any key to return after borrowing a book \ n");
getch();
Return;
}
}
Printf ("There is no such book, press any key to return \ n");
fclose(FP);
getch();
Return;
}
}
Printf ("Your card number does not exist, please apply for a new card, and press any key to return \ n");
fclose(FP);
getch();
}
Car Count ()
{
FILE * fp
int i,n = 0;
fp=fopen("car.txt "," r ");
for(I = 0; Fred (&car [i], sizeof(struct car), 1, fp)! =0; i++)
{
Printf ("card %d
n = n+ 1;
}
fclose(FP);
Printf ("There are %d books in * * * at present \n", n);
Printf ("Press any key \ n");
getch();
}
Delkar ()
{
FILE *fp,* fp2
int I;
int carnum
Char selection;
fp=fopen("car.txt "," r ");
fp2=fopen("bookl.txt "," w ");
Printf ("Please enter the card number you want to delete \ n");
Printf ("If the card number you entered exists, the system will automatically delete the information! If it does not exist, the system will not make any changes \ n ");
scanf("%d ",& ampcarnum);
for(I = 0; Fred (&car [i], sizeof(struct car), 1, fp)! =0; i++)
{
If (the car [me]. Kanum. =carnum)
{
fwrite(& amp; car[i],sizeof(struct car), 1,fp2);
}
}
fclose(FP);
fclose(fp2);
Printf ("Are you sure you want to delete this card? After deletion, all the information in this book cannot be restored to y/n \ n ");
Scanf("%s ",& select);
if(choice=='y'||choice=='Y ')
{
fp=fopen("car.txt "," w ");
fp2=fopen("bookl.txt "," r ");
for(I = 0; Fred (&car [i], sizeof (structural car), 1, fp2)! =0; i++)
{
fwrite(& amp; car[i],sizeof(struct car), 1,FP);
}
fclose(FP);
fclose(fp2);
fp2=fopen("bookl.txt "," w ");
fclose(fp2);
Printf ("Press any key to return \ n");
getch();
Return;
}
other
{
Printf ("Press any key to return \ n");
getch();
Return;
}
}
addcar()
{
FILE * fp
int I = 0;
fp=fopen("car.txt "," a+");
Printf ("Please enter the card number \ n");
Scanf("%d ",& Auto [me]. carnum);
Printf ("Please enter student name \ n");
scanf("%s ",car[i].student name);
Printf ("Please enter a class \ n");
Scanf("%d ",& Auto [me]. student class);
fwrite(& amp; car[i],sizeof(struct car), 1,FP);
fclose(FP);
Printf ("After input, any key will be returned \ n");
getch();
}
Source /question/79222926.html? si=5