请设计一个简单的图书目录管理系统(初级版)。

图书目录信息包括:

统一书号(不超过13字符)
书名(不超过30字符)
作者(不超过20字符)
出版社(不超过30字符)
出版日期(包括:年、月、日)
价格(精确到分)
注意:为了保证运行窗口能正确地显示,请右击运行窗口,修改“属性”:

在“选项”选项卡中,选中“使用旧版本控制台”
在“字体”选项卡中,选择“8×16”“点阵字体”
在“布局”选项卡中,将屏幕窗口宽度均设为“120”。
具体需求如下:

显示如下的主菜单:
Append Find Remove Modify Show Quit > _
如果用户输入 A 或 a、F 或 f、R 或 r、M 或 m、S 或 s,则可完成相应的操作。如果用户输入其它字符,则显示错误信息。
程序将反复显示主菜单,让用户持续工作。如果用户输入 Q 或 q,则程序结束。

Append Find Remove Modify Show Quit > Q
Thank you! Goodbye!
若用户输入其它字符,则显示错误信息。
Append Find Remove Modify Show Quit > B
Incorrect choice!
Append Find Remove Modify Show Quit > 9
Incorrect choice!
Append Find Remove Modify Show Quit > +
Incorrect choice!
若用户输入 A 或 a,则可以输入新书的信息,将其添加到图书目录中。
Append Find Remove Modify Show Quit > a
     ISBN: 9780439227148
    Title: The Call of the Wild
   Author: Jack London
Publisher: Scholastic Press
 Pub date: 2001/1/1
    Price: 39.4
Append Find Remove Modify Show Quit > A
     ISBN: 9781772262902
    Title: Oliver Twist
   Author: Charles Dickens
Publisher: Engage Books
 Pub date: 2016/9/15
    Price: 648
Append Find Remove Modify Show Quit > a
     ISBN: 9787515911076
    Title: The Call of the Wild
   Author: Jack London
Publisher: Aerospace Publishing House
 Pub date: 2016/5/1
    Price: 29.8
若用户输入的日期信息不正确,则显示错误信息,并要求用户重新输入。
Append Find Remove Modify Show Quit > A
     ISBN: 9787501592401
    Title: The Old Man and the Sea
   Author: Ernest Hemingway
Publisher: Knowledge Press
 Pub date: 2016/2/30
Incorrect date! Please reenter: 2016/6/31
Incorrect date! Please reenter: 2016/8/1
    Price: 25.8
若用户输入 S 或 s,则按书号升序排序,然后列表显示全部图书。
Append Find Remove Modify Show Quit > S
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9780439227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    39.40
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
若用户输入 F 或 f,则输入书名,然后显示该书名的图书。如果没有对应的图书,则显示错误信息。
Append Find Remove Modify Show Quit > F
Title: The Call of the Wild
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9780439227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    39.40
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > f
Title: Gulliver's Travels
Not found!
说明:输出查找结果时,不作排序操作。

若用户输入 R 或 r,则输入书号,然后将删除该书号的图书。如果没有对应的图书,则显示错误信息。
Append Find Remove Modify Show Quit > r
ISBN: 9781772262902
Remove(y/n)? n
Append Find Remove Modify Show Quit > S
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9780439227148 The Call of the Wild           Jack London          Scholastic Press               2001/01/01    39.40
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > R
ISBN: 9780439227148
Remove(y/n)? Y
Append Find Remove Modify Show Quit > s
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
Append Find Remove Modify Show Quit > r
ISBN: 9787515914145
Not found!
Append Find Remove Modify Show Quit > s
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787515911076 The Call of the Wild           Jack London          Aerospace Publishing House     2016/05/01    29.80
要求:用户回答是否删除时,必须回答 Y 或 N (大小写均可)。如果是其它字符,则显示错误信息,要求用户重新回答。

Append Find Remove Modify Show Quit > R
ISBN: 9781772262902
Remove(y/n)? k
Incorrect answer!
Remove(y/n)? $
Incorrect answer!
Remove(y/n)? N
若用户输入 M 或 m,则可以修改图书信息。首先按书号查找,然后重新输入该图书的信息。
Append Find Remove Modify Show Quit > m
ISBN: 9787515911076
Modify(y/n)? y
     ISBN: 9787544724968
    Title: The House on Mango Street
   Author: Sandra Heathneros
