| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 14688 人关注过本帖, 1 人收藏
标题:求高手 C编程图书管理系统
只看楼主 加入收藏
傲之冰枫
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-4-1
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:10 
求高手 C编程图书管理系统
图书信息管理程序(3人)
具体要求实现如下功能:
1)定义与图书相关信息的数据结构,包含书号,书名,作者,出版社,出版时间,总页数,定价等信息。
2)添加数据功能:向已有图书信息表中添加新的图书信息的功能。
3)删除数据功能:在已有数据中删除某个图书的相关数据,保证其他数据的正常使用。4)查询数据功能:在已有数据中查找某些图书的相关数据,并给出相关的查找结果;查找可以根据图书的书名或者出版社进行,如果查找成功,给出具体信息,否则给出没有找到的提示。
5)修改数据功能:对已有的图书信息进行修改。
6)排序功能:根据要求按照书号或者出版时间进行排序。
7)添加功能选择菜单。

程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
#define PF printf
#define SF scanf
struct books
    {
        int booknum;        //书号
        char bookname[20];  //书名
        char authorname[20];//作者
        char cbs[20];       //出版社
        int  price;         //价格   
   
    };struct books book[N];
   
int luru(struct books * p_book,int i)//录入函数    p_book=book;i=n;
{   
    system("cls");//清屏
   
    while(1)
    {   char ch;
        PF("~~~~~~~~~~~~~~~开始输入信息~~~~~~~~~~~~~\n");
        PF("请输入书的编号:");
        SF("%d",&p_book->booknum);PF("\n");//book[i].booknum
        PF("请输入出版社:");
        SF("%s",p_book->cbs);PF("\n");//
        PF("请输入图书价格:");
        SF("%d",&p_book->price);PF("\n");
        PF("请输入书名:");
        SF("%s",p_book->bookname);PF("\n");
        getchar( );//屏蔽回车
        PF("请输作者名:");
        gets(p_book->authorname);
        ++i;
        PF("是否继续输入,请选择(y/n):");
        SF("%c",&ch);
            if(ch=='n')break;
            else p_book++;
   
        

        
    }
        return i;        
}



void paixu(struct books book[],int i)//按书号进行排序  
{   
    int n,a,temp;
    char t1[20],t2[20],t3[20];
    for(n=0;n<i-1;n++)//趟数
    for(a=0;a<i-1-n;a++)//每趟的次数
        if(book[a].booknum>book[a+1].booknum)//整型的比较
        {   
            {temp=book[a].booknum;book[a].booknum=book[a+1].booknum;book[a+1].booknum=temp;}//书号换位
            {strcpy(t1,book[a].bookname);strcpy(book[a].bookname,book[a+1].bookname);strcpy(book[a+1].bookname,t1);}//书名换位
            {strcpy(t2,book[a].cbs);strcpy(book[a].cbs,book[a+1].cbs);strcpy(book[a+1].cbs,t2);}//出版社换位
            {temp=book[a].price;book[a].price=book[a+1].price;book[a+1].price=temp;}//价格换位
            {strcpy(t3,book[a].authorname);strcpy(book[a].authorname,book[a+1].authorname);strcpy(book[a+1].authorname,t3);}//书作者换位
        }
        system("cls");
            PF("书号\t书名\t出版社\t价格\t作者\n");
        for(a=0;a<i;a++)
            PF("%d\t%s\t%s\t%d\t%s\n",book[a].booknum,book[a].bookname,book[a].cbs,book[a].price,book[a].authorname);

}

void cx1(struct books book[],int i)//书名查询
{
    int a;
    char name[20];
        system("cls");
        PF("|按书名查询|\n");
        SF("%s",&name);
        for(a=0;a<i;a++)
        if(strcmp(name,book[a].bookname)==0)
        {
        PF("书号\t书名\t出版社\t价格\t作者\n");
        PF("%d\t%d\t%d\t%.2f\t%s\n",book[a].booknum,book[a].bookname,book[a].cbs,book[a].price,book[a].authorname);
        }
        else PF("没有你要的查询结果\n");
}
void cx2(struct books book[],int i)//作者名查询
{
    int a;char g[20];
        system("cls");
        PF("|按作者名查询|\n");
            scanf("%s",&g);
        for(a=0;a<i;a++)
            if(strcmp(g,book[a].authorname)==0)
            {
                PF("书号\t书名\t出版社\t价格\t作者\n");
                PF("%d\t%d\t%d\t%.2f\t%s\n",book[a].booknum,book[a].bookname,book[a].cbs,book[a].price,book[a].authorname);
            }
        else PF("没有你要的查询结果\n");
}

