主题:求助高手,链表输入输出问题。。
求助大虾,下面代码的name有问题,还有showstudent也有问题,但本菜鸟不知道出什么问题,请教各位大虾下面的程序哪里出错,要怎么改?在此先谢谢了
#include <iostream.h>
class student
{
public:
int num;
char name[10];
double china;
double eng;
double math;
student *next;
student *head;
};
student *create()
{
int n;
student *p,*s;
p=new student;
p->next=NULL;
cout<<"输入学生的人数:";
cin>>n;
for(int i=0;i<n;i++)
{
s=new student;
cout<<"输入第"<<i+1<<"学生的学号和姓名:";
cin>>s->num;
cin>>s->name[10];
cout<<"输入第"<<i+1<<"学生的中英数成绩:";
cin>>s->china;
cin>>s->eng;
cin>>s->math;
s->next=p;
p=s;
}
return p;
}
void showstudent(student *head)
{
student *p;
p=head->next;
while(p!=NULL)
{
cout<<p->num;
cout<<p->name[10];
cout<<p->china;
cout<<p->eng;
cout<<p->math;
p=p->next;
}
cout<<endl;
}
void main()
{
student *head=NULL;
head=create();
showstudent(head);
}
#include <iostream.h>
class student
{
public:
int num;
char name[10];
double china;
double eng;
double math;
student *next;
student *head;
};
student *create()
{
int n;
student *p,*s;
p=new student;
p->next=NULL;
cout<<"输入学生的人数:";
cin>>n;
for(int i=0;i<n;i++)
{
s=new student;
cout<<"输入第"<<i+1<<"学生的学号和姓名:";
cin>>s->num;
cin>>s->name[10];
cout<<"输入第"<<i+1<<"学生的中英数成绩:";
cin>>s->china;
cin>>s->eng;
cin>>s->math;
s->next=p;
p=s;
}
return p;
}
void showstudent(student *head)
{
student *p;
p=head->next;
while(p!=NULL)
{
cout<<p->num;
cout<<p->name[10];
cout<<p->china;
cout<<p->eng;
cout<<p->math;
p=p->next;
}
cout<<endl;
}
void main()
{
student *head=NULL;
head=create();
showstudent(head);
}