当前位置:网站首页>C language course set up library information management system (big homework)
C language course set up library information management system (big homework)
2022-07-01 06:25:00 【Ordinary senior】
One 、 Design function ( The article is for reference only )
Book information includes : Login number 、 Title 、 The author's name 、 Classification number 、 Publisher 、 Publication date 、 Price etc. . Try to design a library information management system , It can provide the following functions :
(1) The system works as a menu
(2) Book information input function ( Books and information are preserved in files )-- Input
(3) Book information browsing function -- Output
(4) Book information inquiry function -- Algorithm
A query : Search by title ; Search by author name
(5) Deletion and modification of book information ( optional )
Two 、 Function display
3、 ... and 、 Mind mapping
Four 、 Program source code
#include <stdio.h>/* Reference library functions */
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
typedef struct book_info// Define the structure variable of the book information and declare the new type name
{
char AN[10]; /* Login number */
char name[20]; /* Title */
char author[20]; /* The author's name */
char clc[10]; /* Classification of */
char company[20]; /* Publisher */
char date[20]; /* Publication date */
char price[10]; /* Price */
struct book_info*next;
}Booklist,*Pointer;
int num=0;// Definition of global variables
Pointer Head=NULL;// The header pointer is empty
FILE*fp;// Pointer to file
/* Declare functions */
int menu_select();/* Main menu function */
void Insert(Pointer*Head);/* Input function */
void Scan(Pointer Head);/* Show function */
void Search_name(Pointer Head);/* Find functions by book title */
void Search_author(Pointer Head);/* Find function by author name */
void Listbyname(Pointer*Head);/* Sort functions by book title */
void Delete(Pointer*Head);// Delete function
void Update(Pointer Head);// Modify the function
void Save();// Save the function as a text file
void Read();// Read in text file function
void Exit();// Exit function
int main()// The main function
{
system("cls");/* Screen clearing before operation */
for(;;)
{
switch(menu_select())
{
case 1:Insert(&Head);
break;
case 2:Scan(Head);
break;
case 3:Search_name(Head);
break;
case 4:Search_author(Head);
break;
case 5:Listbyname(&Head);
break;
case 6:Delete(&Head);
break;
case 7:Update(Head);
break;
case 8:Save();
break;
case 9:Read();
break;
case 0:Exit();
default:
putchar('\a');
}
}
}
int menu_select()// Main menu function
{
int a;
printf("\n\t\t\t Welcome to the library information management system \n\n\n\n\n\t\t***** Please press any key to enter the system menu !*****\n");
getch();
system("cls");
printf("\t\t********************MENU*********************\n");// The main menu
printf("\t\t 1. Enter book information \n");
printf("\t\t 2. Browse book information \n");
printf("\t\t 3. Query book information by book title \n");
printf("\t\t 4. Query book information by author name \n");
printf("\t\t 5. Book information sorting \n");
printf("\t\t 6. Delete book information \n");
printf("\t\t 7. Modify book information \n");
printf("\t\t 8. Book data storage \n");
printf("\t\t 9. Open the book information file \n");
printf("\t\t 0. sign out \n");
printf("\t\t***********************************************\n");
do
{
printf("\n\t Please select the service you need :");
scanf("%d",&a);
}
while(a<0||a>9);
return a;
}
void Insert(Pointer*Head)// Enter the book information function
{
char AN[10];
char c;
Pointer p,q,r;
printf("\n\t\t**************** Please enter book information ****************\n");/* Interactive input */
printf("\n\t\t Please enter your login number :");
scanf("%s",AN);
p=q=*Head;// Check whether the login number is duplicate
while(p!=NULL)
{
if(strcmp(p->AN,AN)==0)
{
printf(" Already have the same login number :");
return;
}
else
{
q=p;p=p->next;
}
}
r=(Pointer)malloc(sizeof(Booklist));
r->next=NULL;
if(r==NULL)
{
printf(" Failed to allocate space !");
return;
}
if(q==NULL)
*Head=r;
else
{
q->next=r;
}
strcpy(r->AN,AN);
printf("\n\t\t Enter the title of the book :");// Enter book information
scanf("%s",r->name);
getchar();
printf("\n\t\t Enter the author name :");
scanf("%s",r->author);
getchar();
printf("\n\t\t Enter the classification number :");
scanf("%s",r->clc);
getchar();
printf("\n\t\t Enter the publishing unit :");
scanf("%s",r->company);
getchar();
printf("\n\t\t Enter the publication date :");
gets(r->date);
printf("\n\t\t Enter the price :");
scanf("%s",r->price);
do
{
printf("\n\t\t Input succeeded !!!!");
num++;
printf(" Select whether to continue to enter (Y/N)?:"); /* Continuously input book information */
getchar();
scanf("%c",&c);
if(c=='y'||c=='Y')
Insert(Head);
else
{
if(c=='n'||c=='N')
return;
else
printf("\n\t\t Input error , Please re-enter !!!");
}
}
while(c!='y'&&c!='n'&&c!='Y'&&c!='N');
}
void Scan(Pointer Head)// Display book information function
{
Pointer p;
p=Head;
if(p==NULL)
printf(" Record is empty ");// Check whether there is book information
else
{
printf("\n\t share %d Bar record ",num);
while(p!=NULL);
{
printf("\n\n\t\t Login number :%-10s",p->AN);// Show book information
printf("\n\t\t Title :%-20s",p->name);
printf("\n\t\t The author's name :%-20s",p->author);
printf("\n\t\t Classification number :%-10s",p->clc);
printf("\n\t\t Publisher :%-20s",p->company);
printf("\n\t\t Publication date :%-20s",p->date);
printf("\n\t\t Price :¥%-10s",p->price);
p=p->next;
}
printf("\n\t\t Please press any key to return to the main menu ");
return;
}
}
void Search_name(Pointer Head)// Find functions by book title
{
int flag=0;// Mark the initial value of the variable
char name[10];
Pointer p;
printf ("\n Please enter the title of the book to be queried :");
scanf("%s",name);
printf("\n\t\t************* Here is the information you are looking for ***************");
p=Head;
while(p!=NULL);
{
if(strcmp(p->name,name)==0)// Find books that match
{
printf("\n\t Login number :%-10s",p->AN);
printf("\n\t Title :%-20s",p->name);
printf("\n\t The author's name :%-20s",p->author);
printf("\n\t Classification number :%-10s",p->clc);
printf("\n\t Publisher :%-20s",p->company);
printf("\n\t Publication date :%-20s",p->date);
printf("\n\t Price :¥%-10s",p->price);
flag=1;// Find the tag variable set to 1
p=p->next;// The pointer goes to the next node
}
else
p=p->next;
}
if(flag==0)
printf("\n\t\t There is no record of the same title ");
printf("\n\t\t Please press any key to return to the main menu ");
getchar();
}
void Search_author(Pointer Head) // Find function by author name
{
int flag=0;
char author[10];
Pointer p;
printf("\n Please enter the author name to query :");
scanf("%s",author);
printf("\n\t\t************* Here is the information you are looking for ?***************");
p=Head;
while(p!=NULL);// Find books that match
{
if(strcmp(p->author,author)==0)/* Find the book display information */
{
printf("\n\t Login number :%-10s",p->AN);
printf("\n\t Title :%-20s",p->name);
printf("\n\t The author's name :%-20s",p->author);
printf("\n\t Classification number :%-10s",p->clc);
printf("\n\t Publisher :%-20s",p->company);
printf("\n\t Publication date :%-20s",p->date);
printf("\n\t Price :¥%-10s",p->price);
flag=1;
p=p->next;
}
else
p=p->next;
}
if(flag==0)
printf("\n\t\t There is no record of the same author name ");
printf("\n\t\t Please press any key to return to the main menu ");
getch();
}
void Listbyname(Pointer*Head)// Sort functions by book title ?
{
Pointer p,q;
int i,j;
char t[10];
char c;
if(Head==NULL)
{
printf("\n\t\t No information !\n");
return;
}
if(num==0)// Check whether there is data to sort
{
printf("\n\t\t The book information record is empty !! Please press any key to return to the main menu .");
getchar();
return;
}
p=q=*Head;
for(i=0;i<num;i++)// Sort
{
for(j=i+1;j<num;j++)
{
q=p;
p=p->next;// Make the pointer point to the next node
if(strcmp(q->name,p->name)>0)// Check both rows
{
//p The data corresponding to the pointer should be arranged in q After the pointer corresponds to the data ,p,q Data exchange
strcpy(t,p->AN);
strcpy(p->AN,q->AN);
strcpy(q->AN,t);
strcpy(t,p->author);
strcpy(p->author,q->author);
strcpy(q->author,t);
strcpy(t,p->clc);
strcpy(p->clc,q->clc);
strcpy(q->clc,t);
strcpy(t,p->company);
strcpy(p->company,q->company);
strcpy(q->company,t);
strcpy(t,p->date);
strcpy(p->date,q->date);
strcpy(q->date,t);
strcpy(t,p->name);
strcpy(p->name,q->name);
strcpy(q->name,t);
strcpy(t,p->price);
strcpy(p->price,q->price);
strcpy(q->price,t);
}
}
q=*Head;p=*Head;
}
do
{
printf("\n\t Sort complete , Whether or not shown (Y/N):"); /* Ask whether to display the sorting results */
getchar();
scanf("%c",&c);
if(c=='y'||c=='Y')
Scan(*Head); // Show sorting results
else
{
if(c=='n'||c=='N')
return; // Back to main menu
else
printf("\n\t\t Input error , Please re-enter !!!");// If there is an error, continue to ask
}
}
while(c!='y'&&c!='n'&&c!='Y'&&c!='N');
}
void Delete(Pointer*Head)/* Delete function */
{
int flag=1;
char AN[10];
char c,z;
Pointer p,q;
printf("\n\t\t******************* Book deletion *******************\n");
printf("\t Please enter the login number to delete the information of the book :");
scanf("%s",AN);
p=q=*Head;/* Find books that match the criteria */
while(p!=NULL&&flag);
{
if(strcmp(p->AN,AN)==0)/* Find the book */
{
printf("\t\n Login number :%-10s",p->AN);// Display information about the book to be deleted
printf("\t\n Title :%-20s",p->name);
printf("\t\n The author's name :%-20s",p->author);
printf("\t\n Classification number :%-10s",p->clc);
printf("\t\n Publisher :%-20s",p->company);
printf("\t\n Publication date :%-20s",p->date);
printf("\t\n Price :¥%-10s\n",p->price);
printf(" Sure to delete ? Please enter if you are sure Y, Others will not be deleted ");// Ask if you want to delete
getchar();
scanf("%c",&z);
if(z=='Y'||z=='y')
{
if(p==*Head)
{
*Head=p->next;free(p);
}/* Delete book information */
else
{
q->next=p->next;
free(p);
}
flag=0;
}
else
{
printf(" The book information has not been deleted , Back to main menu .");
return;
}
}
else
{
q=p;p=p->next;
}/* The pointer goes to the next node */
printf("\t\t Delete successful !!!\n");
}
if(flag)
printf("\t No data to delete !!!");
do
{
printf(" Choose whether to continue deleting (Y/N)?:"); /* Delete book information continuously */
getchar();
scanf("%c",&c);
if(c=='y'||c=='Y')
Delete(Head); /* Continue to delete */
else
{
if(c=='n'||c=='N')
return;/* Return to the main menu without deleting */
else
printf("\n\t\t Input error , Please re-enter !!!");
}
}
while(c!='y'&&c!='n'&&c!='Y'&&c!='N');
}
void Update(Pointer Head)/* Book information modification function */
{
int flag=1;
char AN[10];
char c;
Pointer p;
printf("\n\t\t***************** Book information modification *****************\n");
printf("\t Please enter the login number of the book to be modified :");
scanf("%s",AN);/* Find books that match the criteria */
p=Head;
while(p!=NULL&&flag);
{
if(strcmp(p->AN,AN)==0)
{
printf("\n\t\t Please enter your login number :");/* Modify book information */
scanf("%s",p->AN);
printf("\n\t\t Enter the title of the book :");
scanf("%s",p->name);
getchar();
printf("\n\t\t Enter the author name :");
scanf("%s",p->author);
getchar();
printf("\n\t\t Enter the classification number :");
scanf("%s",p->clc);
getchar();
printf("\n\t\t Enter the publishing unit :");
scanf("%s",p->company);
getchar();
printf("\n\t\t Enter the publication date :");
gets(p->date);
printf("\n\t\t Enter the price :");
scanf("%s",p->price);
flag=0;
printf(" Modification successful !!\n");
}
else
p=p->next;/* The pointer goes to the next node */
}
if(flag)
printf("\n\t\t There is no record of this book !!!");
do
{
printf(" Select whether to continue to modify (Y/N):"); /* Continuously modify book information */
getchar();
scanf("%c",&c);
if(c=='y'||c=='Y')
Update(Head);/* Continue to modify */
else
{
if(c=='n'||c=='N')
return;// Don't modify , Go back to the menu
else
printf("\n\t\t Input error , Please re-enter !!!");
}
}
while(c!='y'&&c!='n'&&c!='Y'&&c!='N');// Continue to ask if the input is wrong
}
void Save() /* Functions saved as text files */
{
Pointer p;
p=Head;
char file[20]; /* Used to store the file save path and file name */
printf(" Please enter the file path and file name :");
scanf("%s",file);
if((fp=fopen(file,"w+"))==NULL)/* Determine whether the file can be opened */
{
printf(" Can't open file !\n");
return;
}
while(p!=NULL);
{
fprintf(fp,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->AN,p->name,p->author,p->clc,p->company,p->date,p->price);// Write data to file
p=p->next;/* Move down one node */
}
fclose(fp);// Write completion , Close file
printf(" The file has been saved !\n");
return;
}
void Read()/* Functions that read text files */
{
Pointer p,q;
int m=0;
char file[20];
printf(" Please enter the file path and file name :");
scanf("%s",file);/* Enter the file path and name */
if((fp=fopen(file,"r+"))==NULL)// Check if the file exists
{
printf(" Can't open file !\n");
return;
}
m=m+1;
if(m==1)
{
p=(Pointer)malloc(sizeof(Booklist));/* Open up a new unit */
Head=p;// take p To the header pointer Head
fscanf(fp,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n",&p->AN,&p->name,&p->author,&p->clc,&p->company,&p->date,&p->price);/* File read in */
do
{
num=num+1;// Record the amount of information in books
if(num==1)// Distinguish between the beginning and the middle of the open list
Head->next=p;
else
q->next=p;
q=p;
p=(Pointer)malloc(sizeof(Booklist));/* Open up a new unit */
fscanf(fp,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n",&p->AN,&p->name,&p->author,&p->clc,&p->company,&p->date,&p->price);// Read in file data
}
while(!feof(fp));// Check that the file is closed , If yes, stop reading , Otherwise, continue to read
q->next=p;
p->next=NULL;// End of linked list processing
num=num+1;// The right amount of book information
}
printf(" Write data successfully , You can go back and browse its information .");
fclose(fp);/* End reading , Close file */
return;
}
void Exit()/* Function to exit the program */
{
char c;
do
{
printf("\n\t\t Exiting ...... Whether to save to file (Y/N)?");/* Ask whether to save book information , To prevent loss */
getchar();
scanf("%c",&c);
if(c=='y'||c=='Y')
{
Save();
exit(0);
}
else
{
if(c=='n'||c=='N')
{
exit(0);}
else
printf("\n\t\t Input error , Please re-enter !!!");
}
}
while(c!='y'&&c!='n'&&c!='Y'&&c!='N');// If there is an error, continue to ask
}
You can pay attention to it, and it will be updated continuously in the future 0.0( Thank you first )
边栏推荐
- Pit of kotlin bit operation (bytes[i] and 0xff error)
- 做技术,自信不可或缺
- 【ManageEngine】终端管理系统,助力华盛证券数字化转型
- 【#Unity Shader#自定义材质面板_第二篇】
- 【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
- make: g++:命令未找到
- JDBC connection pool
- Top 10 Free 3D modeling software for beginners in 2022
- Redis安装到Windows系统上的详细步骤
- 【#Unity Shader#Amplify Shader Editor(ASE)_第九篇】
猜你喜欢
ForkJoin和Stream流测试
HCM Beginner (IV) - time
【ManageEngine】如何实现网络自动化运维
Solve the problem of garbled files uploaded by Kirin v10
Distributed lock implementation
On siem
【#Unity Shader#Amplify Shader Editor(ASE)_第九篇】
Application of IT service management (ITSM) in Higher Education
SystemVerilog learning-10-validation quantification and coverage
让厦门灌口镇田头村变甜头村的特色农产品之一是蚂蚁新村
随机推荐
[ManageEngine Zhuohao] use unified terminal management to help "Eurex group" digital transformation
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
Mysql 表分区创建方法
JDBC database operation
Projects and dependencies in ABP learning solutions
Teach you how to implement a deep learning framework
JMM details
Discrimination between left and right limits of derivatives and left and right derivatives
HCM Beginner (I) - Introduction
图片服务器项目测试
ABP 学习解决方案中的项目以及依赖关系
VS2019如何永久配置本地OpenCV4.5.5使用
[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map
[leetcode] day91- duplicate elements exist
libpng12.so. 0: cannot open shared object file: no such file or directory
Pol8901 LVDS to Mipi DSI supports rotating image processing chip
Understanding of C manualresetevent class
地宫取宝(记忆化深搜)
Pit of kotlin bit operation (bytes[i] and 0xff error)
Forkjoin and stream flow test