📄 teacher.cpp
字号:
//文件teacher.cpp
#include<iostream.h>
#include<string.h>
#include "teacher.h"
#include "fstream.h"
teacher::teacher()//无参构造函数
{ principalship=new char[11];
department=new char[21];
}
teacher::teacher(char*na,int num,char*pid,char s,int y,int m,int d,char*pri,char*dep):people(na,num,pid,s,y,m,d)//有参构造函数
{principalship=new char[strlen(pri)+1];
strcpy(principalship,pri);
department=new char[strlen(dep)+1];
strcpy(department,dep);
}
void teacher::print()//内联函数,输出信息
{people::print();
cout<<"职务:"<<principalship<<endl;
cout<<"部门:"<<department<<endl;
}
void searchtea(teacher p[],int num,int n)//友员查找函数
{ int i,z;
z=num;
for(i=0;i<n;i++)
if(z==p[i].getnum())
{cout<<"您要找的对象有如下信息:"<<endl;
p[i].print();
cout<<"查找完毕!请继续操作!"<<endl;
break;
}
if(i==n) cout<<"对不起,没有找到合适的对象。"<<endl;
}
void sorttea(teacher p[],int n)//友员排序函数
{ int i,j;
teacher temp;//定义临时对象
for(j=1;j<=n-1;j++) //起泡法排序
for(i=0;i<=n-1-j;i++)
if(p[i].getnum()>p[i+1].getnum())
{temp=p[i];p[i]=p[i+1];p[i+1]=temp;}
for(i=0;i<n;i++)
{p[i].print();}
cout<<"对teacher的排序完毕!!请继续操作"<<endl;
ofstream ostrm; //使用文件,把人员信息输出到文件上显示
ostrm.open("teacher.dat");
if(!ostrm)
{cout<<"teacher.dat can't open.\n";
}
for( i=0;i<n;i++)
{ostrm<<"老师人员信息有如下:"<<endl;
ostrm<<"\n";
ostrm<<"姓名:"<<p[i].getname()<<endl;
ostrm<<"编号:"<<p[i].getnum()<<endl;
ostrm<<"身份证号码:"<<p[i].getID()<<endl;
ostrm<<"职务:"<<p[i].getpri()<<endl;
ostrm<<"部门:"<<p[i].getdep()<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -