一个链表问题求高手找错
#include <iostream>#include <string>
using namespace std;
class student
{
public:
student();
void aver(int math,int english,int c,int computer);
void showdate();
student *next;
private:
string name;
string sex;
int ID;
int math;
int english;
int c;
int computer;
int average;
};
student::student()
{
cin>>name>>sex>>ID>>math>>english>>c>>computer;
aver(math,english,c,computer);
}
void student::aver(int math,int english,int c,int computer)
{
average=(math+english+c+computer)/4;
}
void student::showdate()
{
cout<<name<<sex<<ID<<math<<english<<c<<computer<<average;
}
int main()
{
student *head,*p1,*p2;
int n;
cout<<"Please Input the Number of Students:\n";
cin>>n;
cout<<"Please input"<< n <<"student info: Name ID Sex Math English C Computer"<<endl;
p1=new student;
head=NULL;
p2=p1;
for(int i=1;i<=n;i++)
{
if(head==NULL)
head=p1;
else
p2->next=p1;
p2=p1;
p1=new student;
}
p2->next=NULL;
for(int i=1;i<=n;i++)
{
head->showdate();
head=head->next;
}
delete []p1;
}