标题:[求助]我有三个程序怎么都搞不了,请高手们指点指点
只看楼主
lichee8611
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-4-3
 问题点数:0 回复次数:3 
[求助]我有三个程序怎么都搞不了,请高手们指点指点

这是第一个
#include<iostream.h>
struct worker
{
int num;
int year;
char sex;
worker *next;
}*l;
void creat(worker*&head)
{
worker *s,*p;
s=new worker;
cout<<"Please input number,year,sex of worker:\n";
cin>>s->num>>s->year>>s->sex;
while(s->num!=0)
{
if(head==NULL)head=s;
else p->next=s;
p=s;
s=new worker;
cin>>s->num>>s->year>>s->sex;
}
p->next=NULL;
delete s;
cout<<"Have built"<<endl;
}
void read(worker*head)
{
cout<<"The information of the worker:\n";
while(head)
{
cout<<head->num<<'\t'<<head->year<<'\t'<<head->sex<<endl;
head=head->next;
}
cout<<"Have read"<<endl;
}
void count(worker*&head)
{
int i=0,j=0;
while(head)
{
if(head->sex=='f')i++;
if(head->sex=='m')j++;
head=head->next;
}
cout<<"Have count"<<endl;
}
void insert(worker*&head)
{
worker*s;
while(!head->next)
{
s=new worker;
cin>>s->num>>s->year>>s->sex;
head->next=s;
delete s;
s=NULL;
}
cout<<"Have inserted"<<endl;
}
void del(worker*&head)
{
int a;
worker *k;
cout<<"Please input the number of worker you want to delete:\n";
cin>>a;
if(head->num==a)
{
k=head;
head=head->next;
delete k;
k=NULL;
cout<<"Have deleted\n";
}
for(worker*&pg=head;pg->next;pg=pg->next)
if(pg->next->num==a)
{
k=pg->next;
pg->next=k->next;
delete pg;
pg=NULL;
cout<<"Have deleted\n";
}
}
void delover(worker*&head)
{
worker *s,*x;
while(head)
{
x=head;
if((x->sex=='f'&&x->year==60)||(x->sex=='m'&&x->year==55))
{
s=new worker;
s=x;
x=x->next;
delete x;
x=NULL;
}
head=head->next;
}
cout<<"Have delete\n";
}
void main()
{
worker*haed=NULL;
creat(&head);
count(&head);
insert(&head);
del(&head);
delover(&head);
cout<<"Over"<<endl;
}


这是第二个
#include<iostream.h>
struct worker
{
int num;
int year;
char sex;
worker *next;
}*l;
void creat(worker*&head)
{
worker *s,*p;
s=new worker;
cout<<"Please input number,year,sex of worker:\n";
cin>>s->num>>s->year>>s->sex;
while(s->num!=0)
{
if(head==NULL)head=s;
else p->next=s;
p=s;
s=new worker;
cin>>s->num>>s->year>>s->sex;
}
p->next=NULL;
delete s;
cout<<"Have built"<<endl;
}
void read(worker*head)
{
cout<<"The information of the worker:\n";
while(head)
{
cout<<head->num<<'\t'<<head->year<<'\t'<<head->sex<<endl;
head=head->next;
}
cout<<"Have read"<<endl;
}
void count(worker*&head)
{
int i=0,j=0;
while(head)
{
if(head->sex=='f')i++;
if(head->sex=='m')j++;
head=head->next;
}
cout<<"Have count"<<endl;
}
void insert(worker*&head)
{
worker*s;
while(!head->next)
{
s=new worker;
cin>>s->num>>s->year>>s->sex;
head->next=s;
delete s;
s=NULL;
}
cout<<"Have inserted"<<endl;
}
void del(worker*&head)
{
int a;
worker *k;
cout<<"Please input the number of worker you want to delete:\n";
cin>>a;
if(head->num==a)
{
k=head;
head=head->next;
delete k;
k=NULL;
cout<<"Have deleted\n";
}
for(worker*&pg=head;pg->next;pg=pg->next)
if(pg->next->num==a)
{
k=pg->next;
pg->next=k->next;
delete pg;
pg=NULL;
cout<<"Have deleted\n";
}
}
void delover(worker*&head)
{
worker *s,*x;
while(head)
{
x=head;
if((x->sex=='f'&&x->year==60)||(x->sex=='m'&&x->year==55))
{
s=new worker;
s=x;
x=x->next;
delete x;
x=NULL;
}
head=head->next;
}
cout<<"Have delete\n";
}
void main()
{
worker*haed=NULL;
creat(&head);
count(&head);
insert(&head);
del(&head);
delover(&head);
cout<<"Over"<<endl;
}


这是第三个

