怎么改用对象指针实现(即链表)?
#include<iostream>#include<string>
using namespace std;
class Date{
public:
Date();
Date(const string &name, int x,char y,int m,int e, int c,int co);
void setdate(const string &name, int x,char y,int m,int e, int c,int co);
void showstudent();
double aver();
private:
string Name;
int ID;
char Sex;
int Math;
int English;
int C;
int Computer;
int Average;
};
Date::Date()
{
}
Date::Date(const string &name, int x,char y,int m,int e, int c, int co)
{
Name=name;
ID=x;
Sex= y;
Math=m;
English=e;
C=c;
Computer=co;
}
void Date::setdate(const string &name, int x,char y,int m,int e, int c, int co)
{
Name=name;
ID=x;
Sex= y;
Math=m;
English=e;
C=c;
Computer=co;
}
void Date::showstudent()
{
cout <<Name<<" "<<ID<<" "<<Sex<<" "<<Math<<" "<<English<<" "<<C
<<" "<<Computer<<" "<<aver()<<endl;
}
double Date::aver()
{
return (Math + English + C + Computer) / 4.0;
}
int main()
{ int q;
cout<<"Please Input the Number of Students:"<< endl;
cin>>q;
Date *stu = new Date[q];
string name;
int x;
char y;
int m;
int e;
int c;
int co;
cout <<"Please input"<<" "<<q<<" "<<"student info: Name ID Sex Math English C Computer"<< endl;
for(int j = 0; j < q; j++)
{
cin >> name >> x >> y >> m >> e >> c >> co;
stu[j].setdate(name, x, y, m, e, c, co);
}
cout<< "Student Information you input:"<<endl;
cout<<"Name ID Sex Math English C Computer Average" << endl;
for(int i = 0; i < q; i++)
{
stu[i].showstudent();
}
delete[] stu;
return 0;
}