任务一:打印个人信息,学生,老师,在职教师
2-11
#include "stdafx.h"
#include<iostream>
#include<string>
using namespacestd;
class person
{
public:
person(char*n,char*s,inty,intm)
{
name =newchar[strlen(n)+ 1];
strcpy(name,n);
sex = newchar[strlen(s)+ 1];
strcpy(sex,s);
year =y;
month= m;
}
voidprint()
{
cout<< "姓名:" << name << endl;
cout<< "性别:" << sex << endl;
cout<< "出生日期:" << year <<"年"<< month <<"月"<< endl;
}
protected:
char*name;
char*sex;
intyear;
intmonth;
};
class student:virtualpublicperson
{
public:
student(char*n,char*s,inty,intm,intN,char*g):person(n,s,y,m)
{
NO = N;
grade= new char[strlen(g)+ 1];
strcpy(grade,g);
}
void print()
{
cout << "年级:"<< grade << endl;
cout<< "学号:" << NO << endl;
person::print();
}
protected:
int NO;
char*grade;
};
class studentTeacher:virtualpublicstudent
{
public:
studentTeacher(char*n,char*s,inty,intm,intN,char*g,char*c):student(n,s,y,m,N,g),person(n,s,y,m)
{
course= new char[strlen(c)+ 1];
strcpy(course,c);
}
void print()
{
student::print();
cout<< "教授课程:" << course << endl;
}
protected:
char*course;
};
class teacher:virtualpublicperson
{
public:
teacher(char*n,char*s,inty,intm,char*t, char *c):person(n,s,y,m)
{
tile =newchar[strlen(t)+ 1];
strcpy(tile,t);
course= new char[strlen(c)+ 1];
strcpy(course,c);
}
void print()
{
person::print();
cout << "职称:"<< tile << endl;
cout<< "教授课程:" << course << endl;
}
protected:
char*tile;
char*course;
};
void main()
{
person p("周民","男",1993,2);
student st("张帆","女",1993, 12, 14721614,"硕士一年级");
studentTeacher sT("林勤勤","女", 1990, 12, 12721614,"博士一年级","c++程序设计");
teacher teac("李宁","男",1963,2,"教授","数字化制造");
cout<< "************************"<< endl;
p.print();
cout<<"************************"<<endl;
st.print();
cout<< "************************"<< endl;
sT.print();
cout<< "************************"<< endl;
teac.print();
cout<< "************************"<< endl;
}