Publisher: Yilin Press
 Pub date: 2012/1/1
    Price: 30
Append Find Remove Modify Show Quit > M
ISBN: 9787501592401
Modify(y/n)? n
Append Find Remove Modify Show Quit > m
ISBN: 9787515914145
Not found!
Append Find Remove Modify Show Quit > S
ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---
9781772262902 Oliver Twist                   Charles Dickens      Engage Books                   2016/09/15   648.00
9787501592401 The Old Man and the Sea        Ernest Hemingway     Knowledge Press                2016/08/01    25.80
9787544724968 The House on Mango Street      Sandra Heathneros    Yilin Press                    2012/01/01    30.00
要求:用户回答是否修改时,必须回答 Y 或 N (大小写均可)。如果是其它字符,则显示错误信息,要求用户重新回答。

Append Find Remove Modify Show Quit > M
ISBN: 9787544724968
Modify(y/n)? K
Incorrect answer!
Modify(y/n)? *
Incorrect answer!
Modify(y/n)? n
相关习题:图书目录管理系统(高级版)。

Append Find Remove Modify Show Quit > Thank you! Goodbye!
q

代码

注:代码还有很多bug,请各路大神指点一二

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>struct bookInfo //创建结构体存储书籍数据
{char ISBN[13];char Title[30];char Author[20];char Publisher[30];char Pub_date[10];double Price;
};
struct Node
{struct bookInfo data;struct Node* next;
};
struct Node* list = NULL;//初始化struct Node* createHead()//建立表头
{//动态分配内存struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));//变量初始化headNode->next = NULL;return headNode;
}struct Node* createNode(struct bookInfo data)
{struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));newNode->data = data;newNode->next = NULL;return newNode;
}
//表头插入法
void Append(struct Node* headNode,struct bookInfo data)
{struct Node* newNode = createNode(data);newNode->next = headNode->next;headNode->next = newNode;
}
//查找
struct Node* Find(struct Node* headNode,char* Title)
{struct Node* posNode = headNode->next;while (posNode != NULL && strcmp(posNode->data.Title, Title)){posNode = posNode->next;}return posNode;
}void Remove(struct Node* headNode,char* ISBN)
{struct Node* posLeftNode = headNode;struct Node* posNode = headNode->next;while (posNode != NULL && strcmp(posNode->data.ISBN, ISBN)){posLeftNode = posNode;posNode = posLeftNode->next;}if (posNode == NULL){return;}else{posLeftNode->next = posNode->next;free(posNode);posNode = NULL;}
}
/*若用户输入 M 或 m,则可以修改图书信息。首先按书号查找,然后重新输入该图书的信息。*/
void Modify(struct Node* headNode,char* ISBN )
{struct Node* posNode = headNode->next;while (posNode != NULL && strcmp(posNode->data.ISBN, ISBN)){posNode = posNode->next;}char userKey;printf("Modify(y/n)? ");userKey = getchar();if (posNode != NULL && (userKey == 'y'|| userKey == 'Y')){scanf("%s%s%s%s%s%.2f\n", &posNode->data.ISBN, posNode->data.Title, posNode->data.Author, posNode->data.Publisher, posNode->data.Pub_date, &posNode->data.Price);//scanf("%s", posNode->data.ISBN);//scanf("%s", posNode->data.Title);//scanf("%s", posNode->data.Author);//scanf("%s", posNode->data.Publisher);//scanf("%s", posNode->data.Pub_date);//scanf("%.2f", &posNode->data.Price);fflush(stdin);}else{return;}
}
void bubluSortList(struct Node* headNode)
{for (struct Node* p = headNode->next; p != NULL; p = p->next){for (struct Node* q = p; q != NULL; q = q->next){if (q->data.ISBN > q->next->data.ISBN){struct bookInfo tempData = q->data;q->data = q->next->data;q->next->data = tempData;}}}
}
void Show(struct Node* headNode)
{bubluSortList(headNode);struct Node* pMove = headNode->next;printf("ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---\n");while (pMove != NULL){printf("%s\t%s\t%s\t%s\t%s\t%.2f\n", pMove->data.ISBN, pMove->data.Title, pMove->data.Author, pMove->data.Publisher, pMove->data.Pub_date, pMove->data.Price);//printf("%s\t", pMove->data.ISBN);//printf("%s\t", pMove->data.Title);//printf("%s\t", pMove->data.Author);//printf("%s\t", pMove->data.Publisher);//printf("%s\t", pMove->data.Pub_date);//printf("%.2f\n", pMove->data.Price);fflush(stdin);pMove = pMove->next;}
}
void saveInfoToFile(const char* fileName, struct Node* headNode)
{FILE* fp = fopen(fileName, "w");struct Node* pMove = headNode->next;while (pMove != NULL){fprintf("%s\t%s\t%\ts%\ts%\ts%.2f\n", pMove->data.ISBN, pMove->data.Title, pMove->data.Author, pMove->data.Publisher, pMove->data.Pub_date, pMove->data.Price);//fprintf("%s\t", pMove->data.ISBN);//fprintf("%s\t", pMove->data.Title);//fprintf("%s\t", pMove->data.Author);//fprintf("%s\t", pMove->data.Publisher);//fprintf("%s\t", pMove->data.Pub_date);//fprintf("%.2f\n", &pMove->data.Price);pMove = pMove->next;}fclose(fp);
}
void readInfoToFile(const char* fileName, struct Node* headNode)
{FILE* fp = fopen(fileName, "r");if (fp == NULL){fp = fopen(fileName, "w+");}struct bookInfo tempData ;while (fscanf("%s %s %s %s %s %.2f\n", tempData.ISBN, tempData.Title, tempData.Author, tempData.Publisher, tempData.Pub_date, &tempData.Price) != EOF){Append(list,tempData);}fclose(fp);
}
void menu()
{char ret=0;struct bookInfo tempData ={0,0,0,0,0,0};struct Node* result = NULL;ret = getchar();switch (ret) {case 'A':case 'a'://scanf("%s", tempData.ISBN);//scanf("%s", tempData.Title);//scanf("%s", tempData.Author);//scanf("%s", tempData.Publisher);//scanf("%s", tempData.Pub_date);//scanf("%.2f", &tempData.Price);scanf_s("%s%s%s%s%s%.2f\n", tempData.ISBN, tempData.Title, tempData.Author, tempData.Publisher, tempData.Pub_date, &tempData.Price);Append(list,tempData);saveInfoToFile("bookinfo.txt", list);fflush(stdin);break;case 'F':case 'f':scanf("%s", tempData.ISBN);result=Find(list,tempData.ISBN);if (result == NULL) {printf("Not founf!\n");}else{printf("ISBN--------- Title------------------------- Author-------------- Publisher--------------------- Pub-date-- Price---\n");printf("%s\t%s\t%\ts%\ts%\ts%.2f\n", result->data.ISBN, result->data.Title, result->data.Author, result->data.Publisher, result->data.Pub_date, result->data.Price);//printf("%s\t", result->data.ISBN);//printf("%s\t", result->data.Title);//printf("%s\t", result->data.Author);//printf("%s\t", result->data.Publisher);//printf("%s\t", result->data.Pub_date);//printf("%.2f\n", result->data.Price);fflush(stdin);}break;case 'R':case 'r':printf("ISBN :");scanf("%s", tempData.ISBN);Remove(list,tempData.ISBN);saveInfoToFile("bookinfo.txt", list);fflush(stdin);break;case 'M':case 'm':printf("ISBN :");scanf("%s", tempData.ISBN);Modify(list, tempData.ISBN);saveInfoToFile("bookinfo.txt", list);fflush(stdin);break;case 'S':case 's':Show(list);break;case 'Q':case 'q':printf("Thank you! Goodbye!");system("pause");exit(0);//Quit();break;default:printf("Incorrect choice!\n");fflush(stdin);break;}
}
int main()
{list = createHead();readInfoToFile("bookinfo.txt",list);while (1) {printf("Append Find Remove Modify Show Quit > \n");menu();system("pause");system("cls");}system("pause");return 0;
}

PTA 7-42 《图书目录管理系统》(初级修订版)相关推荐

  1. 文件+树,图书目录管理系统

    文件+树,图书目录管理系统 [主要内容] 开发一个图书目录管理系统,作为图书馆系统的子系统.目录管理系统管理的对象是目录,要求是实现以下基本功能: (1)对目录的增删查改功能 (2)对文件中保存的目录 ...

  2. 基于云服务器 B/S模式 JavaWeb RFID 图书借阅管理系统

    RFID图书借阅管理系统:点击此处访问系统 前排提示: 源码.文档(开题/结题报告/演示视频)包含于上述链接. 本文是一篇初学者写的 "软件文档". 全部仔细阅读完毕需要10min ...

  3. 计算机毕设(附源码)JAVA-SSM基于web的图书借阅管理系统

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  4. (附源码)计算机毕业设计SSM基于web的图书借阅管理系统

    (附源码)计算机毕业设计SSM基于web的图书借阅管理系统 项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe ...

  5. [附源码]java毕业设计线上图书销售管理系统

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  6. [附源码]SSM计算机毕业设计线上图书销售管理系统JAVA

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  7. 基于Spring MVC + Spring + MyBatis的【图书信息管理系统(一)】

    资源下载:https://download.csdn.net/download/weixin_44893902/34867237 练习点设计:模糊查询.删除.新增 一.语言和环境 1.实现语言:JAV ...

  8. 基于Spring MVC + Spring + MyBatis的【图书信息管理系统(二)】

    资源下载:https://download.csdn.net/download/weixin_44893902/35123371 练习点设计:添加.删除.修改 一.语言和环境 实现语言:JAVA语言. ...

  9. C#-修改图书借阅管理系统-错误与SQL server 2008错误、复制数据库

    VS2012错误: *)不存在从对象类型 System.Object[] 到已知的托管提供程序本机类型的映射 public DataTable loadData2UserSearch(params o ...

最新文章

  1. matlab 多个表数据相加,Excel合并计算完成多表格数据汇总求和
  2. 特斯拉撞了警车:辅助系统Autopilot全程开启,连撞两车还没自动停下
  3. 零基础学Python(第十三章 元组)
  4. 【verilog语法】always@(*)自动添加敏感变量列表
  5. android 手机交互设计,移动设备交互设计比较
  6. 要成为一个 Java 架构师得学习哪些知识?
  7. qdialog 只有点击才能获得焦点_张怡筠:怎么做,孩子才能真正爱上学习?
  8. 自定义View调用onDraw方法
  9. iOS内存管理学习笔记二
  10. atitit。浏览器缓存机制 and 微信浏览器防止缓存的设计 attilax 总结
  11. 查询解析MySQL_mysql内部查询过程详解
  12. via浏览器原始css,简约却不简单—via浏览器
  13. 中国矿业大学本科毕业设计Latex模板cumtthesis
  14. 切换电脑窗口的快捷键
  15. 华为交换机配置ntp服务时间 自动同步不成功unsynchronized
  16. 北航linux内核编译及烧录实验报告,北航操作系统实验Lab1笔记
  17. 你想过逃离上海吗?不用4小时
  18. package-info类
  19. 如何正确的去学习C语言
  20. 区块链储存类项目发展报告|链塔智库

热门文章

  1. 统计1~N之间所有立方数的个数并输出这个数目(Java编写)
  2. 服务端渲染可以用ajax吗,服务端渲染(SSR)
  3. 大工21春《SQL数据库课程设计》模板及要求
  4. MySQL在线DDL gh-ost 使用说明
  5. 代理模式-Proxy Pattern
  6. VMware 15 出现的EFI VMware Virtual SCSI Hard Drive(0,0) …. unsuccessful、Directory “EZBOOT“ not found问题
  7. 硬盘分区魔术师易我分区大师,磁盘分区问题不发愁!
  8. mysql 日期的数据类型,MySQL日期数据类型、MySQL时间类型使用总结
  9. HackerRank初级篇之Between Two Sets
  10. 人脸属性识别数据库和开源项目