void chaxun(struct books shu[],int i)//查询
{   
    int x;
    system("cls");
    PF("~~~~~~~~~~~~~~~~图书信息查询~~~~~~~~~~~~~~~\n");
    PF("********请选择查询方式********\n");
    PF("|1.按书名查询|\n");
    PF("|2.按作者名查询|\n");
    PF("请输入你选择___");
    SF("%d",&x);
    switch(x)
    {
    case 1:cx1(book,i);break;//调用cx1函数完成按书名查询
    case 2:cx2(book,i);break;//调用cx2函数完成按作者查询

    default :PF("输入有误,请重新输入!\n");break;
    }

   
}
/*int fl(struct books shu[],int i)//按书号删除
{   
    int y,h,m;int j;
    fanhui:PF("请你输入想要删除图书的书号\n");
    scanf("%d",&y);//接收书号
        if(y>=i)
        {
            PF("您要删除的图书信息不存在\n");return 0;
        }
        else
        {
            y=y-1;
            
        PF("书号\t书名\t出版社\t价格\t作者\n");
        PF("%d\t%d\t%d\t%.2f\t%s\n",shu[y-1].booknum,shu[y-1].bookname,shu[y-1].cbs,shu[y-1].price,shu[y-1].authorname);
        PF("你确定要删除以上信息吗?\n");
        PF("|1.是,确认删除\n");
        PF("|2.否,返回上一层\n");
        PF("|3.返回主菜单\n");
        SF("%d",&h);
        switch(h)
        {
        case 1:
               
            for(m=0;m<i;m++)
               {
                    if(y==shu[m].booknum&&y<i-1)
                    {

                        shu[m].booknum=shu[m+1].booknum;
                        for(j=m;j<i-1;j++)
                        {
                            shu[j].booknum=shu[j+1].booknum;
                            shu[j].bookname=shu[j+1].bookname;
                            shu[j].cbs=shu[j+1].cbs;
                            strcpy(shu[j].price,shu[j+1].price);
                            strcpy(shu[j].authorname,shu[j+1].authorname);
                        }
                        i--;
                    }
                    if(y==shu[m].booknum&&m==i-1)
                        i--;
               }
            PF("i=%d",i);break;
            
        case 2: system("cls");
            goto fanhui;break;// 返回
        case 3:system("cls");break;
        default :PF("输入有误,请重新输入!\n");break;
            
        }
        }
        return i;
}*/
int sm(struct books shu[],int i)//按书名删除
{
    char book[20];int a,h,m;
    fanhui:printf("请你输入想要删除图书的名称\n");
    SF("%s",book);//接收书名
    for(a=0;a<i;a++)
        if(strcmp(book,shu[a].bookname)==0)
        {
            PF("书号\t书名\t出版社\t价格\t作者\n");
            PF("%d\t%d\t%d\t%.2f\t%s\n",shu[a].booknum,shu[a].bookname,shu[a].cbs,shu[a].price,shu[a].authorname);
            PF("你确定要删除以上信息吗?\n");
            PF("|1.是,确认删除\n");
            PF("|2.否,返回上一层\n");
            PF("|3.返回主菜单\n");
            SF("%d",&h);
            SF("%d",&h);
            switch(h)
            {
            case 1:for(m=0;m<i;m++)
                    {
                    if(a==m&&a<i-1)
                    {
                        m=m+1;
                    }
                    if(a==m&&m==i-1)
                        i--;
                   }
            return --i;break;
        case 2:system("cls");
            goto fanhui;break;//返回
        case 3:system("cls");break;
        default :PF("输入有误,请重新输入!\n");break;
               
            }
        }
        if(strcmp(book,shu[a].bookname)!=0) printf("您要删除的图书信息不存在\n");
        return i;
}
int del(struct books shu[],int i)//删除信息
{
    int h;
    system("cls");
    PF("~~~~~~~~~~~~~~~~图书信息删除~~~~~~~~~~~~~~~\n");
    PF("|1.图书的书号|\n");
    PF("|2.图书的书名|\n");
    SF("%d",&h);
    switch(h)
    {
    //case 1:    system("cls");i=fl(shu,i);break;//按书号删除
    case 2:    system("cls");i=sm(shu,i);break;//按书名删除
    default :PF("输入有误,请重新输入!\n");break;
    }
    return i;
}
int charu(struct books shu[],int i)//插入信息
{
    system("cls");
        PF("~~~~~~~~~~~~~~~开始插入信息~~~~~~~~~~~~~\n");
        PF("请输书号\n");
        SF("%d",&shu[i].booknum);
        PF("请输入书名\n");
        SF("%d",&shu[i].bookname);
        PF("请输入价格\n");
        SF("%f",&shu[i].price);
        PF("请输入出版社\n");
        SF("%s",&shu[i].cbs);
        getchar( );//屏蔽回车
        PF("请输作者名\n");
        gets(shu[i].authorname);
        i++;
        system("cls");
        PF("插入信息成功\n");
        return i;        

}
void main()
{
    int choice,n=0;
    for( ; ; )
    {   
        system("cls");
        {
        PF("\t\t*****************图书信息管理系统*****************\n");
        PF("\t\t*\t\t|1.图书信息录入                  *\n");
        PF("\t\t*\t\t|2.图书信息浏览                  *\n");
        PF("\t\t*\t\t|3.图书信息查询                  *\n");
        PF("\t\t*\t\t|4.图书信息的删除                *\n");
        PF("\t\t*\t\t|5.图书信息的插入                *\n");
        PF("\t\t*\t\t|6.退出系统                      *\n");
        PF("\t\t*****************图书信息管理系统*****************\n\n\n");
        PF("\t\t请输入以上序号进行选择:\n");
        SF("%d",&choice);
        }
    switch(choice)
    {
    case 1:n=luru(book,n);//录入  book[0]
        system("pause");break;
    case 2:paixu(book,n);//liulan(book,n);//浏览
        system("pause");break;
    case 3:chaxun(book,n);//查询
        system("pause");break;
    case 4:n=del(book,n);
        system("pause");break;
    case 5:n=charu(book,n);
        system("pause");break;
    case 6:exit(0);
        system("pause");
    default :PF("输入有误,请重新输入!\n");
        system("pause");break;
    }
}
}
搜索更多相关主题的帖子: 出版社 时间 
2011-04-01 13:56
傲之冰枫
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-4-1
收藏
得分:0 
帮我看看 怎搞 知道写链表的写个 链表的程序 给我吧。。谢谢 不会的 帮我看下这个程序要怎么改 谢谢
2011-04-01 13:57
张敏樱木花道
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:139
专家分:137
注 册:2011-3-26
收藏
得分:3 
好贴,我今天又长见识了……谢了!
2011-04-01 14:01
傲之冰枫
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-4-1
收藏
得分:0 
高手啊
2011-04-01 14:15
vandychan
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
等 级:贵宾
威 望:18
帖 子:2296
专家分:6418
注 册:2010-8-20
收藏
得分:3 
麻烦结贴子啊

