| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 942 人关注过本帖
标题:急求c语言程序,图书管理
只看楼主 加入收藏
sino
Rank: 1
来 自:山东济南
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-21
收藏
 问题点数:0 回复次数:0 
急求c语言程序,图书管理
各位好,我是个菜鸟没学多久现在需要对自己的程序进一步增进,希望各位帮个忙
代码如下:
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE1
#define FALSE 0
#define ERROR 0

struct student /*定义学生类型*/
{
int cardnum;
char lendbook[10];
}student[1000];



struct book /*定义书的类型*/
{
int booknum;
char bookname[10];
char bookcreat[20];
int estate; /*书的状态,有无*/
}book[1000];

struct card /*借书卡的类型*/
{
int cardnum;
char studentname[20];
char studentclass[10];
}card[100];


returnbook()
{
FILE *fp; /*定义文件指针,*/
int i,n;
int cardnum;
char lendbook[10];
printf("Plese input your cardnum.\n");
scanf("%d",&cardnum);
fp=fopen("card.txt","r"); /*读取卡号记录*/
for(i=0;fread(&card[i],sizeof(struct card),1,fp)!=0;i++) /*for循环判断卡号是否存在*/
{
   if(card[i].cardnum==cardnum) /*卡号存在,进入下一循环*/
   {
    n=i;
    fclose(fp);
    printf("please input the book's name which you will return \n");
    scanf("%s",&lendbook);
    for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
    {
     if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
     {
      fclose(fp);
      fp=fopen("book.txt","a");
      for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
      {
       if(strcmp(student[i].lendbook,lendbook)==0)
       {
        continue; /*删除还掉的书的借书记录*/
       }
       fwrite(&student[i],sizeof(struct student),1,fp); /*写入原来没还的书的记录*/
      }
      fclose(fp);
      fp=fopen("record.txt","w");
      for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
       {
        fwrite(&student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
       }
      fclose(fp);
      fopen("bookl.txt","w"); /*清临时文件的记录*/
      fp=fopen("book.txt","r");
      for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
      {
       if(i==n)
       {
        book[i].estate=1;
        fwrite(&book[i],sizeof(struct book),1,fp); /*将还的书的原来状态设为无人借阅的*/
        continue;
       }
       fwrite(&book[i],sizeof(struct book),1,fp);
      }
      fclose(fp);
      fp=fopen("book.txt","w");
      for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
      {
       fwrite(&book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
      }
      fclose(fp);
      fopen("bookl.txt","w"); /*清临时文件*/
      printf("ok,press any key to return \n");
      getch();
      return 1;
     }
    }
    printf("there is no book ,press any key to return \n"); /*出错提示*/
    fclose(fp);
    getch();
    return 0;
   }
}
printf("your cardnum/cardcode is wrong please call the cmd or exit \n"); /*出错提示*/
fclose(fp);
getch();
}


findbook()
{
FILE *fp;
char bookname[10];
char bookcreat[20];
int ture,i;
fp=fopen("book.txt","r");
printf("press the bookname which you are loking for \n");
scanf("%s",&bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
   if(strcmp(bookname,book[i].bookname)==0)
   {
    if(book[i].estate==1)
    {
     printf("the bookdate is :bookmun %d  bookname %s  bookcreat %s it is here\n press any key to return \n",
     book[i].booknum,book[i].bookname,book[i].bookcreat);
    }
    else {printf("it is out \n");fclose(fp);return 0;}
    fclose(fp);
    return FALSE;
   }
}
printf("there is no your demand\n");
fclose(fp);
return FALSE;
}


findbook1()
{
FILE *fp;
char bookcreat[10];
int ture,i;
fp=fopen("book.txt","r");
printf("press the author's name \n");
scanf("%s",bookcreat);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
   if(strcmp(bookcreat,book[i].bookcreat)==0)
   {
    if(book[i].estate==1)
    {
     printf("the book's date is:booknum%d  bookname%s   bookcreat%s it is here\n press any key to return\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
    }
    else {printf("it is out \n");fclose(fp);return 0;}
    fclose(fp);
    return FALSE;
   }
}
printf("there is not your demand\n");
fclose(fp);
return FALSE;
}



lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
{
   printf("num.:%d the book have lent :%s \n",student[i].cardnum,student[i].lendbook);
   n=n+1;
}
fclose(fp);
printf("there are %d books have lent\n",n);
printf("press any key \n");
getch();
return n;
}



referbook()
{
char ch5;
do
{
printf("---------------<<Welcome to sunshine library>>-----------------\n");
printf(" 1.          <serch for the bookname >\n");
printf(" 2.          <serch for the author>\n");
printf(" 0.          <exit>\n");
printf("Please press0,1,2,the other is wrong \n");
scanf("%s",&ch5);
switch(ch5)
   {
    case '1':findbook();getch();break;
    case '2':findbook1();getch();break;
    case '0':break;
    default:printf("no operation\n");getch();break;
   }
}while(ch5!='0');
return FALSE;
}


lendbook()
{
FILE *fp;
int i,n;
int cardnum;
printf("press your cardnum\n");
scanf("%d",&cardnum);
fp=fopen("card.txt","r");
for(i=0;fread(&card[i],sizeof(struct card),1,fp)!=0;i++)
{
   if(card[i].cardnum==cardnum)
   {
    n=i;
    fclose(fp);
    printf("please press the bookame you will lent \n");
    scanf("%s",student[n].lendbook);
    fp=fopen("book.txt","r");
    for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
    {
     if(strcmp(book[i].bookname,student[n].lendbook)==0)
     {
      if(book[i].estate==0) {
      printf("sorry it is out ,please lent the other book \n");
      fclose(fp);
      }
      else

    getch();
    return;
   }
  }
   printf("your ID num is inexistence,please apply a new cardnum.press any key to return \n");
  fclose(fp);
  getch();
 }
 }
}


cardcount()
{
FILE *fp;
struct card card[100];
int i,n=0;
fp=fopen("card.txt","r");
for(i=0;fread(&card[i],sizeof(struct card),1,fp)!=0;i++)
{
   printf("NO.%d   ID num:%d name:%s class:%d>\n",
   i+1,card[i].cardnum,card[i].studentname,card[i].studentclass);
   n=n+1;
}
fclose(fp);
printf("there are %d card(s) ,so far \n",n);
printf("press any key \n");
getch();
}




addcard()
{
FILE *fp;
int i=0;
fp=fopen("card.txt","a+");
printf("please input your cardnum.\n");
scanf("%d",&card[i].cardnum);
printf("please input the student's name\n");
scanf("%s",card[i].studentname);
printf("please input class\n");
scanf("%d",&card[i].studentclass);
fwrite(&card[i],sizeof(struct card),1,fp);
fclose(fp);
printf("ok,press any key to return \n");
getch();
}




addbook()
{
FILE *fp;
int i=0;
char choice='y';
fp=fopen("book.txt","a+");
while(choice=='y'||choice=='Y')
{
   printf("please input the NO. %d book's serial number\n",i+0);
   scanf("%d",&book[i].booknum);
   printf("please input the book's name \n");
   scanf("%s",book[i].bookname);
   printf("please input author \n");
   scanf("%s",book[i].bookcreat);
   printf("please select estate 1: exist\t 0:out\n the other key can't work\n");
   
   scanf("%d",&book[i].estate);
 
   fwrite(&book[i],sizeof(struct book),1,fp);
   printf("input next book <<Y/N>>\n");
   scanf("%s",&choice);
}
fclose(fp);
}

bookcount()
{
FILE *fp;
int i,n=0;
fp=fopen("book.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
   if(book[i].booknum!=0&&strlen(book[i].bookname)!=0&&strlen(book[i].bookcreat)!=0)
   {
    printf("NO.%dbook<serial number: %d bookname:%s author:%s estate:%d>\n",i+1,book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].estate);
    n=n+1;
   }
}
 fclose(fp);
printf("At present there is (are)%d book(s)\n",n);
printf("press any key\n");
}




