请大家指点一下链表这个问题
定义一个学生类,有姓名、学号、性别、四门功课(Math English C Computer)和平均分等私有数据成员;学生人数及学生信息由键盘输入,求出每个学生的平均分;打印每个学生的姓名、学号、四门课成绩和平均分。要求:
1.用对象指针实现(即链表);
2.用构造函数实现学生信息的输入;
3.平均分的计算要用一个单独的函数实现;
4.请严格按照下面的格式进行输入输出。
输入/输出样式:
Please Input the Number of Students:
3
Please input 3 student info: Name ID Sex Math English C Computer
wang 1 f 80 80 80 80
zhang 2 m 85 85 85 85
liang 3 m 75 75 75 75
Student Information:
Name ID Sex Math English C Computer Average
wang 1 f 80 80 80 80 80
zhang 2 m 85 85 85 85 85
liang 3 m 75 75 75 75 75
我的代码如下,系统说我还有特殊情况没考虑到,请大家帮帮我。。。
#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;
int ID;
string sex;
int math;
int english;
int c;
int computer;
int average;
};
student::student()
{
cin>>name>>ID>>sex>>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<<" "<<ID<<" "<<sex<<" "<<math<<" "<<english<<" "<<c<<" "<<computer<<" "<<average<<endl;
}
int main()
{
student *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;
if(n!=0)
{
p1=new student;
p1->next=NULL;
}
for(int i=1;i<n;i++)
{
p2=new student;
p2->next=p1->next;
p1->next=p2;
}
cout<<endl<<"Student Information:"<<endl;
cout<<"Name ID Sex Math English C Computer Average"<<endl;
for(int i=1;i<=n;i++)
{
p1->showdate();
p1=p1->next;
}
}