到底是“出来混迟早要还”还是“杀人放火金腰带”?
2011-04-01 22:20
hnuhsg1226
Rank: 9Rank: 9Rank: 9
来 自:中国
等 级:蜘蛛侠
威 望:2
帖 子:314
专家分:1314
注 册:2011-3-27
收藏
得分:3 
为了帮你做一个,差点把我绕进去了,我这个是双向链表的,输入的时候就是按学号排序的,所以要按要求排序还得自己好好想想,界面之类的自己去弄吧:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct books{
        char booknum[20];        //书号
        char bookname[20];       //书名
        char authorname[20];     //作者
        char cbs[20];            //出版社
        char price[5];           //价格
        struct books *next;
        struct books *prior;  
};

struct books *head;       //头结点
struct books *last;       //尾结点

int menu(void);    //菜单选项
void inputs(char *prompt,char *s,int count);//输入格式
void enter(void);                           //信息输入
void dls_store(struct books *i,struct books **head,struct books **last);//按书号大小建立链表
struct books *find(char *bn);                      //按书名检索
void search(void);                                 //按书名查找
void modify(void);                                 //修改信息
void display(struct books *p);                       //显示格式
void list(void);
void del(struct books **head,struct books **last);           //删除信息
void save(void);             //以文件形式保存信息
void load(void);              //从文件中载入信息


