| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 904 人关注过本帖
标题:求助(数据结构课程设计--电视机仓库管理)...
只看楼主 加入收藏
lenovo913
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-12-30
收藏
 问题点数:0 回复次数:0 
求助(数据结构课程设计--电视机仓库管理)...

大家帮忙看看这段程序哪里有错,是C语言编的数据结构课程设计--电视机仓库管理

#include "stdio.h"
#define NULL 0

typedef struct node{
int price;
int num;
struct node *next;
}TVStorage;

void CreateList(TVStorage *h)/*初始化链表(输入电视机价格、台数),以0为结束符,并以升序打印*/
{TVStorage *q,*r,*p;
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nCreate List as follows:");
printf("\nInput price,num:");
scanf("%d,%d",&r->price,&r->num);
r->next=NULL;
while(r->price!=0)
{q=h;p=h->next;
if(p==NULL) h->next=r;
else {while ((r->price>p->price)&&(p->next!=NULL))
{q=p;p=p->next;}
if (r->price<p->price)
{r->next=p;q->next=r;}
else if(r->price==p->price)(p->num)=(p->num)+(r->num);
else {p->next=r;r->next=NULL;}
}
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput price,num:");
scanf("%d,%d",&r->price,&r->num);
}
}

void Intostore(TVStorage *h)/*电视机入库(输入电视机价格、台数),以0为结束符,并以升序打印*/
{TVStorage *q,*r,*p;
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput intostore's price,num:");
scanf("%d,%d",&r->price,&r->num);
r->next=NULL;
while(r->price!=0)
{q=h;p=h->next;
if(p==NULL) h->next=r;
else {while ((r->price>p->price)&&(p->next!=NULL))
{q=p;p=p->next;}
if (r->price<p->price)
{r->next=p;q->next=r;}
else if(r->price==p->price) (p->num)=(p->num)+(r->num);
else {p->next=r;r->next=NULL;}
}
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput intostore's price,num:");
scanf("%d,%d",&r->price,&r->num);
}
}


Outstore(TVStorage *h)/* 电视机出库(输入电视机价格、台数),以0为结束符,并以升序打印*/
{ TVStorage *q,*r,*p;
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput outstore's price,num:");
scanf("%d,%d",&r->price,&r->num);
while(r->price!=0)
{q=h;p=h->next;
while ((r->price!=p->price)&&(p->next!=NULL))
{q=p;p=p->next;}
if (r->price==p->price)
{while (r->num>p->num)
{printf("\n Outstore's num is more,please choose:\n");
printf(" A.Input again----choose 'A'or'a'\n");
printf(" B.Outstore as the-most-storage %dsets---choose any key\n",p->num);
printf(" please choose:");
if(getchar()=='A'||getchar()=='a')
{printf("\nInput num again:");
scanf("%d",&r->num);}
else {printf("Outstore as the most storage %d\n",p->num);
r->num=p->num;}
}
p->num=p->num-r->num;
if(p->num==0) {q->next=p->next;free(p);}
}
else printf("Outstore's price isn't exists,please input again.\n");
r=(TVStorage*)malloc(sizeof(TVStorage));
printf("\nInput outstore's price,num:");
scanf("%d,%d",&r->price,&r->num);
}
}


void Search(TVStorage *h)/*根据价格查询库存台数,以0为结束符,并输出相应台数*/
{ TVStorage *p,*q;
int Schprice;
printf("\nplease input search's price:");
scanf("%d",&Schprice);
while(Schprice!=0)
{ q=h;p=q->next;
while(p->price!=Schprice&&p->next!=NULL)
{q=p;p=p->next;}
if(p->price==Schprice)
printf("\nthe price %d is %d sets.\n",Schprice,p->num);
else printf("\nsearch's price isn't exist,please input again.\n");
printf("\nplease input search's price:");
scanf("%d",&Schprice);}
}

void PrintList(TVStorage *h) /*打印电视机的价格和台数*/
{TVStorage *p;
p=h->next;
printf("TVStorage as follow:(Sort Ascending of price)\n\n");
printf(" TV price Storage\n\n");
while(p!=NULL)
{printf("%10dyuan%10dsets\n",p->price,p->num);
p=p->next;}
}

main() /*主函数体部分*/
{TVStorage *head,*p;
int c;
head=(TVStorage*)malloc(sizeof(TVStorage));
head->next=NULL;
CreateList(head);
PrintList(head);
do{
printf("\nThe system provides as follow's function:\n");
printf(" 1.Tv Intostore\n");
printf(" 2.Tv Outstore\n");
printf(" 3.Storage Search\n");
printf(" 4.Exit\n");
printf("Please choose 1,2,3,4:");
scanf("%d",&c);
switch(c)
{ case 1:Intostore(head);printf("\nAfter intostore,");PrintList(head);break;
case 2:Outstore(head);printf("\nAfter outstore,");PrintList(head);break;
case 3:Search(head);break;
case 4:printf("See you later !\n");break;
default:printf("error,please choose again\n");
}

}

while(c!=4);

}



哪位大侠帮帮忙,小弟感激不尽!!

在线等........

搜索更多相关主题的帖子: 仓库管理 数据结构 电视机 课程 
2006-01-01 16:37
快速回复:求助(数据结构课程设计--电视机仓库管理)...
数据加载中...
 
   



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

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