| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 393 人关注过本帖
标题:求修改这段代码实现查找和架都能输入书名实现
只看楼主 加入收藏
slaidas
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-6-14
收藏
 问题点数:0 回复次数:0 
求修改这段代码实现查找和架都能输入书名实现
#include <stdlib.h>
#include <stdio.h>
#include "math.h"      

struct  Book                     /*书本结构*/
{
    int  m_iBook_Number;         /*对应书本号*/           
    char m_strTitle[150];        /*书名*/
    char m_strWroter[150];       /*作者*/   
    int  m_nMoreNum;             /*当前在架册数*/   
    int  m_nSjNum;               /*所在书架*/
    int  m_nSjList;              /*所在列数*/
    char m_strComment[2000];      /*图书简介*/
    float  m_Inprice;             /*图书进价*/
    float  m_Outprice;            /*图书售价*/
};

struct Info                      /*借售信息结构*/
{
    struct Info *m_pParentPoint; /*前驱结点*/      
    struct Book *m_pBookInfo;    /*对应书本的信息*/   
    struct Info *m_pSun;         /*后继结点*/
   
};

struct Book *InputNode();
struct Info *Search(struct Info *bth,int x,int *flag);/*查找图书*/
struct Info *Insert_BookInfo(struct Info *bth);/*图书上架*/
struct Info *Delete_BookInfo(struct Info *bth);/*图书下架*/
void   Output_BookInfo(struct Info *bth);/*打印输出书本信息*/
void   Sell_TheBook(struct Info *bth);/*图书出售*/
char   Select_Menu();/*书店管理系统主菜单*/

struct Info *Search(struct Info *bth,int x,int *flag)//查找图书
{
    struct Info *p=NULL;
   
    p=bth;
    *flag=0;
    while(p)
    {
        if(p->m_pBookInfo->m_iBook_Number==x)
        
        {
            /*找到相同的书名,置找到的标志*/
            *flag = 1;
            return p;
        }
        else
        {
            
            *flag = 0;
        }
        if(p->m_pSun!=NULL)
        {
            p = p->m_pSun;
            
        }
        else
        {
            break;
        }
        
    }

    return bth;
}

struct Book *InputNode() /*上架图书信息*/
{
    struct Book *p=NULL;
    p=(struct Book *)malloc(sizeof(struct Book));   
    system("cls");/*清屏*/
    fflush(stdin);  /*清除以前的输入*/
    printf("\n\t请输入书名: ");   
    gets(p->m_strTitle);/*从键盘取得书名*/
    printf("\n\t请输入作者: ");
    gets(p->m_strWroter);/*从键盘取得作者名*/   
    fflush(stdin);
    printf("\n\t请输入本书简介: ");
    gets(p->m_strComment);
    printf("\n\t请输入入架册数: ");
    scanf("%d",&p->m_nMoreNum);
    printf("\n\t请输入所入书架:");
    scanf("%d",&p->m_nSjNum);
    printf("\n\t请输入所入书架行数:");
    scanf("%d",&p->m_nSjList);
    printf("\n\t请输入本书进价(RMB):");
    scanf("%f",&p->m_Inprice);
    printf("\n\t请输入本书售价(RMB):");
    scanf("%f",&p->m_Outprice);
    return(p);  
}

struct Info *Insert_BookInfo(struct Info *bth) //图书入库
{
    int flag;
    int y,x,z;
    struct Info *p=NULL,*q=NULL,*u=NULL,*s=NULL;
    struct Book *r=NULL,*l=NULL;
    system("cls");
    printf("\n\t请输入你想上架的书本号: ");
    scanf("%d",&x);
    q=Search(bth,x,&flag);
    if(flag==1)   
    {
        printf("\n\t当前存在这本书%d本,您想再增加一本<<%s>>书?(y/n)\n",q->m_pBookInfo->m_nMoreNum,q->m_pBookInfo->m_strTitle);
        z=getch();
        if(z=='y'||z=='Y')      
        {
            printf("\n\t本店共有: %d 本未售出.",q->m_pBookInfo->m_nMoreNum);
            q->m_pBookInfo->m_nMoreNum++;  
            printf("\n\t上架后共有:  %d 本在本书店中.",q->m_pBookInfo->m_nMoreNum);
        }
        return(bth);
    }
    r=InputNode(bth);
    if(bth==NULL)
    {
        
        bth=p=(struct Info *)malloc(sizeof(struct Info));
        r->m_iBook_Number = x;
        p->m_pParentPoint= NULL;
        p->m_pSun=NULL;
        p->m_pBookInfo=r;
        return(p);
    }
    else
    {
   
        p=NULL;
        p=bth;
        while(p->m_pSun!=NULL)
        {
            p = p->m_pSun;
        }
        

        q=(struct Info *)malloc(sizeof(struct Info));
        r->m_iBook_Number = x;
        p->m_pSun = q;      
        q->m_pParentPoint= p;
        q->m_pSun=NULL;
        q->m_pBookInfo=r;
    }
    return(bth);  
}

struct Info *Delete_BookInfo(struct Info *bth)//图书下架
{
    int flag;
    int x,y;
    struct Info  *u=NULL,*s=NULL,*p=NULL,*q=NULL;
    struct Book  *bookinfo=NULL;
    struct Info *BookLeftPoint=NULL;
    struct Info *BookRightPoint = NULL;
    system("cls");
    printf("\n\t请输入你想下架的书本号: ");
    scanf("%d",&x);
    q=Search(bth,x,&flag);      
    if(flag==0)
    {
        printf("\n\t这本书不存在!\n");
        return(bth);
    }
    else
    {
        if(q==NULL)
        {
            printf("未知错误");
            return bth;
        }
        else
        {
            bookinfo=q->m_pBookInfo;
            printf("\n\t想下架的书本信息: ");   
            printf("\n\t书名:             %s",bookinfo->m_strTitle);   
            printf("\n\t作者:            %s",bookinfo->m_strWroter);
            printf("\n\t当前在架册数:     %d",bookinfo->m_nMoreNum);
            printf("\n\t所在书架:  %d",bookinfo->m_nSjNum);
            printf("\n\t所在行数:  %d",bookinfo->m_nSjList);
            printf("\n\t本书简介: %s\n",bookinfo->m_strComment);
            
            if(q->m_pParentPoint!=NULL && q->m_pSun!=NULL)
            {
                BookLeftPoint = q->m_pParentPoint;
                BookRightPoint = q->m_pSun;
                BookLeftPoint->m_pSun = BookRightPoint;
                BookRightPoint->m_pParentPoint = BookLeftPoint;
                q->m_pParentPoint = NULL;
                q->m_pSun = NULL;
                free(q->m_pBookInfo);
                q->m_pBookInfo = NULL;
                free(q);
                q = NULL;
                return bth;
            }
            else if(q->m_pParentPoint==NULL)
            {
               
                if(q->m_pSun==NULL)
                {
                    free(q->m_pBookInfo);
                    q->m_pBookInfo = NULL;
                    free(q);
                    q = NULL;
                    return q;
                }
                bth = q->m_pSun;
                bth->m_pParentPoint = NULL;
               
            
                BookRightPoint = q;
                BookRightPoint->m_pParentPoint = NULL;
                BookRightPoint->m_pSun = NULL;
               
                free(BookRightPoint->m_pBookInfo);
                BookRightPoint->m_pBookInfo = NULL;
                free(BookRightPoint);
                BookRightPoint = NULL;
               
                return bth;
            }
            else if (q->m_pSun==NULL)
            {
            

                BookLeftPoint = q->m_pParentPoint;
                BookLeftPoint->m_pSun = NULL;
                q->m_pParentPoint = NULL;
                free(q->m_pBookInfo);
                q->m_pBookInfo = NULL;
                free(q);
                q = NULL;
                return bth;
            }
        }
    }
}


