?? 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<<"人員結(jié)束"<<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<<"結(jié)束"<<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<<"結(jié)束"<<endl;
age=1000;
}
}
void tec::display()
{
cout<<"姓名:"<<name<<" "<<"年齡:"<<age<<endl;
}
list::list(void)
{
head=0;
cout<<"鏈表開始"<<endl;
}
list::~list()
{
cout<<"鏈表結(jié)束"<<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<<"未找到要刪除的結(jié)點!"<<endl;
else
cout<<"結(jié)點被刪除,其姓名是:"<<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<<"未找到該結(jié)點!"<<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 + -