Student.h文件 //应用层实现
#include "Person.h"
class CStudent :public CPerson
{
public:
int StudentNumber;
char *StudentName; //学号或者称呼/外号
public:
CStudent();
virtual ~CStudent();
CStudent(int StudentNumber,char *StudentName,int HumanAge); //有惨构造函数
void print_studentHuman(); //打印函数
};
源文件 Student.cpp
// Student.cpp: implementation of the CStudent class.
//
//////////////////////////////////////////////////////////////////////
#include "Student.h"
#include
#include
#include
#include "StudentList.h" using namespace std; #include "Person.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CStudent::CStudent() { } CStudent::~CStudent() { cout<<"在次调用Stduent析构函数."<
StudentNumber=StudentNumber; this->StudentName=new char[strlen(StudentName)+1]; strcpy(this->StudentName,StudentName); return ; } void CStudent::print_studentHuman() //打印 { cout<<"StudentNumber is "<
TeacherLink.h //以下与以上学生类、链表的建立同理
#include "Node.h"
class CTeacherLink
{
public:
CTeacherLink();
virtual ~CTeacherLink();
CNode *CreateLink();
void TeacherLinkAdd(CNode **head,void *data);
void PrintTeacherLink(CNode *head,pfun Print_teacher);
};
TeacherLink.cpp
// TeacherLink.cpp: implementation of the CTeacherLink class.
//
//////////////////////////////////////////////////////////////////////
#include "TeacherLink.h"
#include
#include
#include
#include "Node.h" using namespace std; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CTeacherLink::CTeacherLink() { } CTeacherLink::~CTeacherLink() { } CNode *CTeacherLink::CreateLink() { CNode *head=NULL; return head; } void CTeacherLink::TeacherLinkAdd(CNode **head,void *data) { CNode *node=new CNode; CNode *node2; if(node==NULL) { cout<<"节点为空."<
data=data; node->next=NULL; if(*head==NULL) { *head=node; } else { node2=*head; while(node2->next!=NULL) { node2=node2->next; } node2->next=node; } return ; } void CTeacherLink::PrintTeacherLink(CNode *head,pfun print_teacher) { CNode *node=head; if(head==NULL) { return ; } while(node!=NULL) { print_teacher(node->data); node=node->next; } return ; }
TeacherList.h
#include "Node.h"
#include "TeacherLink.h"
class CTeacherList :public CTeacherLink
{
public:
CNode *header;
CTeacherList();
virtual ~CTeacherList();
void TeacherListAdd(void *data);
void PrintList(pfun print_teacher);
//CNode *CreateLis