应同学请求帮忙写个简易版的图书管理系统,毕竟是个大一菜鸟,写出来还是蛮有趣的。
需求是
书店图书信息管理系统
一、软件开发目的
该软件主要是使用C语言设计开发一个简单的书店图书管理系统,实现对图书信息的输入、增加、删除等功能要求。
二、数据结构
程序中采用结构体数组存储图书的基本信息包括图书编号、书名、作者(要考虑多个作者情况)、出版社、出版日期、ISBN、版次、定价等
结构体成员包括图书编号、书名、作者、出版社、出版日期、ISBN、版次、定价、数量等
三、软件功能说明
1、 各种基本数据的录入和保存。如:图书资料基本信息录入包括图书编号、书名、作者(要考虑多个作者情况)、出版社、出版日期、ISBN、版次、定价、数量等。输入数据信息可以直接在内存操作,也可以保存在文件。
2、各种基本数据的修改。即:允许对以及录入的数据重新进行编辑、修改。可按图书编号修改其他信息如出版日期等,需要提供是否修改的确认信息。除图书编号不能修改外,其余所有信息均能够修改。
3、基本数据的插入。如:有新书进店可在图书信息中插入一条新信息等。
4、各种基本数据的删除。如:某图书全部下架可删除该书的相关信息等。
基于各种数据的查询。
此功能需要设置二级菜单。可提供按各个不同字段查询图书信息,如按图书编号,书名查询;查询时可实现模糊查询,如按书名查输入“计算机”后,书名中含有“计算机”的所有书籍全部显示。6、数据统计
(1)统计某月各种图书的销售量和销售额。
(2)按照图书的销售量排序,显示年度或季度畅销书排行榜,要求至少排出前十名。
四、软件验收标准
1、有较为美观简洁大方的菜单,能保证用户方便、直观、快捷的使用软件的各项功能。
系统菜单功能项:
信息输入
信息显示
信息查询
删除信息
修改信息
增加信息
数据统计
退出系统
注意:要求每执行一个具体的功能之后程序将重新显示菜单。
2、有严密正确的数据验证功能和数据处理功能,能够使用系统功能模块。
3、系统要有一定的可靠性和稳定性。
#include
#include
#include
#include
using namespace std;
struct node
{
char bianhao[30];
char shuming[30];
char zuoze[30];
char chuban[30];
char riqi[30];
char ISBN[30];
int banci;
int dingjia;
int shuliang;
int xiaoliang;
int xiaoer;
struct node *next;
} xx[100000];
struct node *head;
void add_x();
void in();
void out();
void fin();
void mov();
void xiu();
void add();
void toj();
void menu();
void menu1();
void menu2();
void menu3();
int zhuanyi();
void out1(int n);
bool cmp(struct node a, struct node b){
return a.xiaoer > b.xiaoer;
}
int pipei(char *s1, char *s2);
int main()
{
int flag = 1;
int x;
head = (struct node *)malloc(sizeof(struct node));
head -> next = NULL;
while(flag)
{
menu();
scanf("%d", &x);
while(x < 1 || x > 8)
{
printf("输入信息错误,请重新输入\n");
getchar();
getchar();
menu();
scanf("%d", &x);
}
switch(x)
{
case 1:
in();
break;
case 2:
out();
break;
case 3:
fin();
break;
case 4:
mov();
break;
case 5:
xiu();
break;
case 6:
add();
break;
case 7:
toj();
break;
case 8:
flag = 0;
break;
}
}
}
void out1(int n){
int i;
system("cls");
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量", "销售量", "销售额");
for(i = 0; i <= n - 1; i++){
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d%-15d%-15d\n",xx[i].bianhao,xx[i].shuming, xx[i].zuoze, xx[i].chuban,xx[i].riqi, xx[i].ISBN, xx[i].banci, xx[i].dingjia, xx[i].shuliang, xx[i].xiaoliang, xx[i].xiaoer);
}
getchar();
getchar();
}
int zhuanyi(){
int cnt = 0;
struct node *p;
p = head -> next;
while(p){
strcpy(xx[cnt].bianhao,p -> bianhao);
strcpy(xx[cnt].shuming,p -> shuming);
strcpy(xx[cnt].zuoze,p -> zuoze);
strcpy(xx[cnt].chuban,p -> chuban);
strcpy(xx[cnt].riqi,p -> riqi);
strcpy(xx[cnt].ISBN,p -> ISBN);
xx[cnt].banci = p -> banci;
xx[cnt].dingjia = p -> dingjia;
xx[cnt].shuliang = p -> shuliang;
xx[cnt].xiaoliang = p -> xiaoliang;
xx[cnt].xiaoer = p -> xiaoer;
p = p -> next;
cnt++;
}
return cnt;
}
void menu2()
{
system("cls");
printf("请选择修改的内容:\n");
printf("1 书名\n");
printf("2 作者\n");
printf("3 出版社\n");
printf("4 出版日期\n");
printf("5 ISBN\n");
printf("6 版次\n");
printf("7 定价\n");
printf("8 数量\n");
printf("9 退出\n");
printf("请输入编号:\n");
}
void menu3(){
system("cls");
printf("请选择操作:\n");
printf("1 输入销售量\n");
printf("2 显示年度销售排行:\n");
printf("3 退出\n");
printf("请输入编号:\n");
}
void menu1()
{
system("cls");
printf("查询方式:\n");
printf("1 图书编号\n");
printf("2 书名\n");
printf("3 作者\n");
printf("4 出版社\n");
printf("5 出版日期\n");
printf("6 ISBN\n");
printf("7 退出\n");
printf("请选择查询方式:\n");
}
void menu()
{
system("cls");
printf("1 信息输入\n");
printf("2 信息显示\n");
printf("3 信息查询\n");
printf("4 删除信息\n");
printf("5 修改信息\n");
printf("6 增加信息\n");
printf("7 数据统计\n");
printf("8 退出系统\n");
printf("请输入编号:");
}
int pipei(char *s1, char *s2)
{
int i, j;
int flag = 0;
int l1 = strlen(s1);
int l2 = strlen(s2);
int cnt;
for(i = 0; i < l1 - l2 + 1; i++)
{
cnt = i;
for(j = 0; j < l2; j++)
{
if(s2[j] != s1[cnt++])break;
}
if(j == l2)
{
flag = 1;
break;
}
}
return flag;
}
void in()
{
add_x();
system("cls");
printf("1 继续输入\n");
printf("2 退出\n");
printf("请输入:\n");
int x;
scanf("%d", &x);
while(x < 1 || x > 2)
{
printf("输入信息错误,请重新输入\n");
getchar();
getchar();
system("cls");
printf("1 继续输入\n");
printf("2 退出\n");
printf("请输入:\n");
scanf("%d", &x);
}
if(x == 1)in();
if(x == 2)return;
return;
}
void out()
{
system("cls");
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量", "销售量", "销售额");
struct node *p;
p = head -> next;
if(p == NULL)
{
system("cls");
printf("无图书信息\n");
}
else
{
while(p)
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang, p -> xiaoliang, p -> xiaoer);
p = p -> next;
}
}
printf("\n%s\n", "请全屏观看! 按回车退出");
getchar();
getchar();
return;
}
void fin()
{
int flag = 1;
while(flag)
{
system("cls");
menu1();
int x;
scanf("%d", &x);
while(x < 1 || x > 7)
{
printf("输入信息错误!请重新输入\n");
getchar();
getchar();
system("cls");
menu1();
scanf("%d", &x);
}
char ch[30];
struct node *p;
p = head -> next;
int flag1 = 0;
switch(x)
{
case 1:
{
system("cls");
flag1 = 0;
printf("请输入图书编号:\n");
scanf("%s", ch);
if(p == NULL)
{
flag1 = 0;
}
else
{
while(p)
{
if(pipei(p -> bianhao, ch))
{
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1)
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量");
while(p)
{
if(pipei(p -> bianhao, ch))
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang);
}
p = p -> next;
}
}
}
}
break;
case 2:
{
system("cls");
flag1 = 0;
printf("请输入图书书名:\n");
scanf("%s", ch);
if(p == NULL)
{
flag1 = 0;
}
else
{
while(p)
{
if(pipei(p -> shuming, ch))
{
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1)
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量");
while(p)
{
if(pipei(p ->shuming, ch))
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang);
}
p = p -> next;
}
}
}
}
break;
case 3:
{
system("cls");
flag1 = 0;
printf("请输入图书作者:\n");
scanf("%s", ch);
if(p == NULL)
{
flag1 = 0;
}
else
{
while(p)
{
if(pipei(p -> zuoze, ch))
{
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1)
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量");
while(p)
{
if(pipei(p -> zuoze, ch))
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang);
}
p = p -> next;
}
}
}
}
break;
case 4:
{
system("cls");
flag1 = 0;
printf("请输入图书出版社:\n");
scanf("%s", ch);
if(p == NULL)
{
flag1 = 0;
}
else
{
while(p)
{
if(pipei(p -> chuban, ch))
{
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1)
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量");
while(p)
{
if(pipei(p -> chuban, ch))
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang);
}
p = p -> next;
}
}
}
}
break;
case 5:
{
system("cls");
flag1 = 0;
printf("请输入图书出版日期:\n");
scanf("%s", ch);
if(p == NULL)
{
flag1 = 0;
}
else
{
while(p)
{
if(pipei(p -> riqi, ch))
{
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1)
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量");
while(p)
{
if(pipei(p -> riqi, ch))
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang);
}
p = p -> next;
}
}
}
}
break;
case 6:
{
system("cls");
flag1 = 0;
printf("请输入图书ISBN:\n");
scanf("%s", ch);
if(p == NULL)
{
flag1 = 0;
}
else
{
while(p)
{
if(pipei(p -> ISBN, ch))
{
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1)
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量");
while(p)
{
if(pipei(p -> ISBN, ch))
{
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang);
}
p = p -> next;
}
}
}
}
break;
case 7:
flag = 0;
break;
}
if(flag1 == 0 && x != 7)printf("无该图书信息!\n");
if(x != 7)
{
printf("请按回车退出!\n");
getchar();
getchar();
}
}
}
void mov()
{
system("cls");
printf("请输入需要删除的图书编号:\n");
char sh[30];
scanf("%s", sh);
struct node *p, *q;
p = head -> next;
q = head;
if(p == NULL)
{
system("cls");
printf("无图书信息! 按回车继续!\n");
}
while(p)
{
if(strcmp(p -> bianhao, sh) == 0)
{
system("cls");
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "图书编号", "书名", "作者","出版社", "出版日期", "ISDN", "版次", "定价", "数量");
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15d%-15d%-15d\n",p -> bianhao, p -> shuming, p -> zuoze, p -> chuban,p -> riqi, p -> ISBN, p -> banci, p -> dingjia, p ->shuliang);
printf("是否删除?(yes/no)\n请输入:\n");
char ch[10];
getchar();
scanf("%s", ch);
printf("%s\n", ch);
if(strcmp(ch, "yes") == 0)
{
system("cls");
q -> next = p -> next;
free(p);
printf("删除成功! 按回车退出!\n");
}
else if(strcmp(ch, "no") == 0)
{
break;
}
else printf("输入信息错误! 按回车退出!\n");
break;
}
else
{
printf("无该图书信息:\n");
break;
}
p = p -> next;
q = q -> next;
}
getchar();
getchar();
return;
}
void xiu()
{
system("cls");
int flag = 1;
char sh[30];
printf("请输入修改图书编号:\n");
scanf("%s", sh);
int flag1 = 0;
struct node *p;
p = head -> next;
while(p)
{
if(strcmp(p -> bianhao, sh) == 0)
{
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1)
{
while(flag)
{
menu2();
int x;
scanf("%d", &x);
while(x < 1 || x > 9)
{
printf("输入信息错误! 请重新输入! 按回车继续!\n\n");
getchar();
getchar();
menu2();
scanf("%d", &x);
}
switch(x)
{
case 1:
{
system("cls");
printf("请输入新书名:\n");
char pp[30];
scanf("%s", pp);
strcpy(p -> shuming, pp);
}
break;
case 2:
{
system("cls");
printf("请输入新作者:\n");
char pp[30];
scanf("%s", pp);
strcpy(p -> zuoze, pp);
}
break;
case 3:
{
system("cls");
printf("请输入新出版社:\n");
char pp[30];
scanf("%s", pp);
strcpy(p -> chuban, pp);
}
break;
case 4:
{
system("cls");
printf("请输入新出版日期:\n");
char pp[30];
scanf("%s", pp);
strcpy(p -> riqi, pp);
}
break;
case 5:
{
system("cls");
printf("请输入新ISBN:\n");
char pp[30];
scanf("%s", pp);
strcpy(p -> ISBN, pp);
}
break;
case 6:
{
system("cls");
printf("请输入新版次:\n");
int pp;
scanf("%d", &pp);
p -> banci = pp;
}
break;
case 7:
{
system("cls");
printf("请输入新定价:\n");
int pp;
scanf("%d", &pp);
p -> dingjia = pp;
}
break;
case 8:
{
system("cls");
printf("请输入新数量:\n");
int pp;
scanf("%d", &pp);
p -> shuliang = pp;
}
break;
case 9:
{
flag = 0;
break;
}
}
}
}
else{
printf("无该图书信息:\n");
getchar();
getchar();
}
}
void add()
{
add_x();
system("cls");
printf("增加成功,按回车退出!\n");
getchar();
getchar();
return;
}
void toj()
{
//menu3();
int flag = 1;
while(flag){
system("cls");
menu3();
int x;
scanf("%d", &x);
while(x < 1 || x > 3){
printf("输入信息错误! 请重新输入!\n");
getchar();
getchar();
menu3();
scanf("%d", &x);
}
switch(x){
case 1:{
system("cls");
printf("请输入图书编号:\n");
char tt[30];
scanf("%s", tt);
system("cls");
printf("请输入销售量:\n");
int yy;
scanf("%d", &yy);
struct node *p;
p = head -> next;
int flag1 = 0;
while(p){
if(strcmp(p -> bianhao, tt) == 0){
flag1 = 1;
break;
}
p = p -> next;
}
if(flag1){
while(yy < 0 || yy > p -> shuliang){
system("cls");
printf("输入销量超过库存,数据错误, 按回车继续!\n");
getchar();
getchar();
system("cls");
printf("请重新输入销量:\n");
scanf("%d", &yy);
}
p -> xiaoliang += yy;
p -> xiaoer += p -> xiaoliang * p -> dingjia;
}
else{
printf("无该图书信息!\n");
getchar();
getchar();
}
}break;
case 2:{
system("cls");
int uu = zhuanyi();
sort(xx, xx + uu, cmp);
out1(uu);
}break;
case 3:{
flag = 0;
// getchar();
// getchar();
}break;
}
}
// getchar();
// getchar();
}
void add_x()
{
struct node *p, *tail;
int i;
tail = head;
while(tail -> next)
{
tail = tail -> next;
}
p = (struct node *)malloc(sizeof(struct node));
for(i = 1; i <= 9; i++)
{
int flag1 = 0;
system("cls");
struct node *pp;
pp = head -> next;
switch(i)
{
case 1:
printf("请输入编号:\n");
scanf("%s", p -> bianhao);
while(pp){
if(strcmp(pp -> bianhao, p -> bianhao) == 0){
flag1 = 1;
break;
}
pp = pp -> next;
}
break;
case 2:
printf("请输入书名:\n");
scanf("%s", p -> shuming);
break;
case 3:
printf("请输入作者:\n");
scanf("%s", p -> zuoze);
break;
case 4:
printf("请输入出版社:\n");
scanf("%s", p -> chuban);
break;
case 5:
printf("请输入出版日期:\n");
scanf("%s", p -> riqi);
break;
case 6:
printf("请输入ISBN:\n");
scanf("%s", p -> ISBN);
break;
case 7:
printf("请输入版次(输入数字):\n");
scanf("%d", &p -> banci);
break;
case 8:
printf("请输入定价(输入数字):\n");
scanf("%d", &p -> dingjia);
break;
case 9:
printf("请输入数量(输入数字):\n");
scanf("%d", &p -> shuliang);
break;
}
if(flag1)break;
}
if(i != 10){
system("cls");
printf("输入编号于库存图书编号重复! 请重新输入! 按回车继续!\n");
getchar();
getchar();
return;
}
p -> xiaoliang = 0;
p -> xiaoer = 0;
p -> next = NULL;
tail -> next = p;
}