#include
using namespace std;
class People
{
public:
People(const char* name=“People”,int age=1)
{
m_name=name;
m_age=age;
}
virtual void info()const
{
cout<<“名字”<<m_name<<" “<<“年龄”<<m_age<<endl;
}
private:
string m_name;
int m_age;
};
class STU : public People
{
public:
STU(const char* name=“stu”,int age=0,float score=0)
:People(name,age),m_float(score)
{}
void info()const
{
People::info();
cout<<“成绩”<<m_float<<endl<<”**********\n\n";
}
private:
float m_float;
};
class TEC: public People
{
public:
TEC(const char name=“tec”,int age=0,const char coure="\0",float salary=0)
:People(name,age),m_strCourse(coure)
{
m_fsalary=salary;
}
void info()
{
People::info();
cout<<“门课”<<m_strCourse<<“薪资”<<m_fsalary<<endl;
}
private:
string m_strCourse;
float m_fsalary;
};
class List
{
public:
struct Node //类中结构体
{
Node(People* data=NULL)//构造函数
{
pData=data;
pNext=NULL;
}
void show()const //显示函数
{
pData->info();//调用people类型中的成员函数
}
People* pData; //指向People类型的指针
struct Node* pNext;//节点的next指针
};
List()
{
m_fristNode=NULL;
ilen=0;
}
void insert(People people)//需要一个people指针作为参数
{
Node node=new Node(people);//node需要people指针来构造函数
node->pNext=m_fristNode;
m_fristNode=node;
ilen++;
}
void display()const
{
Node* node=m_fristNode;
while(node)
{
node->show();//node 成员 People node*
node=node->pNext;
}
}
private:
Node* m_fristNode;
int ilen;
};
int main(void)
{
List l;
l.insert(new People(“jack”,19));
l.display();
return 0;
}