自己第一个写的图书管理系统,运用的是结构体数组,很稚嫩,算是成长的一小步
#include<stdio.h>
#include<string.h>#include<io.h>
#include<windows.h>
#define N1 20
#define N2 20
#define N sizeof(struct club)
#define M sizeof(struct book)
struct book{
char book_name[30];
int bianhao;
double price;
char author[20];
char state[20];
char name[20];
char sex[10];
int xuehao;
};
struct club
{
char name[20];
char sex[10];
int xuehao;
char mima[20];
char borrow[30];
};
struct book book[N1];
struct club club[N2];
void background1();
void choice1(struct club club[],int n);
void fanhui1(struct club club[],int n);
void denglu(struct club club[],int n);
void zhuce(struct club club[],int n);
void Insert_Club(struct club club[],int n);
void Lent_Book(int bianhao,int xuehao,struct book book[],int m,struct club club[],int n);
void Search_Book_bianhao(struct book book[],int m,int bianhao);
void Search_Book_name(struct book book[],int m,char b_name[]);
void back(struct book book[],int m,struct club club[],int n,int bianhao,int xuehao);
void Search_Book_price(struct book book[],int m,double price_h,double price_l);
void Insert_Book(struct book book[],int m);
void Delete_Book(struct book book[],int m,int bianhao);
void Delete_Club(struct club club[],int n,int xuehao);
void Print_Book(struct book book[],int m);
void Print_Club(struct club club[],int n);
void Search_Club_xuehao(struct club club[],int n,int xuehao);
void Search_Club_name(struct club club[],int n,char c_name[]);
int main(void)
{
int i,j,n=N1,m=N2;
FILE *p,*p1;
int choice;
int bianhao,xuehao;
int f;
char b_name[20],c_name[20];
double price,price_h,price_l;
int k,l;
char book_name[30],name[20],author[20],sex[10];
p=fopen("会员.txt","r");
fread(club,N,N1,p);
fclose(p);
background1();
choice1(club,n);
p=fopen("会员.txt","wt+");
fwrite(club,N,N1,p);
fclose(p);
p1=fopen("图书.txt","r");
fread(book,M,N2,p1);
fclose(p1);
do{
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("\n");
printf("\t\t\t[1]:借书办理\t");printf(" [6]:还书办理\n");
printf("\t\t\t[2]:查询图书\t");printf(" [7]:查询会员\n");
printf("\t\t\t[3]:添加图书\t");printf(" [8]:添加会员\n");
printf("\t\t\t[4]:删除图书\t");printf(" [9]:删除会员\n");
printf("\t\t\t[5]:遍历图书\t");printf("[10]:遍历会员\n\n");
printf("\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n\n");
printf("\t\t\t0:退出\n\n");
printf("请选择<0~10>:");
scanf("%d",&choice);
switch(choice){
case 1:
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("输入所借图书编号:\n");
scanf("%d",&bianhao);
printf("输入借书人的学号:\n");
scanf("%d",&xuehao);
Lent_Book(bianhao,xuehao,book,m,club,n);
Search_Book_bianhao(book,m,bianhao);
break;
case 2:
system("cls");
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("1.按编号查询\n\n");
printf("2.按名称查询\n\n");
printf("3.按价格区间查询\n\n");
printf("0.返回主菜单\n\n");
printf("请选择:");
scanf("%d",&f);
if(f==1){
printf("请输入查询图书编号:");
scanf("%d",&bianhao);
printf("相关信息如下:\n\n");
Search_Book_bianhao(book,m,bianhao);
break;
}
else if(f==2){
printf("请输入查询图书名称:");
gets(b_name);
getchar();
printf("相关信息如下:\n\n");
Search_Book_name(book,m,b_name);
break;
}
else if(f==3){
printf("请输入最高价格:");
scanf("%lf",&price_h);
printf("请输入最低价格:");
scanf("%lf",&price_l);
printf("相关信息如下:\n\n");
Search_Book_price(book,m,price_h,price_l);