#ifndef _PERSON
#define _PERSON
#include <iostream>
#include <string>
using namespace std;
class Date
{
protected :
int year;
int month;
int day;
public :
void Set ( int y, int m, int d ) ;
int GetYear ( ) ;
int GetMonth ( ) ;
int GetDay ( ) ;
} ;
class Person
{
protected :
char name[ 20 ] ;
char number[ 10 ] ;
char sex;
Date birthday;
public :
Person ( ) ;
void Input ( ) ;
void Output ( ) ;
char * GetName ( ) ;
} ;
class Student : virtual public Person
{
protected :
char speciality[ 20 ] ;
public :
void Input ( ) ;
void Output ( ) ;
} ;
class Graduate : virtual public Student
{
protected :
char researchTopic[ 50 ] ;
public :
void Input ( ) ;
void Output ( ) ;
} ;
class Teacher : virtual public Person
{
protected :
char academicTitle [ 20 ] ;
public :
void Input ( ) ;
void Output ( ) ;
} ;
class PostgraduateOnJob : public Graduate, public Teacher
{
public :
void Input ( ) ;
void Output ( ) ;
} ;
#endif
#include "example5_14_people.h"
void Date:: Set ( int y, int m, int d )
{
year = y;
month = m;
day = d;
}
int Date:: GetYear ( )
{
return year;
}
int Date:: GetMonth ( )
{
return month;
}
int Date:: GetDay ( )
{
return day;
}
Person:: Person ( )
{
strcpy ( name, "00" ) ;
}
char * Person:: GetName ( )
{
return name;
}
void Person:: Input ( )
{
cout << "请输入信息\n" ;
cout << "姓 名:" ;
cin >> name ;
cout << "编 号:" ;
cin >> number;
int y, m , d;
cout << "出生日期(年份 月份 日期):" ;
cin >> y >> m >> d;
birthday. Set ( y, m, d) ;
cout << "性别(m/f):" ;
cin >> sex;
}
void Person:: Output ( )
{
cout << "姓 名:" << name << endl;
cout << "编 号:" << number << endl;
cout << "性 别:" ;
if ( sex == 'm' )
cout << "女" << endl;
else
cout << "男" << endl;
cout << "出生日期:" << birthday. GetYear ( ) << '-' << birthday. GetMonth ( ) << '-' << birthday. GetDay ( ) << endl;
}
void Student:: Input ( )
{
Person:: Input ( ) ;
cout << "专 业:" ;
cin >> speciality;
}
void Student:: Output ( )
{
Person:: Output ( ) ;
cout << "专 业:" << speciality << endl;
}
void Graduate:: Input ( )
{
Student:: Input ( ) ;
cout << "研究课题:" ;
cin >> researchTopic;
}
void Graduate:: Output ( )
{
Student:: Output ( ) ;
cout << "研究课题:" << researchTopic << endl;
}
void Teacher:: Input ( )
{
Person:: Input ( ) ;
cout << "职 称:" ;
cin >> academicTitle;
}
void Teacher:: Output ( )
{
Person:: Output ( ) ;
cout << "职 称:" << academicTitle << endl;
}
void PostgraduateOnJob:: Input ( )
{
Graduate:: Input ( ) ;
cout << "职 称:" ;
cin >> academicTitle;
}
void PostgraduateOnJob:: Output ( )
{
Graduate:: Output ( ) ;
cout << "职 称:" << academicTitle << endl;
}
#ifndef _INTERFACE
#define _INTERFACE
#include "example5_14_people.h"
const int N = 3 ;
class Interface
{
protected :
Student st[ N] ;
int numOfSt;
Graduate gr[ N] ;
int numOfGr;
PostgraduateOnJob po[ N] ;
int numOfPo;
Teacher te[ N] ;
int numOfTe;
public :
Interface ( ) ;
void display ( ) ;
void run ( ) ;
void Input ( ) ;
void Output ( ) ;
} ;
#endif
#include "example5_14_interface.h"
#include <cstring>
#include <iostream>
using namespace std;
Interface:: Interface ( )
{
numOfSt = 0 ;
numOfGr = 0 ;
numOfPo = 0 ;
numOfTe = 0 ;
}
void Interface:: display ( )
{
cout << "**********0.退 出**********" << endl;
cout << "**********1.录入信息**********" << endl;
cout << "**********2.浏览信息**********" << endl;
}
void Interface:: run ( )
{
int choice;
do
{
display ( ) ;
cout << "Please input your choice:" ;
cin >> choice;
switch ( choice )
{
case 0 :
break ;
case 1 :
Input ( ) ;
break ;
case 2 :
Output ( ) ;
break ;
}
} while ( choice) ;
}
void Interface:: Input ( )
{
int type;
int i;
char ch;
do
{
cout << "你要输入的人员类型(1-学生 2-研究生 3-在职研究生 4-教师 ):" ;
cin >> type;
if ( type == 1 )
{
if ( numOfSt == N )
{
cout << "人数已满,无法继续录入!" << endl;
}
else
{
for ( i= 0 ; strcmp ( st[ i] . GetName ( ) , "00" ) != 0 ; i++ ) ;
st[ i] . Input ( ) ;
numOfSt++ ;
}
}
else if ( type == 2 )
{
if ( numOfGr == N )
{
cout << "人数已满,无法继续录入!" << endl;
}
else
{
for ( i= 0 ; strcmp ( gr[ i] . GetName ( ) , "00" ) != 0 ; i++ ) ;
gr[ i] . Input ( ) ;
numOfGr++ ;
}
}
else if ( type == 3 )
{
if ( numOfPo == N )
{
cout << "人数已满,无法继续录入!" << endl;
}
else
{
for ( i= 0 ; strcmp ( po[ i] . GetName ( ) , "00" ) != 0 ; i++ ) ;
po[ i] . Input ( ) ;
numOfPo++ ;
}
}
else if ( type == 4 )
{
if ( numOfTe == N )
{
cout << "人数已满,无法继续录入!" << endl;
}
else
{
for ( i= 0 ; strcmp ( te[ i] . GetName ( ) , "00" ) != 0 ; i++ ) ;
te[ i] . Input ( ) ;
numOfTe++ ;
}
}
else
{
cout << "选择有误" << endl;
}
cout << "继续输入?(y/n)" << endl;
cin >> ch;
} while ( ch == 'y' ) ;
}
void Interface:: Output ( )
{
int type;
int i;
cout << "你要查看的人员类型(1-学生 2-研究生 3-在职研究生 4-教师 ):" ;
cin >> type;
if ( type == 1 )
{
if ( numOfSt == 0 )
{
cout << "没有学生数据!" << endl;
}
else
{
for ( i= 0 ; i< N ; i++ )
if ( strcmp ( st[ i] . GetName ( ) , "00" ) != 0 )
st[ i] . Output ( ) ;
}
}
else if ( type == 2 )
{
if ( numOfGr == 0 )
{
cout << "没有研究生数据!" << endl;
}
else
{
for ( i= 0 ; i< N ; i++ )
if ( strcmp ( gr[ i] . GetName ( ) , "00" ) != 0 )
gr[ i] . Output ( ) ;
}
}
else if ( type == 3 )
{
if ( numOfPo == 0 )
{
cout << "没有在职研究生数据!" << endl;
}
else
{
for ( i= 0 ; i< N ; i++ )
if ( strcmp ( po[ i] . GetName ( ) , "00" ) != 0 )
po[ i] . Output ( ) ;
}
}
else if ( type == 4 )
{
if ( numOfTe == 0 )
{
cout << "没有教师数据!" << endl;
}
else
{
for ( i= 0 ; i< N ; i++ )
if ( strcmp ( te[ i] . GetName ( ) , "00" ) != 0 )
te[ i] . Output ( ) ;
}
}
else
{
cout << "选择有误" << endl;
}
}
#include <iostream>
#include "example5_14_interface.h"
using namespace std;
int main ( )
{
Interface in;
in. run ( ) ;
return 0 ;
}