| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1273 人关注过本帖
标题:小的图书管理系统
取消只看楼主 加入收藏
小小的世界
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-5-23
结帖率:100%
收藏
 问题点数:0 回复次数:2 
小的图书管理系统
# include <stdio.h>
# include <stdlib.h>
#include "string.h"
# define SIZE 50
p1();p2();p3();p4();p5();p6();p7();p8();p9();
struct tushu
{
    char shuming[20];
    char isbn[20];
    int yeshu;
    int jiage;
    int shuliang;
}a[SIZE],temp;
int s=0;
main()//--------------------------------主菜单--------------------------------//
{
      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("                       0、 退出\n");
    printf("=================================================================\n");
    do
    {   
        printf("\t\t\t 请您选择序号:");
        scanf("%d",&n);
      switch(n)
      {
        case 1:p1();break;
        case 2:p2();break;   
        case 3:p3();break;
        case 4:p4();break;
        case 5:p5();break;
        case 6:p6();break;
        case 7:p7();break;
        case 0:printf("程序结束\n");break;
        }
    }
    while(n!=0);
}
//*------------------------------------ 图书信息批量录入 ------------------------------*//               
p1()
{
    FILE *fp;
    int i;
    fp=fopen("e:家庭图书信息.txt","r+"); //*以只读方式打开当前目录下的家庭图书信息.txt*//
    if(fp==NULL)
    {
        printf("无法打开文件");
        exit(0);    //*-------- 终止程序 ---------*//
    }
    printf("书名\t\tISBN号\t\t页数\t\t价格\t\t数量\n");
    for(i=0;!feof(fp);i++) //*------!feof(fp)值为0,不在执行循环语句  ------*//
    {
        fscanf(fp,"%s %s %d %d %d\n",a[i].shuming,a[i].isbn,&a[i].yeshu,&a[i].jiage,&a[i].shuliang);
        s++;
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
    fclose(fp);    //*----关闭文件-----*//
 }
//*--------------------------------------  图书信息修改 --------------------------*//
p2()
{
    int i,m=0;                                    
    char shuming[20];                                    
    FILE *fp;
    fp=fopen("e:\\家庭图书信息.txt","w");//*----W是为输出打开一个文本文件------*//
    printf("请输入您要修改的书名");
    scanf("%s",shuming);
    for(i=0;i<s;i++)
    {
        if(strcmp(shuming,a[i].shuming)==0)
        {
            printf("请输入你要修改后的书名");
            scanf("%s",a[i].shuming);
            printf("请输入你要修改后的IBSN码");
            scanf("%s",&a[i].isbn);
            printf("请输入你要修改后的页数");
            scanf("%d",&a[i].yeshu);
            printf("请输入你要修改后的书价");
            scanf("%d",&a[i].jiage);
            printf("请输入你要修改后的数量");
            scanf("%d",&a[i].shuliang);
        }
        else
        m++;
        if(m==s)
        printf("没有找到所要修改的书\n");
    }
                           
    for(i=0;i<s;i++)
    {
        fprintf(fp,"%s %s %d %d %d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
    fclose(fp);
}
//*------------------------------------- 图书信息删除 -------------------------*//
p3()
{
       int i,m=0;                                    
    char shuming[20];
    FILE *fp;
    fp=fopen("e:家庭图书信息.txt","w");
    printf("请输入你要删除的书名");
    scanf("%s",shuming);
    for(i=0;i<s;i++)
    {
        if(strcmp(shuming,a[i].shuming)==0)
        {
            for(;i<s;i++)
            {
                a[i]=a[i+1];               
            }
            s=s-1;
        }
        else
        m++;   
        if(m==s)
        printf("没有找到你要删除的书\n");
    }
    for(i=0;i<s;i++)
    {
        fprintf(fp,"%s %s %d %d %d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
    fclose(fp);
}
//*-------------------------------------- 图书出借--- ---------------------------*//
p4()
{
    int i,m=0,n;                                    
    char shuming[20];                                    
    FILE *fp;
    fp=fopen("e:家庭图书信息.txt","w");
    printf("请您输入您要借阅的书名");
    scanf("%s",shuming);
    for(i=0;i<s;i++)
    {
        if(strcmp(shuming,a[i].shuming)==0)
        {
            printf("请输入你要借数量");
            scanf("%d",&n);
            if(a[i].shuliang==0)
            {
                printf("你要的书已经借光\n");
            }
            if(n>a[i].shuliang)
            {
                printf("你要借的书籍数量已不够\n");
            }
            else
            {
                a[i].shuliang=a[i].shuliang-n;
                printf("你可以借阅\n");
            }
        }
        else
        m++;
        if(m==s)
        printf("抱歉,没有此书\n");

    }
   
    for(i=0;i<s;i++)
    {
        fprintf(fp,"%s %s %d %d %d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
    fclose(fp);
}
//*-------------------------------- 图书归还 -------------------------*//
p5()
{
    int i,m=0,n;                                    
    char shuming[20];                                    
    FILE *fp;
    fp=fopen("e:家庭图书信息.txt","w");
    printf("请您输入您要归还的书名");
    scanf("%s",shuming);
    for(i=0;i<s;i++)
    {
        if(strcmp(shuming,a[i].shuming)==0)
        {
            printf("请输入你要归还的数量");
            scanf("%d",&n);
        
                a[i].shuliang=a[i].shuliang+n;
        }
        else
        m++;
        if(m==s)
        printf("抱歉,出错,此书并未借出\n");
    }
   

    for(i=0;i<s;i++)
    {
        fprintf(fp,"%s %s %d %d %d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
    fclose(fp);
}
//*------------------------------ 单个图书信息插入 -----------------------*//
p6()
{
    int i;
    FILE *fp;
    fp=fopen("e:家庭图书信息.txt","r+");    //*------- 为读写打开一个文本文件 --------*//
    for(i=0;i<s+1;i++)
    {
        if(i==s)
        {
            printf("请输入你要增加的书名");
            scanf("%s",a[i].shuming);
            printf("请输入你要增加的书的IBSN码");
            scanf("%s",&a[i].isbn);
            printf("请输入你要增加的书的页数");
            scanf("%d",&a[i].yeshu);
            printf("请输入你要增加的书的价格");
            scanf("%d",&a[i].jiage);
            printf("请输入你要增加的书的本数");
            scanf("%d",&a[i].shuliang);
        }
    }
    for(i=0;i<s+1;i++)
    {
        fprintf(fp,"%s %s %d %d %d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
   
   
   
}
//*-------------------------------- 排序输出 -----------------------------*//
p7()
{   
    int n;
    printf("                          请您选择排序方式\n");
    printf("=================================================================\n");
    printf("                       1、 按书的价格排序输出\n");
    printf("                       2、 按书的页数排序输出\n");
    printf("                       0、 返回主菜单\n");
    printf("=================================================================\n");
    do
    {
        printf("                       请您选择序号:");
        scanf("%d",&n);
        switch(n)
        {
            case 1:p8();break;
            case 2:p9();break;
            case 0:
                {
                    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("                       0、 退出\n");
                    printf("=================================================================\n");
                }
                break;
            default:printf("error\n");
        }
    }
    while(n!=0);
}
//*----------------------------- 按书的价格排序 -------------------*//
p8()
{
   
    int i,j;
    for(i=0;i<s;i++)  //*---------- 起泡法排序 -----------*//
    {
        for(j=0;j<s-i-1;j++)
        {
            if(a[j].jiage>a[j+1].jiage)   
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    printf("按书的价格排序\n");
    printf("书名\t\tISBN号\t\t页数\t\t价格\t\t数量\n");
    for(i=0;i<s;i++)
    {
        if(a[i].shuliang>0)
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
}   
//*------------------------------ 按书的页数排序 -----------------------*//
p9()
{  
    int i,j;
    for(i=0;i<s;i++)    //*--- --起泡法排序 -------*//
    {
        for(j=0;j<s-i-1;j++)
        {
            if(a[j].yeshu>a[j+1].yeshu)  
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    printf("按书的页数排序\n");
    printf("书名\t\tISBN号\t\t页数\t\t价格\t\t数量\n");
    for(i=0;i<s;i++)
    {
        if(a[i].shuliang>0)
        printf("%s\t\t%s\t\t%d\t\t%d\t\t%d\n",a[i].shuming,a[i].isbn,a[i].yeshu,a[i].jiage,a[i].shuliang);
    }
}
搜索更多相关主题的帖子: 图书管理系统 
2010-05-23 15:35
小小的世界
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-5-23
收藏
得分:0 
呵呵,谢啦,才入门那,这是才做的
2010-05-23 17:00
小小的世界
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-5-23
收藏
得分:0 
我很菜的
2010-05-24 21:47
快速回复:小的图书管理系统
数据加载中...
 
   



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

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