#include<iostream>
#include"people.h"
#include<string.h>
using namespace std;
//people.cpp
day::day(int y,int m,int d)//day类的实现
{
year=y;month=m;date=d;
}
day::~day() {}
day::day(day&one)
{ date=one.date;
month=one.month;
year=one.year;
}
void day::Setday()
{
cout<<"请输入出生日期(年月日之间以空格键或回车键分开):";
cin>>year>>month>>date;
}
void day::Getday()
{
cout<<"出生日期为:"<<year<<"年"<<month<<"月"<<date<<"日"<<endl;
}
//people类的实现
people::people(){}
people:: people(char*name,int number,char*sex,char*id,day bir)
{
birthday=bir;
}
people::~people(){}
void people::Setpeople()
{
cout<<"请输入姓名:";cin>>name;cout<<"请输入编号:";cin>>number;
cout<<"请输入该人的性别(x代表女,y代表男):";
cin>>sex;cout<<"请输入身份证号码:";cin>>id;
birthday.Setday();
}
void people::Getpeople()
{
cout<<"该人的姓名为:"<<name<<endl<<"该人的编号为:"<<number<<endl;
cout<<"该人的性别为:";if(sex=='x')cout<<"女"<<endl; else cout<<"男"<<endl;
cout<<"该人的身份证号码为:"<<id<<endl;birthday.Getday();
}
void people::operator==(people p1)
{
if(id==p1.id)cout<<"这两个people类对象的id相同"<<endl;
else cout<<"这两个people类的对象的id不相同"<<endl;
}
void people::operator=(people p2)
{
people p;
strcpy(name,p2.name);number=p2.number;sex=p2.sex;strcpy(id,p2.id);
birthday=p2.birthday;
}
//student类的实现
student::student(){}
student::~student(){}
void student::Setstudent()
{
people::Setpeople();
cout<<"请输入班号:";cin>>classNO;
}
void student::Getstudent()
{
people::Getpeople();
cout<<"该学生的班号为:"<<classNO<<endl;
}
//teacher类的实现
teacher::teacher(){}
teacher::~teacher(){}
teacher::teacher(teacher&a){cout<<"拷贝构造函数被调用";}
void teacher::Setteacher1(){people::Setpeople();}
void teacher::Setteacher2(){cout<<"请输入老师的职务:";cin>>principalship;
cout<<"请输入老师的部门:";cin>>department;}
void teacher::Getteacher1(){people::Getpeople();}
void teacher::Getteacher2(){cout<<"该老师的职务是:" <<principalship<<endl<<"该老师的部门是:"<<department<<endl;}
//graduate类的实现
graduate::graduate(){}
graduate::~graduate(){};
void graduate::Setgraduate1(){student::Setstudent();}
void graduate::Setgraduate2(){ cout<<"请输入专业:";cin>>subject;cout<<"请输入导师的信息为:"<<endl;
teacheradviser.Setteacher1();teacheradviser.Setteacher2();}
void graduate::Getgraduate1(){student::Getstudent();}
void graduate::Getgraduate2(){cout<<"该研究生的专业为:"<<subject<<endl;cout<<"导师的信息为:"<<endl;
teacheradviser.Getteacher1();teacheradviser.Getteacher2();}
//TA类的实现
TA::TA(){}
TA::~TA(){}
void TA::SetTA()
{
student::Setstudent();graduate::Setgraduate2();
cout<<"请输入该助教生的助教信息:"<<endl;
teacher::Setteacher2();
cout<<"请输入助教生的工作时间:";cin>>time;
cout<<"请输入助教生的工资:";cin>>pay;
}
void TA::GetTA()
{
student::Getstudent();graduate::Getgraduate2();
cout<<"该助教生的助教信息为:"<<endl;
teacher::Getteacher2();
cout<<"该助教生的工作时间为:"<<time<<endl<<"该助教生的工资为:"<<pay<<endl;
}
people p[50];student s[50];teacher t[50];graduate g[50];TA T[50];
int peopleNO=0,studentNO=0,teacherNO=0,graduateNO=0,TANO=0;int number;
void Set(int i)
{
char ch;
switch(i)
{
case 0:
{
do
{
cout<<"请输入people的信息:"<<endl;p[peopleNO].Setpeople();peopleNO++;
cout<<"信息输入成功"<<endl;
cout<<endl<<"继续输入吗?是'y',否'n':";
cin>>ch;
}while(ch=='y');
}break;
case 1:
{
do
{
cout<<"请输入student的信息:"<<endl;
s[studentNO].Setstudent();
studentNO++;
cout<<"信息输入成功"<<endl;
cout<<endl<<"继续输入吗?是'y',否'n':";
cin>>ch;
}while(ch=='y');
}break;
case 2:
{
do
{
cout<<"请输入teacher的信息:"<<endl;
t[teacherNO].Setteacher1();
t[teacherNO].Setteacher2();
teacherNO++;
cout<<"信息输入成功"<<endl;
cout<<"继续输入吗?是'y',否'n':"<<endl;
cin>>ch;
}while(ch=='y');
}break;
case 3:
{
do
{
cout<<"请输入graduate的信息:"<<endl;
g[graduateNO].Setgraduate1();g[graduateNO].Setgraduate2();
graduateNO++;
cout<<"信息输入成功"<<endl;
cout<<"继续输入吗?是'y',否'n':"<<endl;
cin>>ch;
}while(ch=='y');
}break;
case 4:
{
do
{
cout<<"请输入TA的信息:"<<endl;
T[TANO].SetTA();
TANO++;
cout<<"信息输入成功"<<endl;
cout<<endl<<"继续输入吗?是'y',否'n':"<<endl;
cin>>ch;
}while(ch=='y');
}break;
default:cout<<"Error!you must enter 0,1,2,3or4"<<endl;
}
}
void Swap(people&p1,people&p2)//辅助函数交换people类的对象
{
people t;
t=p1;
p1=p2;
p2=t;
}
void SelectionSort(people p[] ,int n)//对people类的对象进行排序
{
int smallIndex;
int i,j;
for(i=0;i<n-1;i++)
{
smallIndex=i;
for(j=i+1;j<n;j++)
if(p[j].number<p[smallIndex].number)
smallIndex=j;
Swap(p[i],p[smallIndex]);
}
cout<<"按编号由小到大排列为:"<<endl;
for(i=0;i<n;i++)
{
p[i].Getpeople();
}
}
void SeqSeach(people p[],int n)
{
int number;char ch;
cout<<"请输入你要查找对象的编号:"<<endl;
cin>>number;
for(int i=0;i<n;i++)
{
if(number==p[i].number)p[i].Getpeople();
}
if((number!=p[0].number)&&(number!=p[1].number)&&(number!=p[2].number))
cout<<"there is not the people"<<endl;
cout<<"继续输入吗?是'y'否'n':"<<endl;
cin>>ch;
if(ch=='y')
SeqSeach( p, n);
}
//mian.cpp
int main() //主函数的实现
{
cout<<"*********Welcome to you!***********"<<endl;
char ch;int k;int j,i,a,b;
line:do
{
cout<<"请选择你要输入的人员信息"<<endl;
cout<<"0-people 1-student 2-teacher 3-graduate 4-TA:";
cin>>i;Set(i);cout<<"你还要输入其他人得信息吗?是“y”,否“n”:";cin>>ch;
}
while(ch=='y');
if(ch=='n'){cout<<"输入任务结束,请执行其他任务"<<endl;}
else
{cout<<"Error!you must enter 'y'or'n'"<<endl<<"请重新输入"<<endl;goto line ;}
cout<<endl<<"你要对people类执行操作吗?是'y',否'n':";//处理people类的对象
cin>>ch;
if(ch=='y')
{
cout<<"请先输入people类的对象:"<<endl;
cout<<"你能够输入三个people类的对象"<<endl;
people p[3];
for(j=0;j<3;j++)
{
cout<<"请输入people类对象的信息:"<<endl;p[j].Setpeople();
}
do
{
cout<<"请选择你要执行的操作:"<<endl;
cout<<" 1-比较对象的id 2-按编号排序 3-按编号查找 :";
cin>>i;
switch(i)
{
case 1:{cout<<"请输入你要比较的对象(必须是p[0],p[1],p[2]中任一个):"<<endl;
cin>>a>>b;p[a]==p[b];}break;
case 2: SelectionSort( p,3);break;
case 3: SeqSeach(p,3); break;
}
cout<<"你还要执行其它操作吗?是'y', 否'n':";cin>>ch;
}while(ch=='y');
if(ch=='n')cout<<"请执行其它操作"<<endl;
}
else cout<<"请执行其他任务"<<endl;
cout<<"你要显示你输入的人员信息吗?是'y',否'n':";
cin>>ch;
if(ch=='y')
{
if(peopleNO!=0)
{
for(k=0;k<peopleNO;k++)
{cout<<"people的信息为:"<<endl;p[k].Getpeople();}
}
else{cout<<"there is no people's message"<<endl;}
if(studentNO!=0)
{
for(k=0;k<studentNO;k++)
{cout<<"student的信息为:"<<endl; s[k].Getstudent();}
}
else{cout<<"there is no student's message"<<endl;}
if(teacherNO!=0)
{
for(k=0;k<teacherNO;k++)
{cout<<"teacher的信息为:"<<endl;t[k].Getteacher1();t[k]