|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请问各路神仙,怎样在原来的基础上做出新书上架和旧书下架,添加与删除学生的模块
也就是我的struct Book和struct Card怎样才能输入的形式实现增加或者减少里面的数据呢?(现在各有五个)
我想输入第六个,或者删掉一个?要怎么做呢?
c语言初学,表达不完善请见谅
#include "stdio.h"
#include "string.h"
#include "windows.h"
struct Card
{
char card_num[10];
char student_name[20];
int book_totle;
};
struct Card card[5]={{"20111101","Zhanjun",3},{"20111103","YangKai",1},{"20111113","WuGang",4},{"20111123","Shanglei",2},{"20111105","ZhangKun",5}};
struct Date
{
int year;
int month;
int day;
};
struct Book
{
char book_num[10];
char book_name[20];
struct Date date;
int flag;
};
struct Book book[5]={{"305032","History",{0,0,0},1},{"409812","Geogrophy",{0,0,0},1},{"213401","English",{0,0,0},1},{"3287463","Maths",{0,0,0},1},{"4102102","Physicyl",{0,0,0},1}};
char num[10];
void menu();//函数的声明
void borrowbook();
void returnbook();
void bookinquiry();
void bookupdate();
void readerinquiry();
void readerupdate();
void reborrow();
void borrowbook()
{
int i;
char booknum[10];
printf("请输入要借阅的书号");
scanf("%s",booknum);
for(i=0;i<5;i++)
{
if(strcmp(booknum,book[i].book_num)==0)
{
if(book[i].flag==0)
printf("这本书已经借出!\n");
else
{
book[i].flag=0;
printf("借出日期填写:(请按年/月/日的顺序,如2019/9/8)\n");
scanf("%d/%d/%d",&book[i].date.year,&book[i].date.month,&book[i].date.day);
break;
}
}
}
for(i=0;i<5;i++)
if(strcmp(num,card[i].card_num)==0)
{ card[i].book_totle=card[i].book_totle+1;
break;
}
printf("1.确认并返回菜单 2.确认信息并退出\n");
scanf("%d",&i);
if(i==1)menu();
else exit(0);
}
void returnbook()
{
int i;
char booknum[10];
printf("请输入要还的书号");
scanf("%s",booknum);
for(i=0;i<5;i++)
{
if(strcmp(booknum,book[i].book_num)==0)
{
book[i].flag=1;
break;
}
if(i>=5)
printf("卡号输入错误!");
for(i=0;i<5;i++)
if(strcmp(num,card[i].card_num)==0)
{
card[i].book_totle=card[i].book_totle+1;
break;
}
printf("1.确认并返回菜单 2.确认信息并退出\n");
scanf("%d",&i);
if(i==1)menu();
else exit(0);
}
}
void bookinquiry()
{
int i;
char booknum[10];
printf("请输入要查询的书号:");
scanf("%s",booknum);
for(i=0;i<5;i++)
if(strcmp(booknum,book[i].book_num)==0)
{
printf("编号 书名 借出日期 状态\n");
printf("%s %s",book[i].book_num,book[i].book_name);
printf("%4d年%2d月%2d日",book[i].date.year,book[i].date.month,book[i].date.day);
if(book[i].flag==1)
printf("未借出!\n");
else
printf("已借出!\n");
}
printf("1.确认并返回菜单 2.确认信息并退出\n");
scanf("%d",&i);
if(i==1)
menu();
else
exit(0);
}
void bookupdate()
{
printf("这是新书上架和旧书下架的函数\n");
}
void readerinquiry()
{
int i;
char studentname[20];
printf("请输入要查询的读者");
scanf("%s",studentname);
for(i=0;i<5;i++)
if(strcmp(studentname,card[i].student_name)==0)
{
printf("借书证号 姓名 书名 借出日期 \n");
printf("%s %s %s",card[i].card_num,card[i].student_name,book[i].book_name);
printf("%4d年%2d月%2d日\n",book[i].date.year,book[i].date.month,book[i].date.day);
}
printf("1.确认并返回菜单 2.确认信息并退出\n");
scanf("%d",&i);
if(i==1)menu();
else exit(0);
}
void readerupdate()
{
printf("这是添加与删除读者的函数\n");
}
void reborrow()
{
int i;
char booknum[10];
printf("请输入要续借的书号");
scanf("%s",booknum);
for(i=0;i<5;i++)
if(strcmp(booknum,book[i].book_num)==0)
{
printf("编号 书名 借出日期 状态\n");
printf("%s %s",book[i].book_num,book[i].book_name);
printf("%4d年%2d月%2d日",book[i].date.year,book[i].date.month,book[i].date.day);
if(book[i].flag==1)
printf("不能续借!\n");
else
printf("可以续借!\n");
}
printf("1.确认续借 2.取消续借");
scanf("%d",&i);
if(i==1)
{
book[i].flag=0;
printf("续借日期填写:(请按年/月/日的顺序,如2019/9/8)\n");
scanf("%d/%d/%d",&book[i].date.year,&book[i].date.month,&book[i].date.day);
}
else
printf("1.确认并返回菜单 2.确认信息并退出\n");
scanf("%d",&i);
if(i==1)menu();
else exit(0);
}
void menu()
{
int n;
printf("~~~欢迎使用本校图书管理系统~~~\n");
printf("*******************************\n");
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("请选择以上选项:\n");
printf("*******************************\n");
scanf("%d",&n);
switch(n)
{
case 1:borrowbook();break;
case 2:returnbook();break;
case 3:bookinquiry();break;
case 4:bookupdate();break;
case 5:readerinquiry();break;
case 6:readerupdate();break;
case 7:reborrow();break;
case 8:exit(0);break;
default:printf("输入错误,退出\n");exit(0);break;
}
}
void main()
{
int i;
char num[10];
printf("请输入你的卡号");
scanf("%s",num);
for(i=0;i<5;i++)
if(strcmp(num,card[i].card_num)==0)
break;
if(i>=5)
{
printf("卡号不存在!");
exit(0);
}
else
menu();
}
|
|