中易网

哪位c语言大神编过图书馆管理系统并且能运行的,急求!!!

答案:2  悬赏:80  
解决时间 2021-03-11 23:32
哪位c语言大神编过图书馆管理系统并且能运行的,急求!!!
最佳答案
#include 
#include 
#include 
#include 

typedef struct record {
char title[64]; 
char author[24];
char isbn[24];
double price;
int copies;
struct record *next;
}Node,*LinkList,*pNode;

LinkList InitList() {
LinkList head = (pNode)malloc(sizeof(Node));
head->title[0] = '\0';
head->author[0] = '\0';
head->isbn[0] = '\0';
head->copies = 0;
head->price = 0.0;
head->next = NULL;
return head;
}

pNode ReadData() {
pNode p = (pNode)malloc(sizeof(Node));
fflush(stdin);
printf("书    名 : ");
gets(p->title);
printf("作    者 : ");
gets(p->author);
printf("图书编号 : ");
gets(p->isbn);
printf("单    价 : ");
scanf("%lf",&p->price);
printf("数    量 : ");
scanf("%d",&p->copies);
return p;
}

void Add(LinkList head) { // 头插法
pNode p = ReadData();
p->next = head->next;
head->next = p;
}

void ReadFile(LinkList head) {
char filename[60];
FILE *inf;
int n = 0;
pNode p;
printf("请输入文件名:");
fflush(stdin);
fgets(filename,60,stdin);
if((inf = fopen(filename,"rb")) == NULL) {
printf("无法打开数据文件:%s\n",filename);
system("pause");
return;
}
p = (pNode)malloc(sizeof(Node));
while(fread((void *)p,sizeof(Node),1,inf) == 1) {
p->next = head->next;
head->next = p;
p = (pNode)malloc(sizeof(Node));
++n;
}
free(p);
fclose(inf);
printf("共读入%d条图书信息!\n",n);
system("pause");
}

void ShowData(pNode pnode) {
printf("书名 : %s\n",pnode->title);
printf("作者 : %s\n",pnode->author);
printf("编号 : %s\n",pnode->isbn);
printf("单价 : %.2lf元\n",pnode->price);
printf("数量 : %d本\n\n",pnode->copies);
}

void PrintBookList(LinkList head) {
pNode p = head->next;
while(p) {
ShowData(p);
p = p->next;
}
system("pause");
}

void WriteFile(LinkList head) {
char filename[60];
FILE *outf;
int n = 0;
pNode p = head->next;
printf("请输入文件名:");
fflush(stdin);
fgets(filename,60,stdin);
if((outf = fopen(filename,"wb")) == NULL) {
printf("无法打开数据文件:%s\n",filename);
system("pause");
return;
}
while(p) {
fwrite((void *)p,sizeof(Node),1,outf);
p = p->next;
}
fclose(outf);
printf("共写出%d条图书信息!\n",n);
system("pause");
}

void Sort(LinkList head) { // 选择排序(按ISBN)
pNode pt,qt,q,p;
for(p = head; p->next; p = p->next) {
qt = p;
for(q = p->next; q->next; q = q->next)
if(strcmp(qt->next->isbn,q->next->isbn) > 0)
qt = q;
if(p != qt) { // 调整节点位置
pt = p->next;
p->next = qt->next;
qt->next = qt->next->next;
p->next->next = pt;
}
}
}

int Delete(LinkList head) {
pNode p,q;
char isbn[50],an[5];
printf("请输入欲删除图书ISBN : ");
gets(isbn);
for(p = head; p->next; p = p->next) {
if(strcmp(p->next->isbn,isbn) == 0) {
printf("将要删除图书《%s》!\n",p->next->title);
ShowData(p->next);
printf("1、删除,0、放弃!\n");
printf("请选择 : ");
fflush(stdin);
fgets(an,5,stdin);
if(an[0] == '1') {
q = p->next;
p->next = q->next;
free(q);
}
return 1;
}
}
printf("对不起,没有找到编号为%s的图书!\n",isbn);
return 0;
}

void Modify(LinkList head) {
pNode p = head->next;
char isbn[50],an[5];
int flag;
do {
printf("欲修改图书编号 : ");
fflush(stdin);
gets(isbn);
flag = 1;
while(p) {
if(strcmp(isbn,p->isbn) == 0) {
p = ReadData();
flag = 0;
break;
}
p = p->next;
}
if(flag) printf("没有找到编号为%s的图书。\n",isbn);
else printf("修改成功。\n\n");
printf("1、继续修改  0、返回主菜单\n");
fflush(stdin);
gets(an);
}while(an[0] == '1');
}

void FreeList(LinkList head) {
pNode q,p = head;
while(p) {
q = p->next;
free(p);
p = q;
}
}

void Menu(void) {
system("cls");
printf("**************************************************\n");
printf("*          1、添加              2、显示          *\n");
printf("*          3、排序              4、删除          *\n");
printf("*          5、修改              6、读文件        *\n");
printf("*          7、写文件            0、退出          *\n");
printf("**************************************************\n\n");
}

int main() {
int choice;
LinkList head = InitList();
do {
Menu();
printf("请选择 : ");
scanf("%d",&choice);
switch(choice) {
case 1 : Add(head); break;
case 2 : PrintBookList(head); break;
case 3 : Sort(head); break;
case 4 : Delete(head); break;
case 5 : Modify(head); break;
case 6 : ReadFile(head); break;
case 7 : WriteFile(head); break;
default : break;
}
}while(choice);
FreeList(head);
printf("End!\n");
return 0;
}
全部回答
我们java的作业也是这个
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
光明纪元林齐都获得哪些元界单位
可变轴怎么没有类似固定轴的区域铣削呢
虽然是去爬山,男友还是千哄万哄让我穿上了白
我有一台冰淇淋机,功率是2000瓦,我每天要用
游戏手柄玩王者荣耀怎么控制技能的放心,求解
想一个人去日本,我不会日语,有什么办法可以
电信卡无缘无故被订了70元流量怎么?
奇瑞瑞虎3后壳换一个要多少钱
为什么打开网页字很小很模糊?
面面俱到我想知道这个在什么地方
apple6plus为什么不能下载校讯通
山大有劳动关系专业吗
快客万华店地址有知道的么?有点事想过去
我家有两棵酸木瓜树,一棵结的果子是成熟苹果
中亚有几个海峡
推荐资讯
进来看看新车应该装一些什么物件
十一想自驾游出去玩。我包头的。帮忙推荐好地
与一只蝶不期而遇阅读答案
昌平都有哪些培训机构,学计算机哪家好
在八卦六爻中辰丑土能克亥子水吗
榕城区嘉维电脑服务中心我想知道这个在什么地
湖陂村地址有知道的么?有点事想过去
西湖糖醋鱼的来历和成名史?
有一个外国电影,我忘了名字叫啥了,帮忙找一
家庭人均年收入多少才算是贫困
珍珠粉和海藻面膜可以加在一起做吗?急
攀枝花中禾矿业有限公司在哪里啊,我有事要去
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?