| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 386 人关注过本帖
标题:请各位老鸟帮忙改下这程序~急用
只看楼主 加入收藏
lonegcl
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-6-9
收藏
 问题点数:0 回复次数:0 
请各位老鸟帮忙改下这程序~急用
这是我在网上找到的图书管理系统的源程序(用TC编的),错误很多。我改了部分,还有就是增加图书那里,如果增加多本图书,他只能读出第一本。麻烦各位帮改下~谢谢!

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>


int sum;
struct book /*定义书的类型*/
{ int number; /*序号*/
char name[10]; /*书名*/
char author[10]; /*作者*/
char from[10]; /*出版社*/
float price; /*价格*/
}book[1000];

main() /*主函数*/
{ char choice,ch1,ch2,ch3,ch4;
bioskey(0);

do
{clrscr();
printf("\n\n\n\t ————————欢迎进入图书管理系统————————\n\n");
printf("0: 查阅图书信息\n");
printf("1:修改图书信息\n");
printf("2:增加图书\n");
printf("3:删除图书\n");
printf("4. 图书信息统计\n");
printf("5. 退出系统\n");
printf("请输入0-5\n");
scanf("%s",&choice);
switch(choice)
{
case '0': viewbook();break;
case '1': changebook();break;
case '2': addbook();break;
case '3': delbook();break;
case '4': bookcount();getch();break;
case '5': break;
default:printf("您输入了错误的操作,请重新输入\n");getch();break;
}
}while(choice!='5');
}


viewbook() /*查阅功能*/
{
char ch1;
do
{
printf("——————————欢迎进入图书查询系统!——————————\n");
printf(" 1:按书名查找\n");
printf(" 2: 按作者查找\n");
printf(" 0:返回\n");
printf("请输入0--2\n");
scanf("%s",&ch1);
switch(ch1)
{
case '1':findbook();getch();break;
case '2':searchbook();getch();break;
case '0':break;
default:printf("您输入了错误的操作,请重新输入\n");getch();break;
}
}while(ch1!='0');
}

findbook() /*查找图书*/
{
FILE *fp;
char name[10];
int i;
fp=fopen("book.txt","r");
printf("请输入你要查找的书名\n");
scanf("%s",name);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(name,book[i].name)==0)
printf("这本书的详细资料是:序号: %d 书名:%s 作者:%s 出版社: %s 价格:%d \n",book[i].number,book[i].name,book[i].author,book[i].from,book[i].price);
fclose(fp);
return;
}
printf("没有你要查询的书籍\n");
fclose(fp);
return;
}

searchbook()
{
FILE *fp;
char author[10];
int i;
fp=fopen("book.txt","r");
printf("请输入你要查找的作者名\n");
scanf("%s",author);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(author,book[i].author)==0)
printf("这本书的详细资料是:序号: %d 书名:%s 作者:%s 出版社: %s 价格:%f \n",book[i].number,book[i].name,book[i].author,book[i].from,book[i].price);
fclose(fp);
return;
}
printf("没有你要查询的书籍\n");
fclose(fp);
return;
}

changebook() /*修改功能*/
{
FILE *fp,*fp2;
char name[10],ch2;
int i;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的书籍的书字\n");
scanf("%s",name);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].name,name)==0)
{
printf("你所要修改的书的资料如下,请选择你要修改的内容\n");
printf("序号: %d 书名:%s 作者:%s 出版社: %s 价格:%d \n",book[i].number,book[i].name,book[i].author,book[i].from,book[i].price);
printf("1:修改书的序号\n");
printf("2:修改书名\n");
printf("3:修改作者\n");
printf("4:修改出版社\n");
printf("5:修改价格\n");
printf("6: 返回主菜单\n");
printf("请输入1-6:");
scanf("%s",&ch2);
switch(ch2)
{
case '1':
{
printf("请输入新的序号\n");
scanf("%d",&book[i].number);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '2':
{
printf("请输入新的书名\n");
scanf("%s",book[i].name);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '3':
{
printf("请输入新的作者\n");
scanf("%s",book[i].author);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '4':
{
printf("请输入新的出版社\n");
scanf("%s",book[i].from);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '5':
{
printf("请输入新的价格\n");
scanf("%d",book[i].price);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '6':break;
default:printf("您输入了错误的操作,请重新输入\n");getch();break;
}
continue;
}
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}

addbook() /*添加功能*/
{
FILE *fp;
int i=0;
char ch4='y';
fp=fopen("book.txt","a+");
while(ch4=='y'||ch4=='Y')
{
printf("请你输入第%d本书的序号\n",i+1);
scanf("%d",&book[i].number);
printf("请你输入书名\n");
scanf("%s",&book[i].name);
printf("请你输入书的作者\n");
scanf("%s",&book[i].author);
printf("请你输入出版社\n");
scanf("%s",&book[i].from);
printf("请你输入书的价格\n");
scanf("%d",&book[i].price);
fwrite(&book[i],sizeof(struct book),1,fp);
printf("是否要输入下本书(Y/N)\n");
scanf("%s",&ch4);
}
fclose(fp);
}

delbook() /*删除功能*/
{
FILE *fp,*fp2;
int i;
char name[10],ch3;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的书名\n");
printf("如果你输入的书名存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",name);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{

if(strcmp(name,book[i].name)!=0)
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该书籍?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",&ch3);
if(ch3=='y'||ch3=='Y')
{
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
fwrite(&book[i],sizeof(struct book),1,fp);

fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}

bookcount() /*统计功能*/
{
FILE *fp;
int i,n=0;
fp=fopen("book.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(book[i].number!=0&&strlen(book[i].name)!=0&&strlen(book[i].author)!=0)
{
printf("第%d本书<序号: %d 书名:%s 作者:%s 出版社: %s 价格:%d \n>\n",i+1,book[i].number,book[i].name,book[i].author,book[i].from,book[i].price);
n=n+1;
}
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
}
搜索更多相关主题的帖子: include 管理系统 number choice 出版社 
2008-06-14 11:31
快速回复:请各位老鸟帮忙改下这程序~急用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016436 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved