| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3450 人关注过本帖
标题:急:求教,图书管理系统怎么删除图书信息啊?
只看楼主 加入收藏
我想要说
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-2-23
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
急:求教,图书管理系统怎么删除图书信息啊?
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

/*学生信息*/
typedef struct{
    char name[20];//姓名
    char num[12];//学号
    char chass[10];//班级
    char sex[5];//性别
}student;

typedef struct{
    int stucount;
    student stu[100];
}mstu;
mstu studata;

/*图书信息*/
typedef struct{
    int  booknumber;        //图书编号
    char bookname[20];      //图书名称
    char bookwriter[20];    //图书作者
    int  status;           //图书的状态,有多少本
    float price;           //图书的价格
}book;
typedef struct{
    int count;
    book book[100];
}mlibrary;
mlibrary library;//存储图书信息
void save_book()//保存图书信息。
{
    FILE *fp;
    if((fp=fopen("library.doc","w"))==NULL)
    {
        printf("\n不能保存图书信息\n");
        return;
    }   
    fwrite(&library.count,sizeof(int),1,fp);
    fwrite(library.book,sizeof(library.book[0]),library.count,fp);
}

void save_stu(){
    FILE *fp;
    if((fp=fopen("student.doc","w"))==NULL){
        printf("\n不能保存用户注册信息\n");
        return;
    }
    fwrite(&studata.stucount,sizeof(int),1,fp);
    fwrite(studata.stu,sizeof(studata.stu[0]),studata.stucount,fp);
}

void function2();
int num_seek(int a){
    int i,flag;
    flag=0;
    for(i=0;i<=library.count;i++)
        if(a==library.book[i].booknumber){
            printf("图书编号\t书名\t\t作者\t数量\t价格\n");
            printf("%d\t\t%s\t%s\t%d\t%f\n",
            library.book[i].booknumber,library.book[i].bookname,library.book[i].bookwriter,library.book[i].status,library.book[i].price);
            flag=1;}
    if(flag==0)
        printf("没有找到相符合的书");
    return flag;
}
int name_seek(char name[20]){
    int flag,i;
    flag=0;
    for(i=0;i<=library.count;i++)
        if(!strcmp(name,library.book[i].bookname)){
            printf("图书编号\t书名\t\t作者\t数量\t价格\n");
            printf("%d\t\t%s\t%s\t%d\t%f\n",
            library.book[i].booknumber,library.book[i].bookname,library.book[i].bookwriter,library.book[i].status,library.book[i].price);
            flag=1;}
    if(flag==0)
        printf("没有找到相符合的书");
    return flag;
}

int author_seek(char writer[]){
    int flag,i;
    flag=0;
    for(i=0;i<=library.count;i++)
        if(!strcmp(writer,library.book[i].bookwriter)){
            printf("图书编号\t书名\t\t作者\t数量\t价格\n");
            printf("%d\t\t%s\t%s\t%d\t%f\n",
            library.book[i].booknumber,library.book[i].bookname,library.book[i].bookwriter,library.book[i].status,library.book[i].price);
            flag=1;}
    if(flag==0)
        printf("没有找到相符合的书");
    return flag;
}
/*新进图书信息输入*/
void function1(){
    int y=1;
    system("cls");
    while(y)
    {
        printf("\t请输入您的书籍的书号:");
        scanf("%d",&library.book[library.count].booknumber);
        printf("\t请输入图书名称:");
        scanf("%s",library.book[library.count].bookname);
        printf("\t请输入作者名:");
        scanf("%s",library.book[library.count].bookwriter);
        printf("\t请输入图书的数量:");
        scanf("%d",&library.book[library.count].status);
        printf("\t请输入该书的价格:");
        fflush(stdin);
        scanf("%f",&library.book[library.count].price);
        library.count++;
        printf("\n是否继续录入(1.继续;0,退出录入):");
        scanf("%d",&y);
        if (y!=1)
        {
            y=0;
            break;
        }
    }
     save_book();
}
/*图书信息查询*/
void function2(){
    int a,i;
    system("cls");
    printf("请选择查找方式:\n1.图书编号 \n2.图书名称 \n3.图书作者\t");
    scanf("%d",&a);
    switch(a){
    case 1:{
        system("cls");
        int a;
        printf("\t\t**********按编号查找**********\n");
        printf("请输入图书编号:");
        scanf("%d",&a);
        num_seek(a);
        break;}
    case 2:{
        system("cls");
        char search[20];
        printf("\t\t**********按图书名称查找**********\n");
        printf("输入图书名称:\t");
        scanf("%s",search);
        name_seek(search);
        break;}
    case 3:{
        system("cls");
        char writer[20];
        printf("\t\t**********按图书作者查找**********\n");
        printf("输入图书作者:\t");
        scanf("%s",writer);
        author_seek(writer);
        break;}
    case 0:exit(0);
    }
    printf("\n是否继续查找?1:继续 0:退出");
    scanf("%d",&i);
    if(i==1)
        function2();
    else
        return;
}
/*图书信息的删除*/
void function3(){
    int number;
    system("cls");
    printf("\n    输入你想要删除书的编号:");
    fflush(stdin);
    scanf("%d",&number);
    int i;
    for (i=0;i<library.count;i++)
    {
        if(number==library.book[i].booknumber) break;   
    }
    if (i!=library.count)
    {
        for(;i<library.count-1;i++)
        {
            strcpy(library.book[i].bookname,library.book[i+1].bookname);
            strcpy(library.book[i].bookwriter,library.book[i+1].bookwriter);
            library.book[i].booknumber=library.book[i+1].booknumber;
            library.book[i].status=library.book[i+1].status;
            library.book[i].price=library.book[i+1].price;
        }
        library.count--;
        printf("删除成功,重启程序后生效");
    }
    else
        printf("\n cannot found!\n");
    save_book();
    fflush(stdin);
    getchar();
}
void function4(){
    system("cls");
    printf("编号\t书名\t\t作者\t状态\t价格\n");
    for(int i=0;i<library.count;i++)
        printf("%d\t%s\t%s\t%d\t%f\n",library.book[i].booknumber,library.book[i].bookname,library.book[i].bookwriter,library.book[i].status,library.book[i].price);
    printf("\n");printf("\n");
    printf("\t\t\t按任意键退出");
    getchar();
    getchar();
    return;
}
void main(){
    FILE *fp;
    if((fp=fopen("library.doc","r"))==NULL){
        printf("\n图书信息库不存在\n");
        fp=fopen("library.doc","w+");
        printf("\n初始化图书信息库,请重启程序\n");
        library.count=0;
        fwrite(&library.count,sizeof(int),1,fp);
        fclose(fp);
        return;
    }
    fread(&library.count,sizeof(int),1,fp);
    fread(library.book,sizeof(library.book[0]),library.count,fp);
    fclose(fp);
    char choice;
    do{
        system("cls");
        printf("\t\t&&&&&&&&图书信息管理系统&&&&&&&&\n");
        printf("\n");
        printf("\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
        printf("\n");
        printf("\t\t@^6^      1:输入图书信息    ^6^@\n");
        printf("\t\t@                              @\n");
        printf("\t\t@^6^      2:查询图书信息    ^6^@\n");
        printf("\t\t@                              @\n");
        printf("\t\t@^6^      3:删除图书信息    ^6^@\n");
        printf("\t\t@                              @\n");
        printf("\t\t@^6^      4:全部图书浏览    ^6^@\n");
        printf("\t\t@                              @\n");
        printf("\t\t@^6^        0:退出服务      ^6^@\n");
        printf("\n");
        printf("\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
        printf("\n");
        printf("\t\t请在上述功能中选择您需要的服务:");
        choice=getchar();
        switch(choice){
        case '1':function1();break;//图书信息输入
        case '2':function2();break;//图书信息查询
        case '3':function3();break;//图书信息删除
        case '4':function4();break;//全部图书浏览
        case '0':exit(0);
              }
    }while(1);
    save_book();
    save_stu();
    return;
}
我删了还是能查到那本书
搜索更多相关主题的帖子: 图书 信息 include status 
2012-02-23 20:09
墨清扬
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:294
专家分:817
注 册:2011-10-4
收藏
得分:10 
num_seek里的for中,i<=,确定要=吗?

酱油实习生
2012-02-26 00:13
mayuebo
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:257
专家分:1282
注 册:2005-9-8
收藏
得分:10 
只是在内存中删除,没有写文件

成功贵在坚持
2012-02-26 07:26
快速回复:急:求教,图书管理系统怎么删除图书信息啊?
数据加载中...
 
   



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

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