📄 peo.cpp
字号:
//peo.cpp
#include"peo.h"
#include<iostream.h>
#include<string.h>
peo::peo(const char *str)
{
strcpy(name,str);
cout<<"人员开始"<<endl;
}
peo::~peo()
{
if(strcmp(name,"empty")==0)
return;
else
{
cout<<"人员结束"<<endl;
strcpy(name,"empty");
}
}
stu::stu(const char *str,double a):peo(str)
{
score=a;
cout<<"学生开始"<<endl;
}
void stu::display(void)
{
cout<<"姓名:"<<name<<" "<<"成绩:"<<score<<endl;
}
stu::~stu()
{
if(score==-1)
return;
else
{
cout<<"学生 "<<name<<"结束"<<endl;
score=-1;
}
}
tec::tec(const char* str,int b):peo(str)
{
age=b;
cout<<"教师开始"<<endl;
}
tec::~tec()
{
if(age==1000)
return;
else
{
cout<<"教师 "<<name<<"结束"<<endl;
age=1000;
}
}
void tec::display()
{
cout<<"姓名:"<<name<<" "<<"年龄:"<<age<<endl;
}
list::list(void)
{
head=0;
cout<<"链表开始"<<endl;
}
list::~list()
{
cout<<"链表结束"<<endl;
}
void list::insert(peo *i)
{
peo* node;
if(head==0)
{
head=i;
head->next=0;
}
else
{
node=head;
while(node->next)
node=node->next;
node->next=i;
i->next=0;
}
}
void list::del(const char* s)
{
peo* node1,*node2;
int flag=0;
node1=head;
if(strcmp(head->name,s)==0)
{
head=head->next;
node1->~peo();
flag=1;
}
else
{
while(node1)
if(strcmp(node1->name,s)==0)
{
node2->next=node1->next;
node1->~peo();
flag=1;
break;
}
else
{
node2=node1;
node1=node1->next;
}
}
if(!flag)
cout<<"未找到要删除的结点!"<<endl;
else
cout<<"结点被删除,其姓名是:"<<s<<endl;
}
void list::ser(const char* s)
{
peo* node=head;
int flag=0;
while(node)
{
if(strcmp(node->name,s)==0)
{
flag=1;
break;
}
else
node=node->next;
}
if(flag)
cout<<"查找成功!"<<endl;
else
cout<<"未找到该结点!"<<endl;
}
void list::display(void)
{
peo* node;
if(head==0)
cout<<"空链表!"<<endl;
else
{
node=head;
while(node)
{
node->display();
node=node->next;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -