| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 574 人关注过本帖
标题:谁能使这个代码完整运行。各个功能全部能使用
只看楼主 加入收藏
学小强编程
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2011-12-4
结帖率:85.71%
收藏
已结贴  问题点数:25 回复次数:5 
谁能使这个代码完整运行。各个功能全部能使用

#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#define STACK_INIT_SIZE 10
#define OK 1


 
 

#define TRUE 1
#define ERROR 0

/*定义学生类型,用于存放借出的书籍*/
struct student {
int carnum;
char lendbook[10];
}student[1000];

 /*定义书的类型*/
struct book
{
int booknum;
char bookname[20];
float bookprice;
char bookcreat[20];
int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[1000];

/*借书卡的数据类型*/
struct car
{
int carnum;
char sex[5];
char studentname[20];
int studentclass;
}car[1000];
/*查询图书信息模块*/
/*(1)按书名查找*/
findbook()
{
FILE *fp;
char bookname[10];
int i;
fp=fopen("book.txt","r");
printf("请输入你要查找的书名:\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].turefalse==1)
    {
printf(" 书号      书名      作者 \n %d      %s     %s \n",book[i].booknum,book[i].bookname,book[i].bookcreat);
printf("此书现在无人借阅\n按任意键返回\n"); }
    else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
    fclose(fp);
    return 0;
   }
}
printf("抱歉无此书!\n");
fclose(fp);
return 0;
}
/*(2)按作者查找*/
findbook1()
{
FILE *fp;
char bookcreat[10];
int i;
fp=fopen("book.txt","r");
printf("请输入作者名:\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].turefalse==1)
    {
     printf(" 书号  书名  作者 \n %d    %s    %s \n",book[i].booknum,book[i].bookname,book[i].bookcreat);
    printf("此书现在无人借阅\n按任意键返回\n");
    }
else {printf("此书已借出!\n");fclose(fp);
return 0;
    }
    fclose(fp);
    return 0;
   }
}
printf("没有此书籍\n");
fclose(fp);
return 0;
}
chabook()/*查找图书主模块 */
{
char ch5;
do
{
printf("!!!欢迎进入图书查询系统!!!\n");
printf(" 1: 按书名查找 \n");
printf(" 2: 按作者查找 \n");
printf(" 0: 返回 \n");
printf("请输入0━2:\n");
ch5=getch();
switch(ch5)
   {
    case '1':findbook();getch();break;
    case '2':findbook1();getch();break;
    case '0':break;
    default:printf("无此操作!\n");getch();break;
   }
}while(ch5!='0');
return 0;
}
/*借书与还书模块*/
/*(1).借书模块*/
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
system("cls");
printf("\t\t*****欢迎进入借书系统*****\n\n");
printf("请输入借书人的:\n卡号:\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
   if(car[i].carnum==carnum)
   {
    n=i;
    fclose(fp);
    printf("书名:\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].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return 0;}
      else
      fclose(fp);
      fp=fopen("record.txt","a+");
      student[n].carnum=carnum;
      fwrite(&student[n],sizeof(struct student),1,fp);
      fclose(fp);
      fp=fopen("book.txt","r");
      fp2=fopen("bookl.txt","w");
      for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
      {
       if(strcmp(book[i].bookname,student[n].lendbook)==0)
       {
        book[i].turefalse=0;
        fwrite(&book[i],sizeof(struct book),1,fp2);
        continue;
       }
       fwrite(&book[i],sizeof(struct book),1,fp2);
      }
      fclose(fp);
      fclose(fp2);
      fp=fopen("book.txt","w");
      fp2=fopen("bookl.txt","r");
      for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
      {
       fwrite(&book[i],sizeof(struct book),1,fp);
      }
      fclose(fp);
      fclose(fp2);
      fopen("bookl.txt","w");
      fclose(fp2);
      printf("借书完毕,按任意键返回...\n");
      getch();
      return 0;
     }
    }
    printf("不存在这样的书,任意键返回...\n");
    fclose(fp);
    getch();
    return 0;
   }
}
printf("你的卡号不存在,请申请新卡,按任意键返回...\n");
fclose(fp);
getch();
return 0;}
/*(2).还书函数*/
huanbook()
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum;
char lendbook[10];
system("cls");
printf("\t\t@@@@欢迎进入还书界面@@@@");
printf("\n请你输入你的\n卡号:\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r"); /*读取卡号记录*/
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/
{
   if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/
   {
    n=i;
    fclose(fp);
    printf("请输入你要还的书的名字:\n");
    scanf("%s",lendbook);
    fp=fopen("record.txt","r");
    for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
    {
     if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
     {
      fclose(fp);
      fp=fopen("record.txt","r");
      fp2=fopen("bookl.txt","w");
      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,fp2); /*写入原来没还的书的记录*/
      }
      fclose(fp);
      fclose(fp2);
      fp=fopen("record.txt","w");
      fp2=fopen("bookl.txt","r");
      for(i=0;fread(&student[i],sizeof(struct student),1,fp2)!=0;i++)
       {
        fwrite(&student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
       }
      fclose(fp);
      fclose(fp2);
      fopen("bookl.txt","w"); /*清临时文件的记录*/
      fclose(fp2);
      fp=fopen("book.txt","r");
      fp2=fopen("bookl.txt","w");
      for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
      {
       if(i==n)
       {
        book[i].turefalse=1;
        fwrite(&book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/
        continue;
       }
       fwrite(&book[i],sizeof(struct book),1,fp2);
      }
      fclose(fp);
      fclose(fp2);
      fp=fopen("book.txt","w");
      fp2=fopen("bookl.txt","r");
      for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
      {
       fwrite(&book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
      }
      fclose(fp);
      fclose(fp2);
      fopen("bookl.txt","w"); /*清临时文件*/
      fclose(fp2);
      printf("还书完毕,按任意键返回...\n");
      getch();
      return 1;
     }
    }
    printf("你没有借这样的书,任意键返回...\n"); /*出错提示*/
    fclose(fp);
    getch();
    return 0;
   }
}
printf("没这样的卡,和管理员联系,按任意键返回...\n"); /*出错提示*/
fclose(fp);
getch();
return 0;}
/*(3).借书统计*/
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("卡号      借出的书籍     \n");
   printf("%d       %s \n",student[i].carnum,student[i].lendbook);
   n=n+1;
}
fclose(fp);
printf("目前共有%d本书借出\n",n);
printf("按任意键...\n");
getch();
return n;
}
/*(1).增加图书信息*/
 void addbook()
{
FILE *fp;
int i=0;
char choice='y';
fp=fopen("book.txt","a+");
while(choice=='y'||choice=='Y')
{
   printf("书号:\n");
   scanf("%d",&book[i].booknum);
   printf("书名:\n");
   scanf("%s",book[i].bookname);
   printf("作者:\n");
   scanf("%s",book[i].bookcreat);
   printf("单价:\n");
   scanf("%f",&book[i].bookprice);
   printf("请你设定书的状态(1在架/0不在):\n");  
   scanf("%d",&book[i].turefalse);
   fwrite(&book[i],sizeof(struct book),1,fp);
   printf("是否要输入下本书(y/n)\n");
   scanf("%s",&choice);
}
fclose(fp);
}
/*(2).删除图书信息*/
delbook()
{
FILE *fp,*fp2;
int i;
char bookname[10],choice;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("书名:\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
   if(strcmp(bookname,book[i].bookname)!=0)
   {
    fwrite(&book[i],sizeof(struct book),1,fp2);
   }
}
fclose(fp);
fclose(fp2);
printf("确认删除(y/n)?\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
   fp=fopen("book.txt","w");
   fp2=fopen("bookl.txt","r");
   for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
   {
    fwrite(&book[i],sizeof(struct book),1,fp);
   }
   fclose(fp);
   fclose(fp2);
   fp2=fopen("bookl.txt","w");
   fclose(fp2);
   printf("按任意键返回...\n");
   getch();
   return 0;
}
else
{
   printf("按任意键返回...\n");
   getch();
   return 0;
}
}
/*(3)修改图书*/
changebook()
{
FILE *fp,*fp2;
char bookname[10],choice;
int i;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("书名:\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
   if(strcmp(book[i].bookname,bookname)==0)
   {
    printf("你所要修改的书的资料如下,请选择你要修改的内容:\n");
    printf("序号       书名      作者 \n");
    printf("%d   %s  %s\n",book[i].booknum,book[i].bookname,book[i].bookcreat); printf("1: 修改书号:\n");
    printf("2: 修改书名:\n");
    printf("3: 修改作者:\n");
printf("4: 修改单价:");
    printf("请输入1━3:");
     choice=getch();
    switch(choice)
    {
     case '1':
     {
      printf("新书号:\n");
      scanf("%d",&book[i].booknum);
      fwrite(&book[i],sizeof(struct book),1,fp2);
     }break;
     case '2':
     {
      printf("新书名:\n");
      scanf("%s",book[i].bookname);
      fwrite(&book[i],sizeof(struct book),1,fp2);
     }break;
     case '3':
     {
      printf("新的作者:\n");
      scanf("%s",book[i].bookcreat);
      fwrite(&book[i],sizeof(struct book),1,fp2);
     }break;
case '4':
{
printf("新的单价:");
scanf("%f",book[i].bookprice);
        fwrite(&book[i],sizeof(struct book),1,fp2);    }
     default:printf("没有这样的操作!");break;
    }
    continue;
   }
   fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
   fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回...\n");
getchar();
return 0;
}
/*(4).图书统计*/
 void 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("第%d本书\n序号           书名               作者       单价    状态 \n",i+1);
    printf(" %d       %10s    ",book[i].booknum,book[i].bookname);
printf("%15s      %4.2f    %d(1在/0不在)\n",book[i].bookcreat,book[i].bookprice,book[i].turefalse);n=n+1;
   }
}
fclose(fp);
printf("目前共有%d本书.\n",n);
printf("按任意键返回...\n");
}
/*结束界面函数*/
void end()
{   system("cls");
printf("\t\t********************************\n");
printf("\t\t********************************\n");
printf("\t\t**** 谢谢使用本系统 , 再见! ****\n");
printf("\t\t********************************\n");
printf("\t\t********************************\n");   
}
/*主函数*/
void main()
{
char ch1,ch2,ch4;
do
{  system("cls");
   printf("\t\t********************************\n");
printf("\t\t***** 欢迎进入图书管理系统 *****\n");
   printf("\t\t********************************\n");
 printf("\t\t********************************\n");
   printf(" 请选择:\n");
   printf(" 1:查阅图书 \n");
   printf(" 2:借阅图书 \n");
   printf(" 3:管理系统 \n");
   printf(" 4:还书 \n");
   printf(" 0:退出 \n");
   printf("请输入0━4:\n");
   ch1=getch();
   switch(ch1)
   {
    case '1':chabook();break;
    case '2':lendbook();;break;
    case '3':{
       do
       {
        system("cls");
        printf("\t\t*******欢迎进入管理系统*******\n");
        printf(" 1:增加图书 \n");
        printf(" 2:删除图书 \n");
        printf(" 3:修改图书 \n");
        printf(" 4:图书统计 \n");
        printf(" 0:返回 \n");
        printf("请输入0━4:\n");
         ch2=getch();
        switch(ch2)
        {
         case '1':addbook();
         break;
         case '2':delbook();break;
         case '3':changebook();break;
         case '4':bookcount();getch();break;
        
         case '5':{
            do
            {
            system("cls");
            printf("\t\t????欢迎进入学生管理系统????\n");
            printf(" 1: 借书统计 \n");
            printf(" 0: 返回 \n");
            printf("请输入0━1:\n");
             ch4=getch();
            switch(ch4)
            {
              case '1':lendcount();break;
              case '0':break;
              default:printf("无此操作!\n");getch();break;
             }
            }while(ch4!='0');}break;
            case '0':break;
            default:printf("无此操作!\n");getch();break;
           }
        }             while(ch2!='0');}break;
        case '4':huanbook();break;
        case '0':break;
        default:printf("无此操作!\n");getch();break;
   }
}while(ch1!='0');
}


谢谢

搜索更多相关主题的帖子: 书籍 include 
2012-04-18 17:13
wuya156
Rank: 2
等 级:论坛游民
帖 子:29
专家分:38
注 册:2010-3-11
收藏
得分:10 
这一坨代码无非就是文件操作,还有注释,你自己连看都不看就贴出这让人给你改好,比作业贴还懒得给你看
2012-04-18 19:00
qidian123
Rank: 2
等 级:论坛游民
帖 子:19
专家分:34
注 册:2012-4-18
收藏
得分:0 
这是什么啊

www.jiajunyuanlin.com  www.futegz.comjtiao.com
2012-04-18 21:11
学小强编程
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2011-12-4
收藏
得分:0 
回复 2楼 wuya156
这里的一部分是可以运行的,是我写的,有的是模仿的,不知道如何运行,所以。。
2012-04-19 19:16
飞扬冲天
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:86
专家分:122
注 册:2011-10-21
收藏
得分:15 
一个main然后要用啥调用啥...
2012-04-19 20:27
学小强编程
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2011-12-4
收藏
得分:0 
多谢各位好人,我已经解出来啦
2012-04-20 18:21
快速回复:谁能使这个代码完整运行。各个功能全部能使用
数据加载中...
 
   



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

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