基本一样的给你,节点内容你自己改改就可以了:
所有的头文件:// TS.h: interface for the TS class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TS_H__8D3DB0C8_022B_40A7_B075_68C376AF8A2B__INCLUDED_)
#define AFX_TS_H__8D3DB0C8_022B_40A7_B075_68C376AF8A2B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class TS
{
public:
TS();
~TS();
virtual void Input();
virtual void Output();
TS *next;
int nMark;
char* GetID();
protected:
char ID[20];
char szName[20];
int nAge;
};
#endif // !defined(AFX_TS_H__8D3DB0C8_022B_40A7_B075_68C376AF8A2B__INCLUDED_)
// Teacher.h: interface for the Teacher class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TEACHER_H__8851AE9A_E10A_49E5_B141_CA9F9C2C274B__INCLUDED_)
#define AFX_TEACHER_H__8851AE9A_E10A_49E5_B141_CA9F9C2C274B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "TS.h"
class Teacher :public TS
{
public:
Teacher();
~Teacher();
void Input();
void Output();
private:
int Income;
};
#endif // !defined(AFX_TEACHER_H__8851AE9A_E10A_49E5_B141_CA9F9C2C274B__INCLUDED_)
// Student.h: interface for the Student class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_STUDENT_H__B93071C7_4EA0_4E9A_A802_D7BA0809EA6E__INCLUDED_)
#define AFX_STUDENT_H__B93071C7_4EA0_4E9A_A802_D7BA0809EA6E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "TS.h"
class Student : public TS
{
public:
Student();
~Student();
void Input();
void Output();
private:
int Grade;
};
#endif // !defined(AFX_STUDENT_H__B93071C7_4EA0_4E9A_A802_D7BA0809EA6E__INCLUDED_)
// ListProc.h: interface for the ListProc class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LISTPROC_H__391F09A8_67E1_4FC1_B51F_31C46AA9FE5B__INCLUDED_)
#define AFX_LISTPROC_H__391F09A8_67E1_4FC1_B51F_31C46AA9FE5B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "TS.h"
#include "Teacher.h"
#include "Student.h"
void CreateList();
void AddNode();
void DeleteNode();
void InsertNode();
void FindNode();
void ClearList();
void ShowList();
class ListProc
{
public:
ListProc();
~ListProc();
void Create();
void Add();
void Delete();
void Insert();
void Find();
void Clear();
void Show();
private:
TS *InType();
TS *Head;
TS *Rear;
};
#endif // !defined(AFX_LISTPROC_H__391F09A8_67E1_4FC1_B51F_31C46AA9FE5B__INCLUDED_)
。cpp文件
// TS.cpp: implementation of the TS class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TS.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TS::TS()
{
nMark = 0;
nAge = 0;
next = NULL;
}
TS::~TS()
{
}
void TS::Input()
{
cout<<"Name:";
cin>>szName;
cout<<"Age:";
cin>>nAge;
}
void TS::Output()
{
cout<<"Name:"<
char *TS::GetID()
{
return ID;
};
// Teacher.cpp: implementation of the Teacher class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Teacher.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Teacher::Teacher()
{
}
Teacher::~Teacher()
{
Income = 0;
}
void Teacher::Input()
{
cout<<"教职工工号:";
cin>>ID;
TS::Input();
cout<<"月工资:";
cin>>Income;
nMark = 1;
}
void Teacher::Output()
{
cout<<"***********************教师*****************************"<
cout<<"月工资:"<
// Student.cpp: implementation of the Student class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Student.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Student::Student()
{
}
Student::~Student()
{
Grade = 0;
}
void Student::Input()
{
cout<<"学号:";
cin>>ID;
TS::Input();
cout<<"总学分:";
cin>>Grade;
nMark = 0;
}
void Student::Output()
{
cout<<"***********************学生*****************************"<
cout<<"总学分:"<
// ListProc.cpp: implementation of the ListProc class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ListProc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ListProc::ListProc()
{
Head = NULL;
Rear = Head;
}
ListProc::~ListProc()
{
Clear();
Rear = Head;
}
void ListProc::Create()
{
if(Head == NULL)
{
Head = InType();
Head->next = NULL;
Rear = Head;
}
else
{
cout<<"链表已经存在,创建失败!!"<
}
void ListProc::Add()
{
if(Head != NULL)
{
Rear->next = InType();
Rear = Rear->next;
Rear->next = NULL;
}
else
{
cout<<"链表为空请创建!!"<
}
void ListProc::Delete()
{
char szBuf[20] = "";
cout<<"请输入你要删除的学号或工号:";
cin>>szBuf;
if (Head != NULL)
{
if (strcmp(Head->GetID(),szBuf) == 0)
{
Head = Head->next;
}
TS *pTemp = Head;
while (pTemp->next != NULL)//删除非头结点
{
if (strcmp(pTemp->next->GetID(),szBuf) == 0)
{
if(pTemp->next = Rear)//始终保持尾结点
{
Rear = pTemp;
}
pTemp->next = pTemp->next->next;
break;
}
pTemp = pTemp->next;
}
}
else
{
cout<<"LIST IS NULL !Please Create!!";
}
}
void ListProc::Insert()
{
char szBuf[20] = "";
cout<<"请输入你要插入ID的位置(位置左边):";
cin>>szBuf;
TS *pTemp = Head;
while (pTemp != NULL)
{
TS *InTemp = InType();
if (strcmp(Head->GetID(),szBuf) == 0)//保护头结点
{
InTemp->next = Head;
Head = InTemp;
break;
}
else if(strcmp(pTemp->next->GetID(),szBuf) == 0)
{
InTemp->next = pTemp->next;
pTemp->next = InTemp;
break;
}
pTemp = pTemp->next;
}
}
void ListProc::Find()
{
char szBuf[20] = "";
cout<<"请输入你要删除的学号或工号:";
cin>>szBuf;
TS *pTemp = Head;
while (pTemp != NULL)
{
if (strcmp(pTemp->GetID(),szBuf) == 0)
{
pTemp->Output();
break;
}
pTemp = pTemp->next;
}
}
void ListProc::Clear()
{
while (Head != NULL)
{
TS *pTemp = Head->next;
delete Head;
Head = pTemp;
}
}
void ListProc::Show()
{
TS *pTemp = Head;
while (pTemp != NULL)
{
pTemp->Output();
pTemp = pTemp->next;
}
}
TS* ListProc::InType()
{
TS *pTemp = NULL;
char szBuf[20] = "";
cout<<"学生0,教师为非0,请选择:";
cin>>szBuf;
if(strcmp(szBuf,"0") == 0)
{
pTemp = new Student;
pTemp->Input();
}
else
{
pTemp = new Teacher;
pTemp->Input();
}
return pTemp;
}
本视频主要从Java语言基础、JavaSE核心、WEB全栈及数据库、Servlet/Jsp核心、 Java框架五个阶段进行讲解。在本教程中,会让大家从零基础快速掌握Java知识。想要配套学习资料的小伙伴可以联系我哦!
这程序写起来不小....没那么快,分儿还少,