异质链表

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值