main()
{
char ch1,ch2,ch3,ch4;
do
{
   printf("\t\t:--------------<<MENU>>--------------:\n");
   printf(" 1            <refer book>\n");
   printf(" 2            <borrow book>\n");
   printf(" 3            <manage system>\n");
   printf(" 4            <return boook>\n");
   printf(" 0            <exit>\n");
   printf("please input 0, 1, 2, 3 or 4\n");
   scanf("%s",&ch1);
   switch(ch1)
   {
    case '1':referbook();break;
    case '2':lendbook();;break;
    case '3':{
       do
       {
        printf("---------------welcome to manage system ----------------\n");
        printf(" 1.          <add book>\n");
        printf(" 2.          <book state>\n");
        printf(" 3.          <student manage system>\n");
        printf(" 0.          <return>\n");
        printf("please input 0--3,else can't work\n");
        scanf("%s",&ch2);
        switch(ch2)
        {
         case '1':addbook();
         break;

         case '2':bookcount();getch();break;
         case '3':{do
         {

            printf("__---------------<<students' home>> ----------------__\n");
            printf(" 1.         <apply for a new cardnum.>\n");
            printf(" 2.         <lend book state>\n");
            printf(" 3.         <cardnum.state>\n");
            printf(" 0.         <return>\n");
            printf("please input 0--3,else can't work   \n");
            scanf("%s",&ch4);
            switch(ch4)
             {
              case '1':addcard();break;
              case '2':lendcount();break;
              case '3':cardcount();break;
              case '0':break;
              default:printf("no work\n");getch();break;
             }
            }while(ch4!='0');}break;
            case '0':break;
            default:printf("no work\n");getch();break;
           }
        }while(ch2!='0');}break;
        case '4':returnbook();break;
        case '0':break;
        default:printf("no work\n");getch();break;
   }
}while(ch1!='0');
}

要求还需要用到静态,动态链接还有注册表的使用,小弟才疏学浅请各位帮个忙,还有对于借出书后的查询功能实现不了,指针使用有问题,麻烦帮忙修改一下!
小弟感激不尽!
搜索更多相关主题的帖子: c语言 图书 管理 
2008-09-21 13:27
快速回复:急求c语言程序,图书管理
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020081 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved