| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 569 人关注过本帖
标题:[求助]这程序的错出在那
只看楼主 加入收藏
monks1986
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-12-26
收藏
 问题点数:0 回复次数:2 
[求助]这程序的错出在那

程序是我同学写的,他运行有些问题,但不知道错在那,各位哥哥姐姐们帮着改一 下,小弟先在此谢谢了 哈希表及其应用

建立一个小型信息管理系统(可以是图书、人事、学生、物资、商品等任何信息管理系统)。
要求:
1 使用哈希查找表存储信息;
2 实现查找、插入、删除、统计、输出等功能;
3 尝试使用多种哈希函数和冲突解决方法,并通过实际运行测试给出自己的评价。
#i nclude<iostream.h>
#i nclude<stdlib.h>
struct student
{
int num;
char name[20];
int foxscore;
int cscore;
int englishscore;
struct student *next;
};

void menu()
{
cout<<" welecome to my student grade management system"<<endl;
cout<<" please follow everyone step in the menu"<<endl;
cout<<" 1.input information"<<endl;
cout<<" 2.total scores"<<endl;
cout<<" 3.sort"<<endl;
cout<<" 4.query"<<endl;
cout<<" ***************************************************"<<endl;
}
struct student *creat(struct student *head) // 函数返回的是与节点相同类型的指针
{
struct student *p1,*p2;
p1=p2=(struct student*) malloc(sizeof(struct student)); // 申请新节点
cin>>p1->num>>p1->name>>p1->foxscore>>p1->cscore>>p1->englishscore; // 输入节点的值
p1-> next = NULL; // 将新节点的指针置为空
for(int i=1;i<=4;i++)
{
if (head==NULL) head=p1; //空表,接入表头
else p2->next=p1; // 非空表,接到表尾
p2 = p1;
p1=(struct student *)malloc(sizeof(struct student)); //申请下一个新节点
if(i<=3)
{
cin>>p1->num>>p1->name>>p1->foxscore>>p1->cscore>>p1->englishscore;
}
//输入节点的值
}
return head; //返回链表的头指针
}

void count(struct student *head)
{
struct student *temp;
temp=head; //取得链表的头指针
for(int i=1;i<=4;i++)
{
int m;
m=temp->foxscore+temp->cscore+temp->englishscore;
cout<<m<<endl;//输出链表节点的值
temp=temp->next; //跟踪链表增长
}
}
void sort(struct student *head)
{
struct student *tp;
tp=head;
int a[4];//定义总分数组
int i,j,k;
a[1]=tp->foxscore+tp->cscore+tp->englishscore;
tp=tp->next;
a[2]=tp->foxscore+tp->cscore+tp->englishscore;
tp=tp->next;
a[3]=tp->foxscore+tp->cscore+tp->englishscore;
tp=tp->next;
a[4]=tp->foxscore+tp->cscore+tp->englishscore;
for(j=1;j<=3;j++)//冒泡法排序
for(k=1;k<=4-j;k++)
if(a[k]<a[k+1])
{
int t=a[k];a[k]=a[k+1];a[k+1]=t;
}
for(i=1;i<5;i++)
cout<<a[i]<<endl;
}
void query(struct student *head)
{
struct student *temper;
temper=head;
int number;
cin>>number;
for(int i=1;i<=4;i++)
{
if(number==temper->num)
{
cout<<" name is:"<<temper->name<<endl;
cout<<" fox score is:"<<temper->foxscore<<endl;
cout<<" c score is:"<<temper->cscore<<endl;
cout<<" English score is:"<<temper->englishscore<<endl;
cout<<" congratulation,syetem have found what you want to search"<<endl;
}
temper=temper->next;
}
}
void main()
{
menu();
cout<<" firstly,please input information:"<<endl;
struct student *head;
head=NULL; /* 建一个空表*/
head=creat(head); /* 创建单链表*/
cout<<" secondly,count the total score each student:"<<endl;
count(head);
cout<<" thirdly,sorting the total score:"<<endl;
sort(head);
cout<<" enter num that you can search each shtudent's information"<<endl;
query(head);
cout<<" thanks you for use my student grade management system"<<endl;
}


还有一 个

#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-12-28 21:24:11编辑过]

搜索更多相关主题的帖子: 管理系统 哥哥 统计 信息 
2006-12-27 16:18
monks1986
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-12-26
收藏
得分:0 
怎么没人回啊,
2006-12-28 21:26
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
LZ你自己不觉得看起来眼花吗
也不是我要偷懒,你总得说哪你觉得不好,或者是什么错.

倚天照海花无数,流水高山心自知。
2006-12-28 23:45
快速回复:[求助]这程序的错出在那
数据加载中...
 
   



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

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