void inputs(char *prompt,char *s,int count)
{
     char p[255];
     do{
          printf(prompt);
          gets(p);
          if(strlen(p) > count)  //限定输入字符长度
          {
                printf("\nToo long\n");
          }
     }while(strlen(p) > count);      
     strcpy(s,p);
}

void enter(void)       //输入信息
{
    system("cls");//清屏
    char ch;
    struct books *p;
    while(1)
    {               
          p=(struct books *)malloc(sizeof(struct books));
          char ch;         
          inputs("请输入书的编号:",p->booknum,20);
          inputs("请输入书名:",p->bookname,20);
          inputs("请输作者名:",p->authorname,20);
          inputs("请输入出版社:",p->cbs,20);
          inputs("请输入图书价格:",p->price,5);
          printf("\n");
          dls_store(p,&head,&last);
          printf("是否继续输入(Y/N):");
          ch = getchar();
          if(ch == 'N') break;
          fflush(stdin);
    }
}
                  
void dls_store(struct books *i,struct books **head,struct books **last)   //按书号顺序插入表中
{
     struct books *p,*old;
     if((*last) == NULL)
     {
          i->prior = NULL;
          i->next = NULL;
          (*head) = i;
          (*last) = i;
          return;
     }
     p = (struct books *)malloc(sizeof(struct books));
     p = (*head);
     old = NULL;
     while(p!=NULL)
     {
           if(strcmp(p->booknum,i->booknum) < 0)   
           {
                  old = p;
                  p = p->next;
           }
           else
           {
                  if(p->prior)
                  {
                       p->prior->next = i;
                       i->next = p;
                       i->prior = p->prior;
                       p->prior = i;
                       return;
                  }
                  i->next = p;          //放表头
                  i->prior = NULL;
                  p->prior = i;
                  *head = i;
                  return;
           }
     }//end while
     old->next = i;
     i->next = NULL;
     i->prior = old;
     *last = i;
}
           
struct books *find(char *bn)     //按书名搜索关键字
{
    struct books *p;
    p = head;
   
    while(p!=NULL)
    {
          if(strcmp(bn,p->bookname) == 0)
          {
                return p;
          }
          p = p->next;
    }
    return NULL;
}

void search(void)
{
     char name[20];
     struct books *p;
     printf("请输入你要查询的书名:");
     gets(name);
     p = find(name);
     if(p == NULL)  printf("没有找到你查询的信息.\n");
     else display(p);
}

void modify(void)  //根据书名查找并修改信息
{
     char name[20];
     struct books *p;
     printf("请输入你要查询的书名:");
     gets(name);
     p = find(name);
     if(p == NULL)  printf("没有找到你查询的信息.\n");
     else
     {
          inputs("请输入书的编号:",p->booknum,20);
          inputs("请输入书名:",p->bookname,20);
          inputs("请输作者名:",p->authorname,20);
          inputs("请输入出版社:",p->cbs,20);
          inputs("请输入图书价格:",p->price,5);
          printf("\n");
     }
}

void display(struct books *p)
{
     printf("%s\t",p->booknum);        //书号
     printf("%s\t",p->bookname);       //书名
     printf("%s\t",p->authorname);     //作者
     printf("%s\t",p->cbs);            //出版社
     printf("%s\t",p->price);
     printf("\n");
}

