我们也开始做课程设计了呢~~~ 这是我同学做的:
#include
#include
#include
struct BOOK
{
int id,usr[10],total,store,days[10];
char name[31],author[21];
}books[100];
/*上面是结构体的定义,用于存放书籍及借书的信息。*/
void page_title(char *menu_item)
{
clrscr();
printf(">>> 图 书 管 理 系 统 <<<\n\n- %s -\n\n",menu_item);
}
/*上面是打印页眉的函数,同时通过参数menu_item,可以显示当前的状态。*/
void return_confirm(void)
{
printf("\n按任意键返回……\n");
getch();
}
/*上面是返回前请求确认的函数,以便在返回前观察结果*/
int search_book(void)
{
int n,i;
printf("请输入图书序号:");
scanf("%d",&i);
for(n=0;n<100;n++)
{
if(books[n].id==i)
{
printf("书名:%s\n",books[n].name);
printf("作者:%s\n",books[n].author);
printf("存数:%d of ",books[n].store);
printf("%d\n",books[n].total);
return n;
}
}
printf("\n输入错误或无效图书序号.\n");
return -1;
}
/*上面的函数是在数组中找到图书号匹配的记录,显示其信息并返
回数组下标,如果找不到相应记录则提示错误并返回-1。*/
void book_out(void)
{
int n,s,l,d;
page_title("借阅图书");
if((n=search_book())!=-1&&books[n].store>0)
{
printf("请输入借书证序号:");
scanf("%d",&s);
printf("请输入可借天数:");
scanf("%d",&d);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==0)
{
books[n].usr[l]=s;
books[n].days[l]=d;
break;
}
}
books[n].store--;
}
if(n!=-1&&books[n].store==0) printf("此书已经全部借出.\n");
return_confirm();
}
/*上面是借书的函数,首先调用找书函数*/
void book_in(void)
{
int n,s,l;
page_title("归还图书");
if((n=search_book())!=-1&&books[n].store
printf("借阅者图书证列表:\n");
for(l=0;l<10;l++)
if (books[n].usr[l]!=0)
printf("[%d] - %d天\n",books[n].usr[l],books[n].days[l]);
printf("请输入借书证序号:");
scanf("%d",&s);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==s)
{
books[n].usr[l]=0;
books[n].days[l]=0;
break;
}
}
books[n].store++;
}
if(n!=-1&&books[n].store==books[n].total)
printf("全部入藏.\n");
return_confirm();
}
void book_add(void)
{
int n;
page_title("注册新书");
for(n=0;n<100;n++)
if(books[n].id==0) break;
printf("序号:");
scanf("%d",&books[n].id);
printf("书名:");
scanf("%s",&books[n].name);
printf("作者:");
scanf("%s",&books[n].author);
printf("数量:");
scanf("%d",&books[n].total);
books[n].store=books[n].total;
return_confirm();
}
void book_del(void)
{
int n;
page_title("注销旧书");
if((n=search_book())!=-1) books[n].id=0;
printf("该书已注销.\n");
return_confirm();
}
void main(void)
{
menu: page_title("操作选单");
printf("请用数字键选择操作\n\n");
printf("1 借阅图书\n2 归还图书\n\n");
printf("3 注册新书\n4 注销旧书\n\n");
printf("\n0 退出\n");
switch(getch())
{
case '1' : book_out();break;
case '2' : book_in();break;
case '3' : book_add();break;
case '4' : book_del();break;
case '0' : exit(0);
}
goto menu;
}
{
int n;
page_title("广?症慕");
if((n=search_book())!=-1) books[n].id=0;
printf("乎慕厮广?.\n");
return_confirm();
}
void main(void)
{
menu: page_title("荷恬佥汽");
printf("萩喘方忖囚佥夲荷恬\n\n");
printf("1 処堋夕慕\n2 拷珊夕慕\n\n");
printf("3 广过仟慕\n4 广?症慕\n\n");
printf("\n0 曜竃\n");
switch(getch())
{
case '1' : book_out();break;
case '2' : book_in();break;
case '3' : book_add();break;
case '4' : book_del();break;
case '0' : exit(0);
}
goto menu;
}
#include
#include
#include
#define n 5
/* n为书的数量,这里用来测试软件所以定义n为5本书,
在这里定义成n,还有助于以后软件的扩充和升级维护*/
struct ar //作者的信息,由于作者信息的繁杂性,需要再欠套一层结构体
{
char ar_name[257]; //作者姓名
char ar_ntl[257]; //作者国际
};
//*******************************************************************************************
struct books
{
char cn[4]; //书目的编号*************************************************
struct ar au; //作者*******************************************************
char bn[257]; //书名*******************************************************
char bc[257]; //出版社信息*************************************************
};
struct books book[n]= {
{ "01 ",{ "Cay S Horstmann ", "USA "}, "Core Java 2 ", "China Machine press "},
{ "02 ",{ "Bruce Eckel ", "USA "}, "THINKING IN JAVA ", "China Machine press "},
{ "03 ",{ "John L.Viescas ", "USA "}, "SQL Queries for mere Mortals ", "Publishing house of Electronics Industry "},
{ "04 ",{ " ", " "}, " ", " "},
{ "05 ",{ " ", " "}, " ", " "},
}; //为了举例在此初始化了一些图书的信息。
//定义并且初始化了图书的结构体。
//*******************************************************************************************
void welcom();
//*******************************************************************************************
void f_au() //按作者姓名查找的函数*******************
{
char buf[257];
char *au_name;
int i;
printf( "please key in the author 's name : ");
au_name = cgets(buf);
strupr(au_name);
for(i=0;i
char temp[257];
memset(temp, 0, sizeof(temp) );
strncpy(temp, book[i].au.ar_name, sizeof(temp)-1);
strupr(temp);
if(strcmp(temp, au_name)==0 )
{
printf( "author is %s\n ",book[i].au.ar_name);
printf( "the author international is %s\n ",book[i].au.ar_ntl);
printf( "His bookmaking is %s\n ",book[i].bn);
}
}
welcom();
}
//***********************************************************************************
void f_bc()
{
char buf[257];
char *bookc = buf;
int i;
printf( "please key in the book concern 's name : ");
bookc = cgets(buf);
for(i=0;i
char temp[257];
memset(temp, 0, sizeof(temp) );
strncpy(temp, book[i].bc, sizeof(temp)-1);
strupr(temp);
if(strcmp(temp,bookc)==0 ) //对比临时变量中存储的字符与输入的字符是否相同
{
printf( "Book concern is %s\n ",book[i].bc);
printf( "The author 'name is %s\n ",book[i].au.ar_name);
printf( "The call number is %s\n ",book[i].cn);
}
}
welcom();
}
//**********************************************************************************************
void f_cn()
{
char buf[4];
char *bookn;
int i;
printf( "please key in the call number : ");
bookn = cgets ( buf);
for(i=0;i
char temp[4];
memset(temp, 0, sizeof(temp) );
strncpy(temp, book[i].cn, sizeof(temp)-1);
strupr(temp);
if(strcmp(temp,bookn)==0 ) //对比临时变量中存储的字符与输入的字符是否相同
{
printf( "The call number is %s\n ",book[i].cn);
printf( "Book concern is %s\n ",book[i].bc);
printf( "The author 'name is %s\n ",book[i].au.ar_name);
}
}
welcom();
}
//*********************************************************************************************
void dele()
{
int i;
char buf[257];
char *bookn;
char str;
char temp[257];
printf( "please key in the call number: ");
bookn = cgets(buf);
for(i=0;i
memset(temp, 0, sizeof(temp) );
strncpy(temp, book[i].bn, sizeof(temp)-1);
strupr(temp);
if(strcmp(temp,bookn)==0 ) //对比临时变量中存储的字符与输入的字符是否相同
{
printf( "The call number is %s\n ",book[i].cn);
printf( "Book concern is %s\n ",book[i].bc);
printf( "The author 'name is %s\n ",book[i].au.ar_name);
printf( "Are you sure to delete, y/n?: "); //给出对应编号的图书信息以确认删除操作。
scanf( "%c ",&str);
}
switch (str)
{
case 'y ':
memset(book + i * sizeof(struct books), 0, sizeof(struct books));
printf( "deleted!! ");
welcom();
//清空所占的内存
break;
case 'n ': welcom();break;
}
}
}
//**********************************************************************************************
void welcom()
{
char num;
printf( "1 finding with the author name\n ");
printf( "2 finding with the book concern\n ");
printf( "3 finding with the call number\n ");
printf( "4 delete the book 's information\n ");
//列出4个查找方案备选。*********************
scanf( "%c ",&num); //输入选项前的数字**************************
switch (num)
{
case '1 ': f_au();break;
case '2 ': f_bc();break;
case '3 ': f_cn();break;
case '4 ': dele();break;
}
}
//***********************************************************************************************
void main()
{
printf( "welcome to the books hypervisor!\n*******************************\n*******************************\n\n ");
printf( "*********************************************************************\n\nplease choose the condition with finding the information about books!\n\n*********************************************************************\n\n ");
//欢迎界面**********************************
welcom();
}