编程处理教师的基本情况。
要求:
1、定义一个“person”类。用来存储及处理人的姓名、性别、年龄,成员函数自定;
2、定义“teacher”类,公有继承“person”类用来存储教师所在学院、所学专业、学历、学位、职称、教龄等,成员函数自定。
3、处理程序,主要包含:
⑴显示姓名、性别、年龄函数:既能显示person对象的姓名、性别、年龄,又能显示teacher对象的姓名、性别、年龄(用person引用对象为形參);
⑵显示教师所在学院、所学专业、学历、学位、职称、教龄的函数;
⑶ main()函数:分别定义persor对象及teacher对象,并输入不同对象相关值。调用成员函数设置对象的值,调用显示函数显示对应值。
#ifndef __person__person__#define __person__person__#includeusing namespace std;#include class person{protected: char *name; char *sex; int age;public: person(char *na,char *se,int ag); void set_person(char *na,char *se,int ag); char* get_name() {return name;} char* get_sex() {return sex;} int get_age() {return age;} void print(); ~person() {delete []name;delete []sex;}};person::person(char *na,char *se,int ag){ name=new char[strlen(na)+1]; strcpy(name,na); sex=new char[strlen(se)+1]; strcpy(sex,se); age = 0;}void person:: set_person(char *na,char *se,int ag){ name=new char[strlen(na)+1]; strcpy(name,na); sex=new char[strlen(se)+1]; strcpy(sex,se); age=ag;}void person:: print(){ for(int i = 0;i<=strlen(name);i++) { cout<
#ifndef person_teacher_h#define person_teacher_h#include"person.h"class teacher:public person{protected: char *college;//学院 char *speciality;//专业 char *school;//学历 char *degree;//学位 char *title;//职称 int teacherage;//教龄public: teacher(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te); void set_t(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te); char* get_college() {return college;} char* get_speciality() {return speciality;} char* get_school() {return school;} char* get_degree() {return degree;} char* get_title() {return title;} int get_teacher_age() {return teacherage;} ~teacher(); void print_t(person&p);};teacher::teacher(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te):person(na,se,ag){ //person::set_person(na, se, ag); college=new char[strlen(co)+1]; strcpy(college,co); speciality=new char[strlen(sp)+1]; strcpy(speciality,sp); school=new char[strlen(sc)+1]; strcpy(school,sc); degree=new char[strlen(de)+1]; strcpy(degree,de); title=new char[strlen(ti)+1]; strcpy(title,ti); teacherage =0;}void teacher:: set_t(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te){ name=new char[strlen(na)+1]; strcpy(name,na); sex=new char[strlen(se)+1]; strcpy(sex,se); age=ag; college=new char[strlen(co)+1]; strcpy(college,co); speciality=new char[strlen(sp)+1]; strcpy(speciality,sp); school=new char[strlen(sc)+1]; strcpy(school,sc); degree=new char[strlen(de)+1]; strcpy(degree,de); title=new char[strlen(ti)+1]; strcpy(title,ti); teacherage =te;}teacher::~teacher(){ delete []college; delete []speciality; delete []school; delete []degree; delete [] title;}void teacher:: print_t(person &p){ p.print(); cout<<"-------------------"<
#include "teacher.h"//#include"person.h"int main(){ person p("s","nv",22); teacher T("张老师","女",44,"计科","网络","本科","博士","教授",20); T.print_t(p); T.set_t("张老师","女",44,"计科","网络","本科","博士","教授",20); T.print_t(p); cout<<