void Output_BookInfo(struct Info *bth)
{
    struct Info *q=NULL;
    struct Book *p=NULL;
    int x=0;
 
    int flag=0;
    system("cls");
    printf("\n\t请输入你想查找的图书编号: ");
    scanf("%d",&x);
    q=Search(bth,x,&flag);   
    if(flag==1)
    {
        p=q->m_pBookInfo;
        printf("\n\t书名:             %s",p->m_strTitle);   
        printf("\n\t作者:            %s",p->m_strWroter);
        printf("\n\t当前在架册数:     %d",p->m_nMoreNum);
        printf("\n\t所在书架:%d",p->m_nSjNum);
        printf("\n\t所在行数:%d",p->m_nSjList);
        printf("\n\t本书简介: %s\n",p->m_strComment);
        printf("\n\t本书进价(RMB):%.2f",p->m_Inprice);
        printf("\n\t本书售价(RMB): %.2f",p->m_Outprice);
    }
    else printf("\n\t这本书不存在!");
}

void Sell_TheBook(struct Info *bth)
{
    struct Info *q=NULL;
    struct Book *p=NULL;
    int i,x, flag,t;
    system("cls");/*清屏*/
    printf("\n\t请输入你想出售的图书编号: ");
    scanf("%d",&x);
    q=Search(bth,x,&flag);
    if(flag==1)  
    {
        p=q->m_pBookInfo;
        printf("\n\t出售这本书 ?(y/n)");
        printf("\n\t书名:             %s",p->m_strTitle);
        printf("\n\t作者:            %s",p->m_strWroter);
        printf("\n\t当前在架册数:     %d",p->m_nMoreNum);
        printf("\n\t本书简介: %s\n",p->m_strComment);
        printf("\n\t本书售价(RMB):  %.2f",p->m_Outprice);
        t=getch();
        if(t=='y'||t=='Y')
        {
            if( (p->m_nMoreNum)==0) printf("\n\t对不起,本书已经全部售出请尽快上架...");
        else
            {
                system("cls");
                p->m_nMoreNum--;      
                printf("\n\t成功售出本书.");}
        }
        
    }
    else printf("\n\t这本书不存在!");
}

char Select_Menu()
{
    system("cls");
       printf("**************************************\n");
    printf("*   欢迎使用书店图书销售/管理系统    *\n");
    printf("*               主菜单               *\n");
    printf("*                                    *\n");
    printf("*            1、图书上架             *\n");
    printf("*            2、图书下架             *\n");
    printf("*            3、查找图书             *\n");
    printf("*            4、图书出售             *\n");
    printf("*            5、退出系统             *\n");
    printf("*                                    *\n");
    printf("*     请选择您要进行的操作(1~5)    *\n");
    printf("**************************************\n");
    return getch();
}


void main()
{
    char c,t;
    int flag,p=1;
    struct Info *bth=NULL;
    while(1)
    {
        c=Select_Menu();
        printf("您选择了:%c",c);
        getch();
        switch(c)  
        {
        case '1':
            bth=Insert_BookInfo(bth);/*图书上架*/
            break;
        case '2':
            bth=Delete_BookInfo(bth);/*图书下架*/
            break;
        case '3': Output_BookInfo(bth);/*查找图书*/
            break;
        case '4': Sell_TheBook(bth);/*图书出售*/
            break;
        case '5':                    /*退出系统*/
        case '0': system("cls");
            printf("\n\t你想退出系统 ?(y/n)");
            t=getch();
            if(t=='y'||t=='Y') exit(0);
            break;
        }
        printf("\n\t按任意键返回主菜单....");
        getch();
    }
}
搜索更多相关主题的帖子: include 书架 
2015-06-14 11:52
快速回复:求修改这段代码实现查找和架都能输入书名实现
数据加载中...
 
   



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

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