void list(void)
{
     system("cls");
     struct books *p;
     p = head;
     printf("书号\t书名\t作者\t出版社\t价格\n");
     while(p != NULL)
     {
             display(p);
             p = p->next;
     }
     printf("\n");
}

void del(struct books **head,struct books **last)
{
     struct books *i;
     
     char s[50];
     inputs("输入书名:",s,20);
     i = find(s);
     if(i)
     {
          if(*head == i)
          {
                *head = i->next;
                if(*head) (*head)->prior = NULL;
                else *last = NULL;
          }
          else
          {
                 i->prior->next = i->next;
                 if(i != *last)
                 {
                      i->next->prior = i->prior;
                 }
                 else
                 {
                     *last = i->prior;
                 }
          }
          free(i);
     }//end  if(i)
}

void save(void)
{
     struct books *p;
     FILE *fp;
     if((fp=fopen("books","wb")) == NULL)
     {
            printf("open file error.\n");
            exit(1);
     }               
     p = head;
     while(p!=NULL)
     {
            fwrite(p,sizeof(struct books),1,fp);
            p = p->next;
     }
     fclose(fp);
}

void load(void)
{
     struct books *p;
     FILE *fp;
     fp=fopen("books","rb");
     if(fp == NULL)
     {
           printf("open file error.\n");
           exit(1);
     }
     while(head)
     {
           p = head->next;
           free(p);
           head = p;
     }
     head = last = NULL;
     printf("\n 载入信息 \n");
     while(!feof(fp))
     {      
            p = (struct books *)malloc(sizeof(struct books));
            if(1 != fread(p,sizeof(struct books),1,fp)) break;
            dls_store(p,&head,&last);
     }
     fclose(fp);
}
                    
int menu(void)
{
    char s[20];
    int c;
    system("cls");
    printf("\t\t*****************图书信息管理系统*****************\n");
    printf("\t\t*\t\t|1.图书信息输入                   *\n");
    printf("\t\t*\t\t|2.图书信息浏览                   *\n");
    printf("\t\t*\t\t|3.图书信息查询                   *\n");
    printf("\t\t*\t\t|4.图书信息修改                   *\n");
    printf("\t\t*\t\t|5.图书信息删除                   *\n");
    printf("\t\t*\t\t|6.存储图书信息                   *\n");
    printf("\t\t*\t\t|7.载入图书信息                   *\n");
    printf("\t\t*\t\t|8.退出系统                       *\n");
    printf("\t\t*****************图书信息管理系统*****************\n\n\n");
    printf("\t\t请输入以上序号进行选择:\n");
    do{
          gets(s);
          c = atoi(s);
    }while(c<0||c>8);
    return c;
}

int main(void)
{
    head = last = NULL;
    while(1)
    {
        switch(menu())
        {
            case 1:enter();system("pause");//录入  
                   break;
            case 2:list();system("pause");//浏览
                   break;
            case 3:search();system("pause");
                   break;
            case 4:modify();system("pause");
                   break;
            case 5:del(&head,&last);system("pause");
                   break;
            case 6:save();system("pause");
                   break;
            case 7:load();system("pause");
                   break;
            case 8:exit(0);
        }//end switch
    }//end while
    return 0;
}

我的地盘
2011-04-03 21:51
t1melost
Rank: 1
等 级:新手上路
帖 子:22
专家分:3
注 册:2010-12-6
收藏
得分:3 
学习。
2011-04-04 12:59
简单回忆
Rank: 2
来 自:郴州
等 级:论坛游民
帖 子:89
专家分:28
注 册:2011-3-19
收藏
得分:3 
又见神般得人物
2011-04-04 14:04
chenhuixiang
Rank: 2
等 级:论坛游民
帖 子:10
专家分:22
注 册:2011-4-4
收藏
得分:3 
高手,我要学习
2011-04-04 20:50
mandown1991
Rank: 4
等 级:业余侠客
帖 子:262
专家分:252
注 册:2011-3-2
收藏
得分:3 
又学到了!
2011-04-05 14:54
快速回复:求高手 C编程图书管理系统
数据加载中...
 
   



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

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