# contains "string.h"
# contains "stdlib.h"
#define N 100 /* defines the total book capacity as 100*/
int Count = 0; /* Define a global variable to represent the number of books */
Struct book /* defines the structure type */
{
Int num/* serial number is an integer */
char name[40]; /* The title of the book is String */
Char author [20]; /* Author is a string */
char publish[50]; /* Publisher is the string */
Floating price; /* The price is a floating point */
};
Structure book list [n]; /* define variables of type struct book list N */
Void show_bookinformation (structured book list []); /* Declare the book information browsing function */
Void check_bookinformation (structured book list []); /* Declare book information inquiry function */
Void modify_bookinformation (structured book list []); /* Application for book information modification function */
Void delete_bookinformation (structured book list []); /* Declare the function of deleting book information */
Void reorder_bookinformation (structured book list []); /* Declare the book information sorting function */
Void buytotal (structured book list []); /* Function of declaring book purchase information */
void read(); /* Declare data read-in function */
Void input (); /* Declaration of book information entry function */
void open(); /* Open function of reporting data and information */
/* Main function */
void main()
{
int choice 1;
printf(" * ~ ~ ~ ~~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ * \ n ");
Printf(" * Welcome to the book sales management system * \ n ");
printf(" * ~ ~ ~ ~~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ * \ n ");
do
{
printf(" ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # "); /* Display menu */
Printf ("function option: \ n");
Printf(" 1: book information entry \ n ");
Printf(" 2: book information browsing \ n ");
Printf(" 3: book information query \ n ");
Printf(" 4: book information modification \ n ");
Printf(" 5: book information deleted \ n ");
Printf(" 6: book information sorting \ n ");
Printf(" 7: book purchase \ n ");
Printf(" 0: exit the system \ n ");
printf(" ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ");
Printf ("\ tPlease select an operation:");
scanf("%d ",& ampchoice 1);
Switch (select 1) /* Menu selection */
{
Case 1:
input();
Break;
Case 2:
Show_bookinformation (list);
Break;
Case 3:
Check_bookinformation (list);
Break;
Case 4:
Modify_bookinformation (list);
Break;
Case 5:
Delete_bookinformation (list);
Break;
Case 6:
reorder _ book information(list);
Break;
Case 7:
Buytotal (list);
Break;
Case 0:
Break;
}
}while (choice 1! =0);
Printf ("Thank you! Welcome to use next time! \ n ");
}
/* Open file function */
Invalid open ()
{
int I;
FILE * fp
if((fp=fopen("book.txt "," Rb ")= = NULL)
{
Printf ("Unable to operate, no file information! ! ! \ n ");
Exit (0);
}
for(I = 0; I & ltn;; i++)
{
if(fread(& amp; List[i], sizeof (structural book), 1, fp)==0)
{
Printf ("Data output failed! ! ! \ n ");
Exit (0);
}
}
fclose(FP);
}
/* Input file function */
Invalid read ()
{
int I;
FILE * fp
if((fp=fopen("book.txt "," wr"))==NULL)
{
Printf ("\ nCannot open file! ! ! \ n ");
Exit (0);
}
for(I = 0; I & ltn;; i++)
if(fwrite(& amp; List[i], sizeof (structural book), 1, fp)! = 1)
Printf ("File write error! ! ! \ n ");
fclose(FP);
}
/* Input function */
Invalid input ()
{
int i,k,j,t;
for(j = 0; List [j]. num! =0; j++)
t = j+ 1;
for(I = 0; I & ltn;; i++)
{
Printf ("\ tPlease enter your book serial number:");
Scanf("\t%d ",& list [i]. num);
Printf ("\ tPlease enter a title:");
scanf("\t%s ",list[i]。 Name);
Printf ("\ tPlease enter the author:");
scanf("\t%s ",list[i]。 Author);
Printf ("\ tPlease enter a publisher:");
scanf("\t%s ",list[i]。 Release);
Printf ("\ tPlease enter price:");
Scanf("\t%f ",& list [i]. Price);
fflush(stdin);
Printf ("\ t \ nDo you want to continue typing? (1. is 2. No) ");
scanf("%d ",& ampk);
If(k==2) is broken;
}
count = I+ 1;
read();
}
/* Delete function */
Void delete_bookinformation (structured book list [])
{
int j,k,d,I = 0;
open();
Printf ("Please enter the serial number of the book to be deleted: \ n");
scanf("%d ",& ampd);
for(j = 0; List [j]. num! =0; j++)
{
if(list[j].num==d)
{
for(k = j; List [k]. num! =0; k++)
list[k]= list[k+ 1];
i++;
}
}
If (i==0)
Printf ("The book serial number you entered is not available in the book sales system, please re-select and enter! ! ! \ n ");
other
Count = Count- 1;
read();
Printf ("Delete succeeded \ n");
}
/* Modify function */
Void modify_bookinformation (structured book list [])
{
int j,k=0,number
open();
Printf ("\ tPlease enter the serial number of the book you want to modify:");
Scanf("%d ",&);
for(j = 0; List [j]. num! =0; j++)
If (list[j].num = = number)
{
Printf ("\ n \ tPlease enter your revised book information! \ n \ n ");
Printf ("\ tPlease enter the serial number of the book you want to modify:");
Scanf("%d ",& list [j]. num);
Printf ("\ tPlease enter your modified title:");
Scanf("%s ",list [j]. Name);
Printf ("\ tPlease enter the modified author name:");
Scanf("%s ",list [j]. Author);
Printf ("\ tPlease enter your revision publisher:");
Scanf("%s ",list [j]. Release);
Printf ("\ tPlease enter the price of the revised book:");
Scanf("%f ",& list [j]. Price);
read();
Printf ("\ nModified successfully! \ n ");
k++;
}
If (k==0)
Printf ("\ n \ n \ tThe book to be modified cannot be found! !" );
}
/* Output function */
Void show_bookinformation (structured book list [])
{
int I;
open();
printf(" \ n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Printf ("book serial number \ tBook name \ t \ tAuthor name \ t \ tPublishing company \ t \ tBook price \ n");
for(I = 0; List [i]. num! =0; i++)
{
printf(" % d \ t \ t % s \ t % s \ t \ t % s \ t % 6.2f \ n ",list[i]。 num,list[i]。 Name, list [i]. Author, list [i]. Publish, list [i]. Price);
}
}
/* Query function */
Voidcheck _ bookinformation (struct booklist [])/* Query book information */
{
int j,I,t,k = 0;
char c[20],d[20];
Printf ("Please enter the query method: \n 1. Query by heading 2. Query by author: \ n ");
scanf("%d ",& ampt);
If (t== 1)
{
open();
Printf ("Please enter the title of the book to be queried: \ n");
scanf("%s ",c);
Printf ("\ n * * * * * * * * * The book information you want to query (according to the author's name) * * * * * * * * * * * * * * \ n");
Printf ("book serial number \ tBook name \ t \ tAuthor name \ t \ tPublishing company \ t \ tBook price \ n");
for(j = 0; List [j]. num! =0; j++)
if(strcmp(c,list[j])。 name)==0)
{
printf(" % d \ t \ t % s \ t % s \ t \ t % s \ t % 6.2f \ n ",list[j]。 num,list[j]。 Name, list [j]. Author, list [j]. Publish, list [j]. Price);
k++;
}
If (k==0)
Printf ("\ nThe book information you want to query does not exist! ! ! \ n ");
}
If (t==2)
{
open();
Printf ("Please enter the name of the author to query: \ n");
scanf("%s ",d);
Printf ("book serial number \ tBook name \ t \ tAuthor name \ t \ tPublishing company \ t \ tBook price \ n");
for(I = 0; List [i]. num! =0; i++)
if(strcmp(d,list[i])。 Author) ==0)
{
printf(" % d \ t \ t % s \ t % s \ t \ t % s \ t % 6.2f \ n ",list[i]。 num,list[i]。 Name, list [i]. Author, list [i]. Publish, list [i]. Price);
k++;
}
If (k==0)
Printf ("\ nThe book information you want to query does not exist! ! ! \ n ");
}
}
/* Sorting function */
Void reorder_bookinformation (structured book list [])
{
int i,j,a,k;
Structure book t;
FILE * fp
Charging temperature [40];
open();
Printf ("\ nPlease select the sorting method \ n 1- Title (in alphabetical order) \ N2- Price (from highest to lowest) \ n");
scanf("%d ",& ampa);
Switch (a)
{
Case 1:
for(I = 0; I< count-1; i++)
{ k = I;
for(j = I+ 1; J< counting; j++)
if(strcmp(list[k])。 Name, list [j]. Name) > 0) k = j;
If (k! =i)
{ strcpy(temp,list[i])。 Name);
Strcpy (list [i]). Name, list [k]. Name);
Strcpy (list [k]). Name, temporary);
}
}
if((fp=fopen("book.txt "," w ")= = NULL)
{
Printf ("Can't open the file! \ n ");
Exit (0);
}
Printf ("New sequence is: \ n");
Printf ("book serial number \ tBook name \ t \ tAuthor name \ t \ tPublishing company \ t \ tBook price \ n");
for(j = 0; J< counting; j++)
{
printf(" % d \ t \ t % s \ t % s \ t \ t % s \ t % 6.2f \ n ",list[j]。 num,list[j]。 Name, list [j]. Author, list [j]. Publish, list [j]. Price);
}
read();
Break;
Case 2:
for(k = 0; List [k]. num! =0; k++)
for(j = 0; List [j]. num! =0; j++)
If(list[j]. price & lt list [j+ 1]. Price)
{ t = list[j]; list[j]= list[j+ 1]; list[j+ 1]= t; }
Printf ("book serial number \ tBook name \ t \ tAuthor name \ t \ tPublishing company \ t \ tBook price \ n");
for(j = 0; List [j]. num! =0; j++)
{
printf(" % d \ t \ t % s \ t % s \ t \ t % s \ t % 6.2f \ n ",list[j]。 num,list[j]。 Name, list [j]. Author, list [j]. Publish, list [j]. Price);
k++;
}
read();
Break;
}
}
/* Book purchase list */
Void buytotal (structural account book list [])
{
int k,m,n,q,r,t = 0;
float sum = 0;
char e[50],f[50],l[50],o[50],p[50];
printf(" \ n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf ("\ nList of sample books of People's Posts and Telecommunications Publishing House \ n");
printf(" \ n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf ("Please enter the serial number of each book purchased (enter 0 to end): \ n");
scanf("%d ",& ampq);
do
{
for(r = 0; r & ltn; r++)
{
if(q==list[r]。 Numbers)
{
sum=sum+list[r]。 Price;
t++;
}
}
scanf("%d ",& ampq);
} while(q! =0);
Printf ("Total number of books published: %d\n", t);
Printf ("book receiving unit:");
scanf("%s ",e);
Printf ("publication basis:");
scanf("%s ",f);
Printf ("price: %.2f\n", sum);
Printf ("Postal Code:");
scanf("%d ",& ampk);
Printf ("shipping address:");
scanf("%s ",l);
printf(" Tel:");
scanf("%d ",& ampm);
Printf ("creation date:");
scanf("%d ",& ampn);
Printf ("freight company:");
scanf("%s ",o);
printf(" reviewer:");
scanf("%s ",p);
}
This is for your reference. I don't know if it's ok. If so, share it with me.