制作图书信息管理系统

发布网友

我来回答

4个回答

热心网友

希望你能满意

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct book{
char name[20],author[20],press[20];
int number,price;
struct book *next;
};
add()
{
FILE *fp;
struct book *head,*new,*current;
int i,n,k=0,j;
clrscr();
head=new=(struct book *)malloc(sizeof(struct book));
printf("How many books do you want to add?\n");
scanf("%d",&n);
getchar();
for(i=1;i<=n;i++)
{
printf("Please input name of%dst'book!\n",i);
fgets(new->name,20,stdin);
printf("Input the name of author!\n");
fgets(new->author,20,stdin);
printf("the name of press!\n");
fgets(new->press,20,stdin);
printf("THe price of book!Notice the price must be type of 'int'\n");
scanf("%d",&new->price);
printf("THe number of book! Notice the number mustn't be '-1'\n");
scanf("%d",&new->number);
getchar();
strlwr(new->name);
strlwr(new->author);
strlwr(new->press);
clrscr();
if(i!=n)
new=new->next=(struct book *)malloc(sizeof(struct book));
}
new->next=NULL;
if((fp=fopen("E:\\book","r"))!=NULL)
{
while(!feof(fp))
{
k++;
if(k==1)
current=new=(struct book *)malloc(sizeof(struct book));
else
new=new->next=(struct book *)malloc(sizeof(struct book));
fgets(new->name,20,fp);
fgets(new->author,20,fp);
fgets(new->press,20,fp);
fscanf(fp,"%d,%d\n",&new->price,&new->number);
}
n=n+k;
new->next=head;
head=current;
}
reapt: new=head;
for(i=1;i<=n-1;i++)
{
k=new->number;
current=new->next;
for(j=1;j<=n-i;j++)
{
if(k==current->number)
{
printf("Sorry!you put the same number!\n");
printf("So you should input the \"%s\" number again\n",current->name);
scanf("%d",¤t->number);
goto reapt;
}
current=current->next;
}
new=new->next;
}
fclose(fp);
fp=fopen("E:\\book","w");
new=head;
for(i=1;i<=n;i++)
{
fprintf(fp,"%s%s%s",new->name,new->author,new->press);
fprintf(fp,"%d,%d\n",new->price,new->number);
new=new->next;
free(head);
head=new;
}
fclose(fp);
}
correct()
{
FILE *fp;
struct book *head,*new,*temple;
int i=0,j=0,n,m=-1,k=0;
char c[20];
clrscr();
head=new=(struct book *)malloc(sizeof(struct book));
printf("Which bood do you want to correct?\n");
printf("If you want to input number,plese press'1',if you want to input press,author,name,please press'2'!\n");
scanf("%d",&n);
getchar();
if(n==1)
{
printf("please input the number!\n");
scanf("%d",&m);
getchar();
}
else
{
printf("Plesae input name or author or press\n");
fgets(c,20,stdin);
strlwr(c);
}
clrscr();
fp=fopen("E:\\book","r");
while(!feof(fp))
{
i++;
fgets(new->name,20,fp);
fgets(new->author,20,fp);
fgets(new->press,20,fp);
fscanf(fp,"%d,%d\n",&new->price,&new->number);
if((new->number==m)||(strcmp(new->name,c)==0)||(strcmp(new->author,c)==0)||(strcmp(new->press,c)==0))
k++;
temple=new;
new=new->next=(struct book *)malloc(sizeof(struct book));
}
fclose(fp);
free(new);
temple->next=NULL;
new=head;
if(k==0)
{
printf("There isn't this book!\n");
for(j=1;j<=i;j++)
{
new=new->next;
free(head);
head=new;
}
}
if(k>1)
{
printf("There are %d books satisfy your demand,you need input book's number!\n",k);
scanf("%d",&m);
getchar();
for(j=0;j<=19;j++)
c[j]='A';
}
if(k!=0)
{
fp=fopen("E:\\book","w");
for(j=1;j<=i;j++)
{
if((new->number==m)||(strcmp(new->name,c)==0)||(strcmp(new->author,c)==0)||(strcmp(new->press,c)==0))
{
printf("Please input name of book!\n");
fgets(new->name,20,stdin);
printf("Input the name of author!\n");
fgets(new->author,20,stdin);
printf("the name of press!\n");
fgets(new->press,20,stdin);
printf("THe price of book!Notice the price must be type of 'int'\n");
scanf("%d",&new->price);
getchar();
clrscr();
strlwr(new->name);
strlwr(new->author);
strlwr(new->press);
}
fprintf(fp,"%s%s%s",new->name,new->author,new->press);
fprintf(fp,"%d,%d\n",new->price,new->number);
new=new->next;
free(head);
head=new;
}
fclose(fp);
}
}
delete()
{
FILE *fp;
struct book *head,*new,*temple;
int i=0,j=0,n,k=0,m=-1;
char c[20];
clrscr();
printf("Which book do you want to search?If you want to input number,plese press'1',if you want to input press,author,name,please press'2'!\n");
scanf("%d",&n);
getchar();
if(n==1)
{
printf("please input the number!\n");
scanf("%d",&m);
}
else
{
printf("Plesae input name or author or press\n");
fgets(c,20,stdin);
strlwr(c);
}
clrscr();
fp=fopen("E:\\book","r");
while(!feof(fp))
{
i++;
if(i==1)
head=new=(struct book *)malloc(sizeof(struct book));
else
new=new->next=(struct book *)malloc(sizeof(struct book));
fgets(new->name,20,fp);
fgets(new->author,20,fp);
fgets(new->press,20,fp);
fscanf(fp,"%d,%d\n",&new->price,&new->number);
if((new->number==m)||(strcmp(new->name,c)==0)||(strcmp(new->author,c)==0)||(strcmp(new->press,c)==0))
k++;
}
fclose(fp);
new->next=NULL;
new=head;
if(k>1)
{
printf("Because there are %d book satisfy your demand,so you must input the number\n",k);
scanf("%d",&m);
}
if(k!=0)
{
fp=fopen("E:\\book","w");
for(j=1;j<=i;j++)
{
if((m==-1)&&((strcmp(new->name,c)==0)||(strcmp(new->author,c)==0)||(strcmp(head->press,c)==0)))
{
temple=new->next;
free(new);
new=temple;
continue;
}
if(new->number==m)
{
temple=new->next;
free(new);
new=temple;
continue;
}
fprintf(fp,"%s%s%s",new->name,new->author,new->press);
fprintf(fp,"%d,%d\n",new->price,new->number);
temple=new->next;
free(new);
new=temple;
}
fclose(fp);
}
}
search()
{
FILE *fp;
int i=0,n,m=-1,k=0;
struct book *head=(struct book *)malloc(sizeof(struct book));
char c[20];
head->next=NULL;
printf("Which book do you want to search?If you want to input number,plese press'1',if you want to input press,author,name,please press'2'!\n");
scanf("%d",&n);
getchar();
if(n==1)
{
printf("please input number!\n");
scanf("%d",&m);
}
else
{
printf("please input name or author or press\n");
fgets(c,20,stdin);
strlwr(c);
}
clrscr();
fp=fopen("E:\\book","r");
while(!feof(fp))
{
fgets(head->name,20,fp);
fgets(head->author,20,fp);
fgets(head->press,20,fp);
fscanf(fp,"%d,%d\n",&head->price,&head->number);
if((head->number==m)||(strcmp(head->name,c)==0)||(strcmp(head->author,c)==0)||(strcmp(head->press,c)==0))
{
printf("book's name:%sauthor:%spress:%sprice:%d,number:%d\n",head->name,head->author,head->press,head->price,head->number);
k++;
}
free(head);
head=(struct book *)malloc(sizeof(struct book));
head->next=NULL;
}
free(head);
fclose(fp);
if(k==0)
printf("None!\n");
}
order()
{
FILE *fp;
struct book *head,*new,*temple,*current;
int i=0,j=0,k=0,n;
printf("If you want to order books,in name,press 1 ,or, in number,press 2\n");
scanf("%d",&n);
clrscr();
fp=fopen("E:\\book","r");
while(!feof(fp))
{
k++;
if(k==1)
head=new=(struct book *)malloc(sizeof(struct book));
else
new=new->next=(struct book *)malloc(sizeof(struct book));
fgets(new->name,20,fp);
fgets(new->author,20,fp);
fgets(new->press,20,fp);
fscanf(fp,"%d,%d\n",&new->price,&new->number);
}
fclose(fp);
new->next=NULL;
temple=(struct book *)malloc(sizeof(struct book));
for(i=1;i<=k-1;i++)
{
current=head;
new=head->next;
for(j=1;j<=k-i;j++)
{
if(n==1)
if(strcmp(current->name,new->name)>0)
{
*temple=*new;
*new=*current;
*current=*temple;
temple->next=new->next;
new->next=current->next;
current->next=temple->next;
}
if(n==2)
if(current->number>new->number)
{
*temple=*new;
*new=*current;
*current=*temple;
temple->next=new->next;
new->next=current->next;
current->next=temple->next;
}
current=new;
new=new->next;
}
}
new=head;
fp=fopen("E:\\book","w");
for(i=1;i<=k;i++)
{
fprintf(fp,"%s%s%s",new->name,new->author,new->press);
fprintf(fp,"%d,%d\n",new->price,new->number);
printf("Book:%sAuthor:%sPress:%s",new->name,new->author,new->press);
printf("Price:%d,Number:%d\n",new->price,new->number);
new=new->next;
free(head);
head=new;
}
fclose(fp);
}
main()
{
int n;
while(1)
{
printf("\n");
printf("If you want to add!please press '1'\n");
printf("If you want to correct!please press '2'\n");
printf("If you want to delete!please press '3'\n");
printf("If you want to search!please press '4'\n");
printf("If you want to order!please press '5'\n");
printf("if you don't want to do anything!pleas press '0'\n");
scanf("%d",&n);
clrscr();
switch(n){
case 1: add();
break;
case 2: correct();
break;
case 3: delete();
break;
case 4: search();
break;
case 5: order();
break;
case 0: break;
}
if(n==0)
break;
}
}


热心网友

补充:
给了个参考 不知道该加什么
#include <stdio.h>
struct student
{
int num;//......
}s[30];
void luru()
{
}
void tongji()
{
}
void sortl()
{
}
void findl()
{
}

void main()
{
int choice=1
printf("欢迎使用本系统!!!\n");
while(choice!=5)
{
printf(" ***********************\n");
printf(" * 主菜单 *\n");
printf(" * 1:学生成绩录入 *\n");
printf(" * 2:学生成绩统计 *\n");
printf(" * 3:学生成绩排序 *\n");
printf(" * 4:学生成绩查找 *\n");
printf(" ***********************\n");
printf(" 请选择:");
scanf("%d",&choice);
switch(choice)
{
case1:
luru();
break;
case2:
tongji()
break;
case3:
findl()
break;
case4:
printf("谢谢使用本系统!\n");
default:
printf("选择错误,清重新选择!\n);
}
}
}
哪位强人给做了额 谢谢

热心网友

时的发生*师的

参考资料:是*师

热心网友

25175上面有你需要的,自己 去下下

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com