#include<iostream.h>
struct worker
{
int num;
int year;
char sex;
worker *next;
}*l;
void creat(worker*&head)
{
worker *s,*p;
s=new worker;
cout<<"Please input number,year,sex of worker:\n";
cin>>s->num>>s->year>>s->sex;
while(s->num!=0)
{
if(head==NULL)head=s;
else p->next=s;
p=s;
s=new worker;
cin>>s->num>>s->year>>s->sex;
}
p->next=NULL;
delete s;
cout<<"Have built"<<endl;
}
void read(worker*head)
{
cout<<"The information of the worker:\n";
while(head)
{
cout<<head->num<<'\t'<<head->year<<'\t'<<head->sex<<endl;
head=head->next;
}
cout<<"Have read"<<endl;
}
void count(worker*&head)
{
int i=0,j=0;
while(head)
{
if(head->sex=='f')i++;
if(head->sex=='m')j++;
head=head->next;
}
cout<<"Have count"<<endl;
}
void insert(worker*&head)
{
worker*s;
while(!head->next)
{
s=new worker;
cin>>s->num>>s->year>>s->sex;
head->next=s;
delete s;
s=NULL;
}
cout<<"Have inserted"<<endl;
}
void del(worker*&head)
{
int a;
worker *k;
cout<<"Please input the number of worker you want to delete:\n";
cin>>a;
if(head->num==a)
{
k=head;
head=head->next;
delete k;
k=NULL;
cout<<"Have deleted\n";
}
for(worker*&pg=head;pg->next;pg=pg->next)
if(pg->next->num==a)
{
k=pg->next;
pg->next=k->next;
delete pg;
pg=NULL;
cout<<"Have deleted\n";
}
}
void delover(worker*&head)
{
worker *s,*x;
while(head)
{
x=head;
if((x->sex=='f'&&x->year==60)||(x->sex=='m'&&x->year==55))
{
s=new worker;
s=x;
x=x->next;
delete x;
x=NULL;
}
head=head->next;
}
cout<<"Have delete\n";
}
void main()
{
worker*haed=NULL;
creat(&head);
count(&head);
insert(&head);
del(&head);
delover(&head);
cout<<"Over"<<endl;
}

有劳各位好汉,小弟先拜谢了!

搜索更多相关主题的帖子: include number color 
2007-04-03 15:14
cz522321
Rank: 1
等 级:禁止访问
威 望:2
帖 子:569
专家分:5
注 册:2006-3-13
得分:0 

#include<iostream.h>
struct worker
{
int num;
int year;
char sex;
worker *next;
}*l;
void creat(worker*&head)
{
worker *s,*p;
s=new worker;
cout<<"Please input number,year,sex of worker:\n";
cin>>s->num>>s->year>>s->sex;
while(s->num!=0)
{
if(head==NULL)head=s;
else p->next=s;
p=s;
s=new worker;
cin>>s->num>>s->year>>s->sex;
}
p->next=NULL;
delete s;
cout<<"Have built"<<endl;
}
void read(worker*head)
{
cout<<"The information of the worker:\n";
while(head)
{
cout<<head->num<<'\t'<<head->year<<'\t'<<head->sex<<endl;
head=head->next;
}
cout<<"Have read"<<endl;
}
void count(worker*&head)
{
int i=0,j=0;
while(head)
{
if(head->sex=='f')i++;
if(head->sex=='m')j++;
head=head->next;
}
cout<<"Have count"<<endl;
}
void insert(worker*&head)
{
worker*s;
while(!head->next)
{
s=new worker;
cin>>s->num>>s->year>>s->sex;
head->next=s;
delete s;
s=NULL;
}
cout<<"Have inserted"<<endl;
}
void del(worker*&head)
{
int a;
worker *k;
cout<<"Please input the number of worker you want to delete:\n";
cin>>a;
if(head->num==a)
{
k=head;
head=head->next;
delete k;
k=NULL;
cout<<"Have deleted\n";
}
for(worker*&pg=head;pg->next;pg=pg->next)
if(pg->next->num==a)
{
k=pg->next;
pg->next=k->next;
delete pg;
pg=NULL;
cout<<"Have deleted\n";
}
}
void delover(worker*&head)
{
worker *s,*x;
while(head)
{
x=head;
if((x->sex=='f'&&x->year==60)||(x->sex=='m'&&x->year==55))
{
s=new worker;
s=x;
x=x->next;
delete x;
x=NULL;
}
head=head->next;
}
cout<<"Have delete\n";
}
void main()
{
worker*haed=NULL;  改为worker *head=NULL;
count(&head); count(head);
insert(&head); insert(head);
del(&head); del(head);
delover(&head); delover(head);
cout<<"Over"<<endl;
}
这样就OK了!


2007-04-03 15:23
cz522321
Rank: 1
等 级:禁止访问
威 望:2
帖 子:569
专家分:5
注 册:2006-3-13
得分:0 
第二第三个没有问题呀!只是haed要改为head,在主函数里面.

2007-04-03 15:26
lichee8611
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-4-3
得分:0 
非常感谢阁下花时间为我解答,无尽感激

我是个有点自负的人,虽然水平还很低,不到迫不得已不会轻易求助.
2007-04-03 23:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-128913-1-1.html




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

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